Skip to content

Commit

Permalink
[AptosFramework] prevent module republish
Browse files Browse the repository at this point in the history
  • Loading branch information
zekun000 authored and aptos-bot committed Apr 30, 2022
1 parent eac6b69 commit 63a9b1d
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 35 deletions.
34 changes: 33 additions & 1 deletion aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ use aptos_types::{
write_set::{WriteSet, WriteSetMut},
};
use fail::fail_point;
use move_binary_format::{errors::VMResult, CompiledModule};
use move_binary_format::{
access::ModuleAccess,
errors::{verification_error, Location, VMResult},
CompiledModule, IndexKind,
};
use move_core_types::{
account_address::AccountAddress,
gas_schedule::{GasAlgebra, GasUnits},
Expand Down Expand Up @@ -359,6 +363,33 @@ impl AptosVM {
}
}

fn verify_module_bundle<S: MoveResolverExt>(
session: &mut SessionExt<S>,
module_bundle: &ModuleBundle,
) -> VMResult<()> {
for module_blob in module_bundle.iter() {
match CompiledModule::deserialize(module_blob.code()) {
Ok(module) => {
// verify the module doesn't exist
if session
.get_data_store()
.load_module(&module.self_id())
.is_ok()
{
return Err(verification_error(
StatusCode::DUPLICATE_MODULE_NAME,
IndexKind::AddressIdentifier,
module.self_handle_idx().0,
)
.finish(Location::Undefined));
}
}
Err(err) => return Err(err.finish(Location::Undefined)),
}
}
Ok(())
}

fn execute_modules<S: MoveResolverExt>(
&self,
mut session: SessionExt<S>,
Expand All @@ -384,6 +415,7 @@ impl AptosVM {
.charge_intrinsic_gas(txn_data.transaction_size())
.map_err(|e| e.into_vm_status())?;

Self::verify_module_bundle(&mut session, modules)?;
session
.publish_module_bundle(modules.clone().into_inner(), module_address, gas_status)
.map_err(|e| e.into_vm_status())?;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e903000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9014d }), Value(a11ceb0b0500000008010002020204030605050b01070c060812200a32050c3707000000010000000200000000014d015401661636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e900020102030001000000010200))] }), events: [], gas_used: 8, status: Keep(Success) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e904000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9014d }), Value(a11ceb0b0500000008010002020204030605050b01070c060812200a32050c3707000000010000000200000000014d015401661636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e900020102030001000000010200))] }), events: [], gas_used: 8, status: Keep(Success) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e904000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000))] }), events: [], gas_used: 1, status: Keep(MiscellaneousError(Some(DUPLICATE_MODULE_NAME))) }])
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e903000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9014d }), Value(a11ceb0b05000000030100020702020804200000014d1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e900))] }), events: [], gas_used: 8, status: Keep(Success) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e904000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9014d }), Value(a11ceb0b0500000005010002020204070606080c200a2c05000000010000014d015401661636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9000201020300))] }), events: [], gas_used: 8, status: Keep(Success) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e904000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000))] }), events: [], gas_used: 1, status: Keep(MiscellaneousError(Some(DUPLICATE_MODULE_NAME))) }])
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e903000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9014d }), Value(a11ceb0b0500000005010002020204070606080c200a2c05000000010000014d015401661636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9000201020300))] }), events: [], gas_used: 8, status: Keep(Success) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e904000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000))] }), events: [], gas_used: 1, status: Keep(MiscellaneousError(Some(BACKWARD_INCOMPATIBLE_MODULE_UPDATE))) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e904000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000))] }), events: [], gas_used: 1, status: Keep(MiscellaneousError(Some(DUPLICATE_MODULE_NAME))) }])
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e903000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9014d }), Value(a11ceb0b0500000005010002020204070606080c200a2c05000000010000014d015401661636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9000201020300))] }), events: [], gas_used: 8, status: Keep(Success) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e904000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000))] }), events: [], gas_used: 1, status: Keep(MiscellaneousError(Some(BACKWARD_INCOMPATIBLE_MODULE_UPDATE))) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e904000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000))] }), events: [], gas_used: 1, status: Keep(MiscellaneousError(Some(DUPLICATE_MODULE_NAME))) }])
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e903000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9014d }), Value(a11ceb0b0500000005010002020204070606080c200a2c05000000010000014d015401661636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9000201020300))] }), events: [], gas_used: 8, status: Keep(Success) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e904000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000))] }), events: [], gas_used: 1, status: Keep(MiscellaneousError(Some(BACKWARD_INCOMPATIBLE_MODULE_UPDATE))) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e904000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000))] }), events: [], gas_used: 1, status: Keep(MiscellaneousError(Some(DUPLICATE_MODULE_NAME))) }])
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e903000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9014d }), Value(a11ceb0b0500000005010002020204070606080c200a2c05000000010000014d015401661636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9000201020300))] }), events: [], gas_used: 8, status: Keep(Success) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e904000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000))] }), events: [], gas_used: 1, status: Keep(MiscellaneousError(Some(BACKWARD_INCOMPATIBLE_MODULE_UPDATE))) }])
Ok([TransactionOutput { write_set: WriteSet(WriteSetMut { write_set: [(AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 010000000000000000000000000000000000000000000000000000000000000001074163636f756e74074163636f756e7400 }), Value(201636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e904000000000000001636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9)), (AccessPath(AccessPath { address: 1636331b85359efd8b9ba888caff7a063eebd722df1633f4bf38f1e2087222e9, path: 0100000000000000000000000000000000000000000000000000000000000000010854657374436f696e0742616c616e636500 }), Value(40420f0000000000))] }), events: [], gas_used: 1, status: Keep(MiscellaneousError(Some(DUPLICATE_MODULE_NAME))) }])
Loading

0 comments on commit 63a9b1d

Please sign in to comment.