Skip to content

Commit

Permalink
Merge pull request #1 from initia-labs/feat/aptos-patch
Browse files Browse the repository at this point in the history
feat: apply latest aptos patches
  • Loading branch information
beer-1 authored Mar 6, 2024
2 parents a9f5cd8 + 7d818d9 commit b7817a6
Show file tree
Hide file tree
Showing 45 changed files with 1,986 additions and 710 deletions.
81 changes: 51 additions & 30 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,35 +104,56 @@ bigdecimal = "0.4"
# Note: the BEGIN and END comments below are required for external tooling. Do not remove.
# BEGIN MOVE DEPENDENCIES

# move-abigen = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
# move-bytecode-utils = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
# move-errmapgen = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
# move-ir-compiler = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
# move-prover-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
# move-stackless-bytecode-interpreter = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
# move-transactional-test-runner = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
# read-write-set = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
# read-write-set-dynamic = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-binary-format = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-bytecode-verifier = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-cli = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-command-line-common = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-compiler = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-core-types = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-docgen = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-model = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-package = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-prover = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-prover-boogie-backend = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-prover-bytecode-pipeline = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-resource-viewer = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-stackless-bytecode = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-stdlib = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-symbol-pool = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-unit-test = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-vm-runtime = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-vm-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }
move-vm-types = { git = "https://github.com/initia-labs/move.git", rev = "1f87f9bac32707e940603e2b8b2cfddf17bc70ab" }

# move-abigen = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
# move-bytecode-utils = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
# move-errmapgen = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
# move-ir-compiler = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
# move-prover-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
# move-stackless-bytecode-interpreter = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
# move-transactional-test-runner = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
# read-write-set = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
# read-write-set-dynamic = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-binary-format = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-bytecode-verifier = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-cli = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-command-line-common = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-compiler = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-core-types = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-docgen = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-model = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-package = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-prover = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-prover-boogie-backend = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-prover-bytecode-pipeline = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-resource-viewer = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-stackless-bytecode = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-stdlib = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-symbol-pool = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-unit-test = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-vm-runtime = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-vm-test-utils = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }
move-vm-types = { git = "https://github.com/initia-labs/move.git", rev = "c27b20c33a8dea33716bf3da931ca8229ac88e00" }

# END MOVE DEPENDENCIES

# FOR LOCAL DEVELOPMENNT
# move-binary-format = { path = "../move/move-binary-format" }
# move-bytecode-verifier = { path = "../move/move-bytecode-verifier" }
# move-cli = { path = "../move/tools/move-cli" }
# move-command-line-common = { path = "../move/move-command-line-common" }
# move-compiler = { path = "../move/move-compiler" }
# move-core-types = { path = "../move/move-core/types" }
# move-docgen = { path = "../move/move-prover/move-docgen" }
# move-model = { path = "../move/move-model" }
# move-package = { path = "../move/tools/move-package" }
# move-prover = { path = "../move/move-prover" }
# move-prover-boogie-backend = { path = "../move/move-prover/boogie-backend" }
# move-prover-bytecode-pipeline = { path = "../move/move-prover/bytecode-pipeline" }
# move-resource-viewer = { path = "../move/tools/move-resource-viewer" }
# move-stackless-bytecode = { path = "../move/move-model/bytecode" }
# move-stdlib = { path = "../move/move-stdlib" }
# move-symbol-pool = { path = "../move/move-symbol-pool" }
# move-unit-test = { path = "../move/tools/move-unit-test" }
# move-vm-runtime = { path = "../move/move-vm/runtime" }
# move-vm-test-utils = { path = "../move/move-vm/test-utils" }
# move-vm-types = { path = "../move/move-vm/types" }
2 changes: 2 additions & 0 deletions crates/compiler/src/test_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use move_cli::base::{
coverage::{Coverage, CoverageSummaryOptions},
test::{run_move_unit_tests, Test, UnitTestResult},
};
use move_core_types::effects::ChangeSet;
use move_package::BuildConfig;
use move_unit_test::UnitTestingConfig;

