diff --git a/Cargo.toml b/Cargo.toml index ad6bb3dd..41434d80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,28 +118,28 @@ pretty_assertions = "1.2.1" # Note: the BEGIN and END comments below are required for external tooling. Do not remove. # BEGIN MOVE DEPENDENCIES -move-binary-format = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-bytecode-verifier = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-bytecode-utils = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-cli = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-command-line-common = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-compiler = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-coverage = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-core-types = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-docgen = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-model = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-package = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-prover = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-prover-boogie-backend = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-prover-bytecode-pipeline = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-resource-viewer = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-stackless-bytecode = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-stdlib = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-symbol-pool = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-unit-test = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-vm-runtime = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-vm-test-utils = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } -move-vm-types = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7131086965eb19c1c7f35b2003d2a5637691f108" } +move-binary-format = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-bytecode-verifier = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-bytecode-utils = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-cli = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-command-line-common = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-compiler = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-coverage = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-core-types = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-docgen = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-model = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-package = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-prover = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-prover-boogie-backend = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-prover-bytecode-pipeline = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-resource-viewer = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-stackless-bytecode = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-stdlib = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-symbol-pool = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-unit-test = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-vm-runtime = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-vm-test-utils = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } +move-vm-types = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "751c9a34969e54dd18452d41f3c996fc2e971eb7" } # END MOVE DEPENDENCIES diff --git a/crates/storage/src/code_scale.rs b/crates/storage/src/code_scale.rs index 9f293421..27f42697 100644 --- a/crates/storage/src/code_scale.rs +++ b/crates/storage/src/code_scale.rs @@ -113,8 +113,8 @@ mod test { use move_core_types::account_address::AccountAddress; use move_core_types::identifier::Identifier; use move_core_types::language_storage::ModuleId; - use move_vm_runtime::{compute_code_hash, CodeStorage, ModuleStorage, RuntimeEnvironment}; - use move_vm_types::code::{Code, ModuleCode, WithBytes, WithHash}; + use move_vm_runtime::{CodeStorage, ModuleStorage, RuntimeEnvironment}; + use move_vm_types::{code::{Code, ModuleCode, WithBytes, WithHash}, sha3_256}; use crate::code_storage::test::make_script; use crate::code_storage::AsInitiaCodeStorage; @@ -284,7 +284,7 @@ mod test { ); let serialized_script = make_script(vec!["a"]); - compute_code_hash(&serialized_script); + sha3_256(&serialized_script); code_storage.deserialize_and_cache_script(&serialized_script).unwrap(); let script = code_storage.verify_and_cache_script(&serialized_script).unwrap(); diff --git a/crates/storage/src/code_storage.rs b/crates/storage/src/code_storage.rs index accd43cd..415d5d3e 100644 --- a/crates/storage/src/code_storage.rs +++ b/crates/storage/src/code_storage.rs @@ -6,13 +6,14 @@ use bytes::Bytes; use move_binary_format::{errors::VMResult, file_format::CompiledScript, CompiledModule}; use move_core_types::{account_address::AccountAddress, identifier::IdentStr, metadata::Metadata}; use move_vm_runtime::{ - ambassador_impl_ModuleStorage, ambassador_impl_WithRuntimeEnvironment, compute_code_hash, + ambassador_impl_ModuleStorage, ambassador_impl_WithRuntimeEnvironment, logging::expect_no_verification_errors, CodeStorage, Module, ModuleStorage, RuntimeEnvironment, Script, WithRuntimeEnvironment, }; use move_vm_types::{ code::{Code, ModuleBytesStorage}, module_linker_error, + sha3_256 }; use std::sync::Arc; @@ -96,7 +97,7 @@ impl CodeStorage for InitiaCodeStorage { &self, serialized_script: &[u8], ) -> VMResult> { - let hash = compute_code_hash(serialized_script); + let hash = sha3_256(serialized_script); Ok(match self.script_cache.get_script(&hash) { Some(script) => script.deserialized().clone(), None => { @@ -112,7 +113,7 @@ impl CodeStorage for InitiaCodeStorage { fn verify_and_cache_script(&self, serialized_script: &[u8]) -> VMResult> { use Code::*; - let hash = compute_code_hash(serialized_script); + let hash = sha3_256(serialized_script); let deserialized_script = match self.script_cache.get_script(&hash) { Some(Verified(script)) => return Ok(script), Some(Deserialized(deserialized_script)) => deserialized_script, @@ -180,7 +181,8 @@ pub(crate) mod test { use move_core_types::{ account_address::AccountAddress, identifier::Identifier, language_storage::ModuleId, }; - use move_vm_runtime::{compute_code_hash, CodeStorage, RuntimeEnvironment}; + use move_vm_runtime::{CodeStorage, RuntimeEnvironment}; + use move_vm_types::sha3_256; use crate::{ code_storage::AsInitiaCodeStorage, @@ -217,11 +219,11 @@ pub(crate) mod test { ); let serialized_script = make_script(vec!["a"]); - let hash_1 = compute_code_hash(&serialized_script); + let hash_1 = sha3_256(&serialized_script); assert_ok!(code_storage.deserialize_and_cache_script(&serialized_script)); let serialized_script = make_script(vec!["b"]); - let hash_2 = compute_code_hash(&serialized_script); + let hash_2 = sha3_256(&serialized_script); assert_ok!(code_storage.deserialize_and_cache_script(&serialized_script)); code_storage.assert_cached_state(vec![&hash_1, &hash_2], vec![]); @@ -249,7 +251,7 @@ pub(crate) mod test { ); let serialized_script = make_script(vec!["a"]); - let hash = compute_code_hash(&serialized_script); + let hash = sha3_256(&serialized_script); assert_ok!(code_storage.deserialize_and_cache_script(&serialized_script)); // Nothing gets loaded into module cache. diff --git a/crates/storage/src/memory_module_storage.rs b/crates/storage/src/memory_module_storage.rs index e31ec056..c09ad579 100644 --- a/crates/storage/src/memory_module_storage.rs +++ b/crates/storage/src/memory_module_storage.rs @@ -19,10 +19,10 @@ use move_core_types::{ value::MoveTypeLayout, vm_status::StatusCode, }; -use move_vm_runtime::compute_code_hash; use move_vm_types::{ code::ModuleBytesStorage, resolver::{resource_size, ModuleResolver, ResourceResolver}, + sha3_256 }; use std::{ collections::{btree_map, BTreeMap}, @@ -193,8 +193,8 @@ impl InMemoryAccountStorage { ( k, match v { - Op::New(bytes) => Op::New(compute_code_hash(&bytes)), - Op::Modify(bytes) => Op::Modify(compute_code_hash(&bytes)), + Op::New(bytes) => Op::New(sha3_256(&bytes)), + Op::Modify(bytes) => Op::Modify(sha3_256(&bytes)), Op::Delete => Op::Delete, }, ) @@ -246,7 +246,7 @@ impl InMemoryStorage { module_name: &IdentStr, bytes: Bytes, ) -> Checksum { - let checksum = compute_code_hash(&bytes); + let checksum = sha3_256(&bytes); let account = get_or_insert(&mut self.accounts, *address, || { InMemoryAccountStorage::new() diff --git a/crates/storage/src/move_core_type/file_format.rs b/crates/storage/src/move_core_type/file_format.rs index 9d8cbb8b..ce16d578 100644 --- a/crates/storage/src/move_core_type/file_format.rs +++ b/crates/storage/src/move_core_type/file_format.rs @@ -200,7 +200,7 @@ pub struct U256(PrimitiveU256); impl GetSize for U256 { fn get_size(&self) -> usize { - 4 + 32 } } impl fmt::Display for U256 { diff --git a/crates/vm/src/session.rs b/crates/vm/src/session.rs index 741eb2aa..4bdb4180 100644 --- a/crates/vm/src/session.rs +++ b/crates/vm/src/session.rs @@ -30,8 +30,8 @@ use move_core_types::{ value::{MoveFieldLayout, MoveStructLayout, MoveTypeLayout}, vm_status::StatusCode, }; -use move_vm_runtime::{compute_code_hash, session::Session, ModuleStorage}; -use move_vm_types::loaded_data::runtime_types::{StructLayout, StructNameIndex, StructType, Type}; +use move_vm_runtime::{session::Session, ModuleStorage}; +use move_vm_types::{loaded_data::runtime_types::{StructLayout, StructNameIndex, StructType, Type}, sha3_256}; /// Maximal depth of a value in terms of type depth. pub const VALUE_DEPTH_MAX: u64 = 128; @@ -123,7 +123,7 @@ impl<'r, 'l> SessionExt<'r, 'l> { module_write_set.insert( ap, op.map(|v| { - let checksum = compute_code_hash(&v); + let checksum = sha3_256(&v); checksum.into() }), );