Expand Down Expand Up @@ -43,6 +44,7 @@ impl TestPackage {
..UnitTestingConfig::default_with_bound(None)
},
all_natives(gas_params, misc_gas_params),
ChangeSet::new(),
None,
self.test_config.compute_coverage,
&mut std::io::stdout(),
Expand Down
3 changes: 2 additions & 1 deletion crates/e2e-move-tests/src/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ impl MoveHarness {
let resolver = StateViewImpl::new(&state);
let mut table_resolver = TableViewImpl::new(&mut table_state);

let gas_limit: initia_move_gas::GasQuantity<initia_move_gas::GasUnit> = Gas::new(100_000_000u64);
let gas_limit: initia_move_gas::GasQuantity<initia_move_gas::GasUnit> =
Gas::new(100_000_000u64);
self.vm.execute_message(
&self.api,
&env,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module std::BasicCoin {
test: bool,
}

#[event]
/// Event emitted when some amount of coins are withdrawn from an Collateral.
struct MintEvent has drop, store {
amount: u64,
Expand Down
2 changes: 1 addition & 1 deletion crates/e2e-move-tests/src/tests/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn test_redeploy_should_update_module_cache() {

h.initialize();

let code = hex::decode("a11ceb0b060000000d01000a020a12031c28044404054822076aa001088a022010aa02350adf02140bf302020cf502670ddc03020ede030200000001000200030004000509010001000600000007060003110700000800010100000900020100000a03040100000b04010002120700000413040801000114050401060505060901050103010b00010900020c03000109000205070b0001090001060c010803010802094261736963436f696e056576656e74067369676e657206737472696e6709747970655f696e666f04436f696e06496e69746961094d696e744576656e7403676574086765745f636f696e046d696e74066e756d6265720576616c756504746573740b64756d6d795f6669656c6406616d6f756e7409636f696e5f7479706506537472696e670a616464726573735f6f6609747970655f6e616d6504656d6974000000000000000000000000000000000000000000000000000000000000000113696e697469613a3a6d657461646174615f76302000000303676574010100066e756d626572010100086765745f636f696e0101000002020c030d010102010e010202020f031008030005000100010004050b003d0037001402010100010004040b003d0014020201040100061d0e0011040c020a023b0020040d0e000a010839003f0005180b023c000c030a033700140a01160b033600150b0138001202380102030100000402064101000000000000020000000500").expect("ms");
let code = hex::decode("a11ceb0b060000000d01000a020a12031c28044404054822076aa001088a022010aa02420aec02140b8003020c8203670de903020eeb030200000001000200030004000509010001000600000007060003110700000800010100000900020100000a03040100000b04010002120700000413040801000114050401060505060901050103010b00010900020c03000109000205070b0001090001060c010803010802094261736963436f696e056576656e74067369676e657206737472696e6709747970655f696e666f04436f696e06496e69746961094d696e744576656e7403676574086765745f636f696e046d696e74066e756d6265720576616c756504746573740b64756d6d795f6669656c6406616d6f756e7409636f696e5f7479706506537472696e670a616464726573735f6f6609747970655f6e616d6504656d6974000000000000000000000000000000000000000000000000000000000000000113696e697469613a3a6d657461646174615f76302d0001094d696e744576656e740104000303676574010100066e756d626572010100086765745f636f696e0101000002020c030d010102010e010202020f031008030005000100010004050b003d0037001402010100010004040b003d0014020201040100061d0e0011040c020a023b0020040d0e000a010839003f0005180b023c000c030a033700140a01160b033600150b0138001202380102030100000402064101000000000000020000000500").expect("ms");
let msg = h.create_publish_message(
AccountAddress::ONE,
vec!["0x1::BasicCoin".to_string()],
Expand Down
2 changes: 2 additions & 0 deletions crates/e2e-move-tests/src/tests/move_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use initia_move_natives::{
transaction_context::NativeTransactionContext,
};
use move_cli::base::test::{run_move_unit_tests, UnitTestResult};
use move_core_types::effects::ChangeSet;
use move_unit_test::UnitTestingConfig;
use move_vm_runtime::{
native_extensions::NativeContextExtensions, native_functions::NativeFunctionTable,
Expand Down Expand Up @@ -60,6 +61,7 @@ fn run_tests_for_pkg(path_to_pkg: impl Into<String>) {
},
UnitTestingConfig::default_with_bound(Some(100_000)),
initia_move_test_natives(),
ChangeSet::new(),
// TODO(Gas): we may want to switch to non-zero costs in the future
None,
/* compute_coverage */ false,
Expand Down
5 changes: 5 additions & 0 deletions crates/gas/src/algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ pub type GasScalingFactor = GasQuantity<UnitDiv<InternalGasUnit, GasUnit>>;
pub type Fee = GasQuantity<Hexa>;

pub type FeePerGasUnit = GasQuantity<UnitDiv<Hexa, GasUnit>>;

/// Unit of module
pub enum Module {}

pub type NumModules = GasQuantity<Module>;
1 change: 1 addition & 0 deletions crates/gas/src/gas_params/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod object;
pub mod oracle;
pub mod query;
pub mod staking;
pub mod string_utils;
pub mod table;
pub mod transaction_context;
pub mod type_info;
12 changes: 12 additions & 0 deletions crates/gas/src/gas_params/string_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use move_core_types::gas_algebra::{InternalGas, InternalGasPerByte};

#[derive(Debug, Clone)]
pub struct FormatGasParameters {
pub base: InternalGas,
pub per_byte: InternalGasPerByte,
}

#[derive(Debug, Clone)]
pub struct GasParameters {
pub format: FormatGasParameters,
}
10 changes: 10 additions & 0 deletions crates/gas/src/initia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "initia", [
[.block.get_block_info.base_cost, "block.get_block_info.base", 100 * SCALING],
[.oracle.get_price.base_cost, "oracle.get_prices.base_cost", 1500 * SCALING],
[.oracle.get_price.per_byte, "oracle.get_prices.per_byte", 18],

[.string_utils.format.base, "string_utils.format.base", 1102],
[.string_utils.format.per_byte, "string_utils.format.per_byte", 3],
]);

use crate::gas_params::*;
Expand All @@ -138,6 +141,7 @@ pub struct GasParameters {
pub json: json::GasParameters,
pub query: query::GasParameters,
pub oracle: oracle::GasParameters,
pub string_utils: string_utils::GasParameters,
}

impl GasParameters {
Expand Down Expand Up @@ -356,6 +360,12 @@ impl GasParameters {
per_byte: 0.into(),
},
},
string_utils: string_utils::GasParameters {
format: string_utils::FormatGasParameters {
base: 0.into(),
per_byte: 0.into(),
},
},
}
}
}
5 changes: 4 additions & 1 deletion crates/gas/src/instr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
use crate::algebra::InternalGasPerAbstractValueUnit;
use move_binary_format::errors::PartialVMResult;
use move_core_types::gas_algebra::{InternalGas, InternalGasPerArg, InternalGasPerByte};
use move_core_types::gas_algebra::{
InternalGas, InternalGasPerArg, InternalGasPerByte, InternalGasPerTypeNode,
};
use move_vm_types::gas::SimpleInstruction;

crate::params::define_gas_parameters!(
Expand Down Expand Up @@ -123,6 +125,7 @@ crate::params::define_gas_parameters!(
[vec_pack_per_elem: InternalGasPerArg, "vec_pack.per_elem", 147],
[vec_unpack_base: InternalGas, "vec_unpack.base", 1838],
[vec_unpack_per_expected_elem: InternalGasPerArg, "vec_unpack.per_expected_elem", 147],
[subst_ty_per_node: InternalGasPerTypeNode, "subst_ty_per_node", 400],
]
);

Expand Down
54 changes: 53 additions & 1 deletion crates/gas/src/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ use crate::{
algebra::Gas, instr::InstructionGasParameters, misc::MiscGasParameters,
transaction::TransactionGasParameters,
};
use crate::{AbstractValueSize, GasUnit};
use crate::{AbstractValueSize, GasUnit, NumModules};

use initia_move_types::access_path::AccessPath;
use initia_move_types::gas_usage::GasUsageSet;
use move_binary_format::errors::{Location, PartialVMError, PartialVMResult, VMResult};
use move_binary_format::file_format::CodeOffset;
use move_core_types::account_address::AccountAddress;
use move_core_types::effects::Op;
use move_core_types::gas_algebra::NumTypeNodes;
use move_core_types::identifier::IdentStr;
use move_core_types::{
gas_algebra::{InternalGas, NumArgs, NumBytes},
language_storage::ModuleId,
Expand Down Expand Up @@ -177,6 +179,10 @@ pub struct InitiaGasMeter {
// and compute `gas_used` at `drop_frame` and `charge_native_function`.
gas_usages: BTreeMap<ModuleId, InternalGas>,
call_stack: Vec<Frame>,

// dependency calculation
num_dependencies: NumModules,
total_dependency_size: NumBytes,
}

struct Frame {
Expand All @@ -199,6 +205,8 @@ impl InitiaGasMeter {
is_call_table: false,
gas_usages: BTreeMap::new(),
call_stack: Vec::new(),
num_dependencies: 0.into(),
total_dependency_size: 0.into(),
}
}

Expand Down Expand Up @@ -738,6 +746,34 @@ impl GasMeter for InitiaGasMeter {

Ok(())
}

#[inline]
fn charge_create_ty(&mut self, num_nodes: NumTypeNodes) -> PartialVMResult<()> {
let cost = self.gas_params.instr.subst_ty_per_node * num_nodes;

self.charge(cost)
}

#[inline]
fn charge_dependency(
&mut self,
_is_new: bool,
addr: &AccountAddress,
_name: &IdentStr,
size: NumBytes,
) -> PartialVMResult<()> {
// Modules under special addresses are considered system modules that should always
// be loaded, and are therefore excluded from gas charging.
if !addr.is_special() {
self.charge(
self.gas_params.txn.dependency_per_module
+ self.gas_params.txn.dependency_per_byte * size,
)?;
self.count_dependency(size)?;
}

Ok(())
}
}

impl InitiaGasMeter {
Expand Down Expand Up @@ -772,3 +808,19 @@ impl InitiaGasMeter {
)
}
}

impl InitiaGasMeter {
fn count_dependency(&mut self, size: NumBytes) -> PartialVMResult<()> {
self.num_dependencies += 1.into();
self.total_dependency_size += size;

if self.num_dependencies > self.gas_params.txn.max_num_dependencies {
return Err(PartialVMError::new(StatusCode::DEPENDENCY_LIMIT_REACHED));
}
if self.total_dependency_size > self.gas_params.txn.max_total_dependency_size {
return Err(PartialVMError::new(StatusCode::DEPENDENCY_LIMIT_REACHED));
}

Ok(())
}
}
Loading

0 comments on commit b7817a6

Please sign in to comment.