diff --git a/Cargo.toml b/Cargo.toml index 11b95e5e..9627b742 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -92,7 +92,10 @@ serde = { version = "1.0.188", default-features = false, features = [ "rc", ] } serde_bytes = "0.11.9" -serde_json = { version = "1.0.94" } +serde_json = { version = "1.0.81", features = [ + "preserve_order", + "arbitrary_precision", +] } # Note: arbitrary_precision is required to parse u256 in JSON serde-generate = { git = "https://github.com/aptos-labs/serde-reflection", rev = "73b6bbf748334b71ff6d7d09d06a29e3062ca075" } serde-reflection = { git = "https://github.com/aptos-labs/serde-reflection", rev = "73b6bbf748334b71ff6d7d09d06a29e3062ca075" } sha2 = "0.10.8" @@ -116,28 +119,28 @@ tiny-keccak = { version = "2.0.2", features = ["keccak", "sha3"] } # 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 = "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" } +move-binary-format = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-bytecode-verifier = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-bytecode-utils = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-cli = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-command-line-common = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-compiler = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-coverage = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-core-types = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-docgen = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-model = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-package = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-prover = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-prover-boogie-backend = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-prover-bytecode-pipeline = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-resource-viewer = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-stackless-bytecode = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-stdlib = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-symbol-pool = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-unit-test = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-vm-runtime = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-vm-test-utils = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } +move-vm-types = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "4ace64edcc41878fe348c07238cfe497a5cb6714" } # END MOVE DEPENDENCIES diff --git a/Makefile b/Makefile index 80c94cc6..12982ab3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all build build-rust build-go test precompile +.PHONY: all build build-rust build-go test precompile contracts-gen bcs-go-gen # Builds the Rust library libmovevm BUILDERS_PREFIX := initia/go-ext-builder:0001 @@ -80,9 +80,11 @@ build: precompile build-rust build-go build-rust: build-rust-release +contracts-gen: precompile precompile: cargo run -p precompile +bcs-go-gen: prebuild-go prebuild-go: cargo run -p generate-bcs-go diff --git a/crates/compiler/src/built_package.rs b/crates/compiler/src/built_package.rs index 302c4724..7d744924 100644 --- a/crates/compiler/src/built_package.rs +++ b/crates/compiler/src/built_package.rs @@ -65,7 +65,7 @@ impl BuiltPackage { } let (mut package, model_opt) = - new_config.compile_package_no_exit(&package_path, &mut stderr())?; + new_config.compile_package_no_exit(&package_path, vec![], &mut stderr())?; // Run extended checks as well as derive runtime metadata let model = &model_opt.expect("move model"); diff --git a/crates/compiler/src/unit_test_factory.rs b/crates/compiler/src/unit_test_factory.rs index c3380ca7..c5c57492 100644 --- a/crates/compiler/src/unit_test_factory.rs +++ b/crates/compiler/src/unit_test_factory.rs @@ -25,7 +25,7 @@ impl InitiaUnitTestFactory { table_context: NativeTableContext, ) -> VMResult<()> { let table_change_set = table_context - .into_change_set() + .into_change_set(None) .map_err(|e| e.finish(Location::Undefined))?; let write_set = WriteSet::new_with_change_set(changes.clone(), table_change_set).map_err(|e| { diff --git a/crates/e2e-move-tests/src/tests/cosmos.rs b/crates/e2e-move-tests/src/tests/cosmos.rs index d3fe38f1..ec26c904 100644 --- a/crates/e2e-move-tests/src/tests/cosmos.rs +++ b/crates/e2e-move-tests/src/tests/cosmos.rs @@ -115,7 +115,7 @@ fn test_cosmos_delegate() { &delegator_address.into_bytes(), ) .unwrap(); - let expected_data = format!("{{\"@type\":\"/initia.mstaking.v1.MsgDelegate\",\"amount\":[{{\"amount\":\"{amount}\",\"denom\":\"{staking_denom}\"}}],\"delegator_address\":\"{delegator_cosmos_addr}\",\"validator_address\":\"{validator_address}\"}}"); + let expected_data = format!("{{\"@type\":\"/initia.mstaking.v1.MsgDelegate\",\"delegator_address\":\"{delegator_cosmos_addr}\",\"validator_address\":\"{validator_address}\",\"amount\":[{{\"denom\":\"{staking_denom}\",\"amount\":\"{amount}\"}}]}}"); let test_delegate = ( delegator_address, "0x1::cosmos::delegate", @@ -169,7 +169,7 @@ fn test_cosmos_fund_community_pool() { let depositor_cosmos_addr = bech32::encode::(Hrp::parse_unchecked("init"), &sender_address.into_bytes()) .unwrap(); - let expected_data = format!("{{\"@type\":\"/cosmos.distribution.v1beta1.MsgFundCommunityPool\",\"amount\":[{{\"amount\":\"{amount}\",\"denom\":\"{denom}\"}}],\"depositor\":\"{depositor_cosmos_addr}\"}}"); + let expected_data = format!("{{\"@type\":\"/cosmos.distribution.v1beta1.MsgFundCommunityPool\",\"depositor\":\"{depositor_cosmos_addr}\",\"amount\":[{{\"denom\":\"{denom}\",\"amount\":\"{amount}\"}}]}}"); let test_fund_community_pool = ( sender_address, @@ -226,7 +226,7 @@ fn test_cosmos_transfer() { let denom = str::from_utf8(STAKING_SYMBOL).unwrap(); let sender_cosmos_addr = bech32::encode::(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap(); - let expected_data = format!("{{\"@type\":\"/ibc.applications.transfer.v1.MsgTransfer\",\"memo\":\"{memo}\",\"receiver\":\"{receiver}\",\"sender\":\"{sender_cosmos_addr}\",\"source_channel\":\"{source_channel}\",\"source_port\":\"{source_port}\",\"timeout_height\":{{\"revision_height\":\"{revision_height}\",\"revision_number\":\"{revision_number}\"}},\"timeout_timestamp\":\"{timeout_timestamp}\",\"token\":{{\"amount\":\"{amount}\",\"denom\":\"{denom}\"}}}}"); + let expected_data = format!("{{\"@type\":\"/ibc.applications.transfer.v1.MsgTransfer\",\"source_port\":\"{source_port}\",\"source_channel\":\"{source_channel}\",\"sender\":\"{sender_cosmos_addr}\",\"receiver\":\"{receiver}\",\"token\":{{\"denom\":\"{denom}\",\"amount\":\"{amount}\"}},\"timeout_height\":{{\"revision_number\":\"{revision_number}\",\"revision_height\":\"{revision_height}\"}},\"timeout_timestamp\":\"{timeout_timestamp}\",\"memo\":\"{memo}\"}}"); let test_transfer = ( sender, @@ -298,7 +298,7 @@ fn test_cosmos_nft_transfer() { let class_id = str::from_utf8(COLLECTION_NAME).unwrap(); let sender_cosmos_addr = bech32::encode::(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap(); - let expected_data = format!("{{\"@type\":\"/ibc.applications.nft_transfer.v1.MsgTransfer\",\"class_id\":\"{class_id}\",\"memo\":\"{memo}\",\"receiver\":\"{receiver}\",\"sender\":\"{sender_cosmos_addr}\",\"source_channel\":\"{source_channel}\",\"source_port\":\"{source_port}\",\"timeout_height\":{{\"revision_height\":\"{revision_height}\",\"revision_number\":\"{revision_number}\"}},\"timeout_timestamp\":\"{timeout_timestamp}\",\"token_ids\":[\"id1\",\"id2\"]}}"); + let expected_data = format!("{{\"@type\":\"/ibc.applications.nft_transfer.v1.MsgTransfer\",\"sender\":\"{sender_cosmos_addr}\",\"receiver\":\"{receiver}\",\"class_id\":\"{class_id}\",\"token_ids\":[\"id1\",\"id2\"],\"source_port\":\"{source_port}\",\"source_channel\":\"{source_channel}\",\"timeout_height\":{{\"revision_number\":\"{revision_number}\",\"revision_height\":\"{revision_height}\"}},\"timeout_timestamp\":\"{timeout_timestamp}\",\"memo\":\"{memo}\"}}"); let test_nft_transfer = ( sender, @@ -398,7 +398,7 @@ fn test_cosmos_pay_fee() { let timeout_fee_denom = str::from_utf8(FEE_B_SYMBOL).unwrap(); let sender_cosmos_addr = bech32::encode::(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap(); - let expected_data = format!("{{\"@type\":\"/ibc.applications.fee.v1.MsgPayPacketFee\",\"fee\":{{\"ack_fee\":[{{\"amount\":\"{ack_fee_amount}\",\"denom\":\"{ack_fee_denom}\"}}],\"recv_fee\":[{{\"amount\":\"{recv_fee_amount}\",\"denom\":\"{recv_fee_denom}\"}}],\"timeout_fee\":[{{\"amount\":\"{timeout_fee_amount}\",\"denom\":\"{timeout_fee_denom}\"}}]}},\"relayers\":[],\"signer\":\"{sender_cosmos_addr}\",\"source_channel_id\":\"{source_channel}\",\"source_port_id\":\"{source_port}\"}}"); + let expected_data = format!("{{\"@type\":\"/ibc.applications.fee.v1.MsgPayPacketFee\",\"signer\":\"{sender_cosmos_addr}\",\"source_port_id\":\"{source_port}\",\"source_channel_id\":\"{source_channel}\",\"fee\":{{\"recv_fee\":[{{\"denom\":\"{recv_fee_denom}\",\"amount\":\"{recv_fee_amount}\"}}],\"ack_fee\":[{{\"denom\":\"{ack_fee_denom}\",\"amount\":\"{ack_fee_amount}\"}}],\"timeout_fee\":[{{\"denom\":\"{timeout_fee_denom}\",\"amount\":\"{timeout_fee_amount}\"}}]}},\"relayers\":[]}}"); let test_pay_fee = ( sender, @@ -449,7 +449,7 @@ fn test_cosmos_move_execute() { let module_addr_hex = module_address.to_hex_literal(); let sender_cosmos_addr = bech32::encode::(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap(); - let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgExecute\",\"args\":[\"{arg1_base64}\",\"{arg2_base64}\"],\"function_name\":\"{function_name}\",\"module_address\":\"{module_addr_hex}\",\"module_name\":\"{module_name}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}"); + let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgExecute\",\"sender\":\"{sender_cosmos_addr}\",\"module_address\":\"{module_addr_hex}\",\"module_name\":\"{module_name}\",\"function_name\":\"{function_name}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"],\"args\":[\"{arg1_base64}\",\"{arg2_base64}\"]}}"); let test_move_execute = ( sender, @@ -494,7 +494,7 @@ fn test_cosmos_move_execute_with_json() { let sender_cosmos_addr = bech32::encode::(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap(); let module_addr_hex = module_address.to_hex_literal(); - let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgExecuteJSON\",\"args\":[\"\\\"hello\\\"\",\"\\\"world\\\"\"],\"function_name\":\"{function_name}\",\"module_address\":\"{module_addr_hex}\",\"module_name\":\"{module_name}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}"); + let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgExecuteJSON\",\"sender\":\"{sender_cosmos_addr}\",\"module_address\":\"{module_addr_hex}\",\"module_name\":\"{module_name}\",\"function_name\":\"{function_name}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"],\"args\":[\"\\\"hello\\\"\",\"\\\"world\\\"\"]}}"); let test_move_execute = ( sender, @@ -540,7 +540,7 @@ fn test_cosmos_move_script() { let arg2_base64 = base64.encode(arg2.clone()); let sender_cosmos_addr = bech32::encode::(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap(); - let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgScript\",\"args\":[\"{arg1_base64}\",\"{arg2_base64}\"],\"code_bytes\":\"{code_bytes_base64}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}"); + let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgScript\",\"sender\":\"{sender_cosmos_addr}\",\"code_bytes\":\"{code_bytes_base64}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"],\"args\":[\"{arg1_base64}\",\"{arg2_base64}\"]}}"); let test_move_script = ( sender, @@ -582,7 +582,7 @@ fn test_cosmos_move_script_with_json() { let code_bytes_base64 = base64.encode(code_bytes.clone()); let sender_cosmos_addr = bech32::encode::(Hrp::parse_unchecked("init"), &sender.into_bytes()).unwrap(); - let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgScriptJSON\",\"args\":[\"\\\"hello\\\"\",\"\\\"world\\\"\"],\"code_bytes\":\"{code_bytes_base64}\",\"sender\":\"{sender_cosmos_addr}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"]}}"); + let expected_data = format!("{{\"@type\":\"/initia.move.v1.MsgScriptJSON\",\"sender\":\"{sender_cosmos_addr}\",\"code_bytes\":\"{code_bytes_base64}\",\"type_args\":[\"{type_arg1}\",\"{type_arg2}\"],\"args\":[\"\\\"hello\\\"\",\"\\\"world\\\"\"]}}"); let test_move_script = ( sender, diff --git a/crates/e2e-move-tests/src/tests/staking.rs b/crates/e2e-move-tests/src/tests/staking.rs index 452bbcec..9e4d5140 100644 --- a/crates/e2e-move-tests/src/tests/staking.rs +++ b/crates/e2e-move-tests/src/tests/staking.rs @@ -183,7 +183,7 @@ fn test_simple_staking() { ExpectedOutput::new( VMStatus::Executed, Some( - format!("{{\"metadata\":\"0x{}\",\"share\":\"500000\",\"unclaimed_reward\":\"0\",\"validator\":\"validator\"}}", staking_metadata.short_str_lossless()) + format!("{{\"metadata\":\"0x{}\",\"validator\":\"validator\",\"share\":\"500000\",\"unclaimed_reward\":\"0\"}}", staking_metadata.short_str_lossless()) .to_string(), ), None, diff --git a/crates/e2e-move-tests/src/tests/view_output.rs b/crates/e2e-move-tests/src/tests/view_output.rs index 382d94b6..7d7cfef7 100644 --- a/crates/e2e-move-tests/src/tests/view_output.rs +++ b/crates/e2e-move-tests/src/tests/view_output.rs @@ -49,7 +49,7 @@ fn test_view_output() { type_args: vec![] })) .to_string(), - "{\"arg\":\"hello world\",\"type_arg\":\"u256\"}".to_string() + "{\"type_arg\":\"u256\",\"arg\":\"hello world\"}".to_string() )]) .into_inner(), ); diff --git a/crates/gas/src/meter.rs b/crates/gas/src/meter.rs index ee2a4d65..f4abf6c3 100644 --- a/crates/gas/src/meter.rs +++ b/crates/gas/src/meter.rs @@ -765,6 +765,11 @@ impl GasMeter for InitiaGasMeter { Ok(()) } + + #[inline] + fn charge_heap_memory(&mut self, _amount: u64) -> PartialVMResult<()> { + Ok(()) + } } impl InitiaGasMeter { diff --git a/crates/json/src/json_to_move.rs b/crates/json/src/json_to_move.rs index a0b7f00c..ccbd9c71 100644 --- a/crates/json/src/json_to_move.rs +++ b/crates/json/src/json_to_move.rs @@ -1,4 +1,4 @@ -use std::{str::FromStr, sync::Arc}; +use std::str::FromStr; use bigdecimal::{ self, @@ -7,21 +7,19 @@ use bigdecimal::{ }; use bytes::Bytes; use initia_move_storage::{initia_storage::InitiaStorage, state_view::StateView}; -use move_binary_format::errors::{PartialVMResult, VMResult}; +use move_binary_format::errors::{Location, PartialVMResult, VMResult}; use move_core_types::{ account_address::AccountAddress, ident_str, - language_storage::{StructTag, TypeTag}, + identifier::Identifier, + language_storage::{ModuleId, StructTag, TypeTag}, metadata::Metadata, u256::U256, value::{MoveTypeLayout, MoveValue}, }; use move_vm_runtime::ModuleStorage; use move_vm_types::{ - loaded_data::runtime_types::{ - StructNameIndex, StructType, - Type::{self, *}, - }, + loaded_data::runtime_types::Type::{self, *}, resolver::ResourceResolver, }; use serde_json::Value as JSONValue; @@ -29,11 +27,11 @@ use serde_json::Value as JSONValue; use crate::errors::{deserialization_error, deserialization_error_with_msg}; pub trait StructResolver { - fn get_struct_type( + fn get_struct_name( &self, - index: StructNameIndex, + ty: &Type, module_storage: &impl ModuleStorage, - ) -> Option>; + ) -> PartialVMResult>; fn type_to_type_tag(&self, ty: &Type, module_storage: &impl ModuleStorage) -> VMResult; } @@ -53,7 +51,6 @@ pub fn deserialize_json_args( MAX_NUM_BYTES ))); } - let json_val: JSONValue = serde_json::from_slice(arg).map_err(deserialization_error_with_msg)?; @@ -137,11 +134,13 @@ fn convert_json_value_to_move_value( } MoveValue::Vector(vec) } - Struct { idx, .. } => { + Struct { .. } => { let st = struct_resolver - .get_struct_type(*idx, code_storage) + .get_struct_name(ty, code_storage) + .map_err(|e| e.finish(Location::Undefined))? .ok_or_else(deserialization_error)?; - let full_name = format!("{}::{}", st.module.short_str_lossless(), st.name); + + let full_name = format!("{}::{}", st.0.short_str_lossless(), st.1); match full_name.as_str() { // JSONValue and JSONObject are not supported as entry function arguments // @@ -214,7 +213,7 @@ fn convert_json_value_to_move_value( } } } - StructInstantiation { idx, ty_args, .. } => { + StructInstantiation { ty_args, .. } => { if ty_args.len() != 1 { return Err(deserialization_error_with_msg( "invalid type arguments length", @@ -222,10 +221,12 @@ fn convert_json_value_to_move_value( } let st = struct_resolver - .get_struct_type(*idx, code_storage) + .get_struct_name(ty, code_storage) + .map_err(|e| e.finish(Location::Undefined))? .ok_or_else(deserialization_error)?; + let ty = ty_args.first().ok_or_else(deserialization_error)?; - let full_name = format!("{}::{}", st.module.short_str_lossless(), st.name); + let full_name = format!("{}::{}", st.0.short_str_lossless(), st.1); match full_name.as_str() { "0x1::option::Option" => { if json_val.is_null() { @@ -343,19 +344,19 @@ mod json_arg_testing { module_cache::InitiaModuleCache, script_cache::InitiaScriptCache, state_view::StateView, }; use initia_move_types::access_path::{AccessPath, DataPath}; - use move_binary_format::{ - errors::{Location, PartialVMError}, - file_format::{Ability, AbilitySet}, - }; + use move_binary_format::errors::{Location, PartialVMError}; use move_core_types::{ + ability::{Ability, AbilitySet}, ident_str, identifier::Identifier, language_storage::{ModuleId, StructTag}, vm_status::StatusCode, }; use move_vm_runtime::RuntimeEnvironment; - use move_vm_types::loaded_data::runtime_types::AbilityInfo; - use smallbitvec::SmallBitVec; + use move_vm_types::loaded_data::{ + runtime_types::{AbilityInfo, StructIdentifier}, + struct_name_indexing::{StructNameIndex, StructNameIndexMap}, + }; use super::*; @@ -363,7 +364,7 @@ mod json_arg_testing { struct MockState { pub map: BTreeMap, Vec>, - pub structs: BTreeMap>, + pub structs: BTreeMap, } impl StateView for MockState { @@ -376,29 +377,35 @@ mod json_arg_testing { } impl StructResolver for MockState { - fn get_struct_type( + fn get_struct_name( &self, - index: StructNameIndex, + ty: &Type, _module_storage: &impl ModuleStorage, - ) -> Option> { - self.structs.get(&index).cloned() + ) -> PartialVMResult> { + match ty { + Type::Struct { idx, .. } | Type::StructInstantiation { idx, .. } => { + Ok(self.structs.get(idx).cloned()) + } + _ => Err(PartialVMError::new(StatusCode::TYPE_MISMATCH)), + } } + fn type_to_type_tag( &self, ty: &Type, module_storage: &impl ModuleStorage, ) -> VMResult { match ty { - Struct { idx, .. } => { - let struct_ty = - self.get_struct_type(*idx, module_storage).ok_or_else(|| { - PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) - .finish(Location::Undefined) - })?; + Struct { .. } => { + let st = self + .get_struct_name(ty, module_storage) + .map_err(|e| e.finish(Location::Undefined))? + .ok_or_else(deserialization_error)?; + Ok(TypeTag::Struct(Box::new(StructTag { - address: struct_ty.module.address, - module: struct_ty.module.name.clone(), - name: struct_ty.name.clone(), + address: st.0.address, + module: st.0.name.clone(), + name: st.1.clone(), type_args: vec![], }))) } @@ -675,17 +682,29 @@ mod json_arg_testing { _ = deserialize_json_args(&code_storage, &mock_state, &ty, arg).unwrap_err(); } - pub fn for_test(module_name: &str, name: &str) -> StructType { - use move_vm_types::loaded_data::runtime_types::StructLayout; + pub fn for_test( + struct_index_map: &StructNameIndexMap, + module_name: &str, + name: &str, + ) -> (Type, StructNameIndex, (ModuleId, Identifier)) { + let struct_identifier = for_test_struct_identifier(module_name, name); + let struct_name_index = struct_index_map + .struct_name_to_idx(&struct_identifier) + .unwrap(); + ( + Struct { + idx: struct_name_index, + ability: AbilityInfo::struct_(AbilitySet::ALL), + }, + struct_name_index, + (struct_identifier.module, struct_identifier.name), + ) + } - StructType { - idx: StructNameIndex(0), - layout: StructLayout::Single(vec![]), - phantom_ty_params_mask: SmallBitVec::new(), - abilities: AbilitySet::EMPTY, - ty_params: vec![], - name: Identifier::new(name).unwrap(), + pub fn for_test_struct_identifier(module_name: &str, name: &str) -> StructIdentifier { + StructIdentifier { module: ModuleId::new(AccountAddress::ONE, Identifier::new(module_name).unwrap()), + name: Identifier::new(name).unwrap(), } } @@ -693,14 +712,11 @@ mod json_arg_testing { fn test_deserialize_json_args_string() { let mut mock_state = mock_state(); - mock_state - .structs - .insert(StructNameIndex(0), Arc::new(for_test("string", "String"))); + let struct_index_map = StructNameIndexMap::empty(); + + let (ty, idx, (module_id, identifier)) = for_test(&struct_index_map, "string", "String"); + mock_state.structs.insert(idx, (module_id, identifier)); - let ty = Type::Struct { - idx: StructNameIndex(0), - ability: AbilityInfo::struct_(AbilitySet::ALL), - }; let arg = b"\"hello\""; let runtime_environment = RuntimeEnvironment::new(vec![]); let script_cache = InitiaScriptCache::new(TEST_CACHE_CAPACITY); @@ -719,18 +735,17 @@ mod json_arg_testing { #[test] fn test_deserialize_json_args_object() { let mut mock_state = mock_state(); + let struct_index_map = StructNameIndexMap::empty(); + let (_, idx, (module_id, identifier)) = for_test(&struct_index_map, "object", "Object"); + mock_state.structs.insert(idx, (module_id, identifier)); - mock_state - .structs - .insert(StructNameIndex(0), Arc::new(for_test("object", "Object"))); - mock_state.structs.insert( - StructNameIndex(1), - Arc::new(for_test("fungible_asset", "Metadata")), - ); - mock_state.structs.insert( - StructNameIndex(2), - Arc::new(for_test("fungible_asset", "Metadata2")), - ); + let (_, idx, (module_id, identifier)) = + for_test(&struct_index_map, "fungible_asset", "Metadata"); + mock_state.structs.insert(idx, (module_id, identifier)); + + let (_, idx, (module_id, identifier)) = + for_test(&struct_index_map, "fungible_asset", "Metadata2"); + mock_state.structs.insert(idx, (module_id, identifier)); // insert object core to object addr let obj_addr = AccountAddress::random(); @@ -766,10 +781,14 @@ mod json_arg_testing { ); let ty = Type::StructInstantiation { - idx: StructNameIndex(0), + idx: struct_index_map + .struct_name_to_idx(&for_test_struct_identifier("object", "Object")) + .unwrap(), ability: AbilityInfo::struct_(AbilitySet::ALL), ty_args: triomphe::Arc::new(vec![Type::Struct { - idx: StructNameIndex(1), + idx: struct_index_map + .struct_name_to_idx(&for_test_struct_identifier("fungible_asset", "Metadata")) + .unwrap(), ability: AbilityInfo::struct_(AbilitySet::singleton(Ability::Key)), }]), }; @@ -798,10 +817,14 @@ mod json_arg_testing { // invalid inner type let wrong_inner_ty = Type::StructInstantiation { - idx: StructNameIndex(0), + idx: struct_index_map + .struct_name_to_idx(&for_test_struct_identifier("object", "Object")) + .unwrap(), ability: AbilityInfo::struct_(AbilitySet::ALL), ty_args: triomphe::Arc::new(vec![Type::Struct { - idx: StructNameIndex(2), + idx: struct_index_map + .struct_name_to_idx(&for_test_struct_identifier("fungible_asset", "Metadata2")) + .unwrap(), ability: AbilityInfo::struct_(AbilitySet::singleton(Ability::Key)), }]), }; @@ -815,12 +838,14 @@ mod json_arg_testing { #[test] fn test_deserialize_json_args_option_some() { let mut mock_state = mock_state(); - mock_state - .structs - .insert(StructNameIndex(0), Arc::new(for_test("option", "Option"))); + let struct_index_map = StructNameIndexMap::empty(); + let (_, idx, (module_id, identifier)) = for_test(&struct_index_map, "option", "Option"); + mock_state.structs.insert(idx, (module_id, identifier)); let ty = Type::StructInstantiation { - idx: StructNameIndex(0), + idx: struct_index_map + .struct_name_to_idx(&for_test_struct_identifier("option", "Option")) + .unwrap(), ty_args: triomphe::Arc::new(vec![Type::Address]), ability: AbilityInfo::struct_(AbilitySet::ALL), }; @@ -850,12 +875,14 @@ mod json_arg_testing { #[test] fn test_deserialize_json_args_option_none() { let mut mock_state = mock_state(); - mock_state - .structs - .insert(StructNameIndex(0), Arc::new(for_test("option", "Option"))); + let struct_index_map = StructNameIndexMap::empty(); + let (_, idx, (module_id, identifier)) = for_test(&struct_index_map, "option", "Option"); + mock_state.structs.insert(idx, (module_id, identifier)); let ty = Type::StructInstantiation { - idx: StructNameIndex(0), + idx: struct_index_map + .struct_name_to_idx(&for_test_struct_identifier("option", "Option")) + .unwrap(), ty_args: triomphe::Arc::new(vec![Type::Address]), ability: AbilityInfo::struct_(AbilitySet::ALL), }; @@ -881,13 +908,15 @@ mod json_arg_testing { #[test] fn test_deserialize_json_args_fixed_point32() { let mut mock_state = mock_state(); - mock_state.structs.insert( - StructNameIndex(0), - Arc::new(for_test("fixed_point32", "FixedPoint32")), - ); + let struct_index_map = StructNameIndexMap::empty(); + let (_, idx, (module_id, identifier)) = + for_test(&struct_index_map, "fixed_point32", "FixedPoint32"); + mock_state.structs.insert(idx, (module_id, identifier)); let ty = Type::Struct { - idx: StructNameIndex(0), + idx: struct_index_map + .struct_name_to_idx(&for_test_struct_identifier("fixed_point32", "FixedPoint32")) + .unwrap(), ability: AbilityInfo::struct_(AbilitySet::ALL), }; let arg = b"\"123.4567\""; @@ -916,15 +945,11 @@ mod json_arg_testing { #[test] fn test_deserialize_json_args_fixed_point64() { let mut mock_state = mock_state(); - mock_state.structs.insert( - StructNameIndex(0), - Arc::new(for_test("fixed_point64", "FixedPoint64")), - ); + let struct_index_map = StructNameIndexMap::empty(); + let (ty, idx, (module_id, identifier)) = + for_test(&struct_index_map, "fixed_point64", "FixedPoint64"); + mock_state.structs.insert(idx, (module_id, identifier)); - let ty = Type::Struct { - idx: StructNameIndex(0), - ability: AbilityInfo::struct_(AbilitySet::ALL), - }; let arg = b"\"123.4567\""; let runtime_environment = RuntimeEnvironment::new(vec![]); @@ -952,14 +977,10 @@ mod json_arg_testing { #[test] fn test_deserialize_json_args_big_uint() { let mut mock_state = mock_state(); - mock_state - .structs - .insert(StructNameIndex(0), Arc::new(for_test("biguint", "BigUint"))); + let struct_index_map = StructNameIndexMap::empty(); + let (ty, idx, (module_id, identifier)) = for_test(&struct_index_map, "biguint", "BigUint"); + mock_state.structs.insert(idx, (module_id, identifier)); - let ty = Type::Struct { - idx: StructNameIndex(0), - ability: AbilityInfo::struct_(AbilitySet::ALL), - }; let arg = b"\"1234567\""; let runtime_environment = RuntimeEnvironment::new(vec![]); let script_cache = InitiaScriptCache::new(TEST_CACHE_CAPACITY); @@ -986,15 +1007,11 @@ mod json_arg_testing { #[test] fn test_deserialize_json_args_big_decimal() { let mut mock_state = mock_state(); - mock_state.structs.insert( - StructNameIndex(0), - Arc::new(for_test("bigdecimal", "BigDecimal")), - ); + let struct_index_map = StructNameIndexMap::empty(); + let (ty, idx, (module_id, identifier)) = + for_test(&struct_index_map, "bigdecimal", "BigDecimal"); + mock_state.structs.insert(idx, (module_id, identifier)); - let ty = Type::Struct { - idx: StructNameIndex(0), - ability: AbilityInfo::struct_(AbilitySet::ALL), - }; let arg = b"\"123.4567\""; let runtime_environment = RuntimeEnvironment::new(vec![]); let script_cache = InitiaScriptCache::new(TEST_CACHE_CAPACITY); diff --git a/crates/json/src/json_to_value.rs b/crates/json/src/json_to_value.rs index 09de08f8..81de4e0d 100644 --- a/crates/json/src/json_to_value.rs +++ b/crates/json/src/json_to_value.rs @@ -290,6 +290,7 @@ mod json_arg_testing { language_storage::StructTag, value::{MoveFieldLayout, MoveStructLayout}, }; + use move_vm_types::value_serde::ValueSerDeContext; use super::*; @@ -423,9 +424,11 @@ mod json_arg_testing { let result = deserialize_json_to_value(&module_id(), &layout, arg).unwrap(); assert_eq!( - result.simple_serialize(&layout).unwrap(), - Value::vector_u8(vec![0u8, 1u8, 2u8, 3u8]) - .simple_serialize(&layout) + ValueSerDeContext::new() + .serialize(&result, &layout) + .unwrap(), + ValueSerDeContext::new() + .serialize(&Value::vector_u8(vec![0u8, 1u8, 2u8, 3u8]), &layout) .unwrap() ); @@ -442,13 +445,20 @@ mod json_arg_testing { let layout = MoveTypeLayout::Vector(Box::new(MoveTypeLayout::Address)); let arg = b"[\"0x1\", \"0x2\"]"; let result = deserialize_json_to_value(&module_id(), &layout, arg).unwrap(); + assert_eq!( - result.simple_serialize(&layout).unwrap(), - bcs::to_bytes(&vec![ - "0x1".parse::().unwrap(), - "0x2".parse::().unwrap() - ]) - .unwrap() + ValueSerDeContext::new() + .serialize(&result, &layout) + .unwrap(), + ValueSerDeContext::new() + .serialize( + &Value::vector_address(vec![ + "0x1".parse::().unwrap(), + "0x2".parse::().unwrap() + ]), + &layout + ) + .unwrap() ); // invalid inner address diff --git a/crates/json/src/move_to_json.rs b/crates/json/src/move_to_json.rs index 1403782f..6098d82f 100644 --- a/crates/json/src/move_to_json.rs +++ b/crates/json/src/move_to_json.rs @@ -71,35 +71,35 @@ fn convert_move_value_to_json_value(val: &MoveValue, depth: usize) -> VMResult { + MoveStruct::WithTypes { _type_, _fields } => { // The move compiler inserts a dummy field with the value of false // for structs with no fields. - if fields.len() == 1 && fields[0].0.as_str() == "dummy_field" { + if _fields.len() == 1 && _fields[0].0.as_str() == "dummy_field" { return Ok(JSONValue::Object(Map::new())); } // check the struct type is string // if yes, then convert move value to json string // else, execute convert function recursively - if is_json_value(type_) { - convert_json_value_to_json_value(&fields[0].1) - } else if is_json_object(type_) { - convert_json_object_to_json_value(&fields[0].1) - } else if is_utf8_string(type_) { - convert_string_to_json_value(&fields[0].1) - } else if is_biguint(type_) { - convert_biguint_to_json_value(&fields[0].1) - } else if is_decimal(type_) { - convert_decimal_to_json_value(&fields[0].1) - } else if is_option(type_) { - convert_option_to_json_value(&fields[0].1, depth) - } else if is_object(type_) { - convert_object_to_json_value(&fields[0].1) - } else if is_fixed_point(type_) { - convert_fixed_point_to_json_value(&fields[0].1) + if is_json_value(_type_) { + convert_json_value_to_json_value(&_fields[0].1) + } else if is_json_object(_type_) { + convert_json_object_to_json_value(&_fields[0].1) + } else if is_utf8_string(_type_) { + convert_string_to_json_value(&_fields[0].1) + } else if is_biguint(_type_) { + convert_biguint_to_json_value(&_fields[0].1) + } else if is_decimal(_type_) { + convert_decimal_to_json_value(&_fields[0].1) + } else if is_option(_type_) { + convert_option_to_json_value(&_fields[0].1, depth) + } else if is_object(_type_) { + convert_object_to_json_value(&_fields[0].1) + } else if is_fixed_point(_type_) { + convert_fixed_point_to_json_value(&_fields[0].1) } else { let mut fields_map: Map = Map::new(); - for (id, mv) in fields.iter() { + for (id, mv) in _fields.iter() { let field_name = match id.as_str() { "_type_" => "@type", "_move_" => "move", @@ -153,15 +153,15 @@ fn convert_json_object_to_json_value(val: &MoveValue) -> VMResult { .iter() .map(|elem| match elem { MoveValue::Struct( - MoveStruct::WithTypes { type_: _, fields } - | MoveStruct::WithFields(fields) - | MoveStruct::WithVariantFields(_, _, fields), + MoveStruct::WithTypes { _type_: _, _fields } + | MoveStruct::WithFields(_fields) + | MoveStruct::WithVariantFields(_, _, _fields), ) => { let key = - std::str::from_utf8(&bytes_from_move_value(&fields.first().unwrap().1)?) + std::str::from_utf8(&bytes_from_move_value(&_fields.first().unwrap().1)?) .map_err(deserialization_error_with_msg)? .to_string(); - let val = convert_json_value_to_json_value(&fields.get(1).unwrap().1)?; + let val = convert_json_value_to_json_value(&_fields.get(1).unwrap().1)?; Ok((key, val)) } @@ -221,11 +221,11 @@ fn convert_decimal_to_json_value(val: &MoveValue) -> VMResult { BigDecimal::new(num.into(), 18) } MoveValue::Struct( - MoveStruct::WithTypes { type_: _, fields } - | MoveStruct::WithFields(fields) - | MoveStruct::WithVariantFields(_, _, fields), + MoveStruct::WithTypes { _type_: _, _fields } + | MoveStruct::WithFields(_fields) + | MoveStruct::WithVariantFields(_, _, _fields), ) => { - let (_, bytes_val) = fields.first().unwrap(); + let (_, bytes_val) = _fields.first().unwrap(); match bytes_val { MoveValue::Vector(bytes_val) => { let bytes_le = bytes_val @@ -371,13 +371,13 @@ mod move_to_json_tests { // biguint let mv = MoveValue::Struct(MoveStruct::WithTypes { - type_: StructTag { + _type_: StructTag { address: CORE_CODE_ADDRESS, module: ident_str!("biguint").into(), name: ident_str!("BigUint").into(), type_args: vec![], }, - fields: vec![( + _fields: vec![( ident_str!("bytes").into(), MoveValue::Vector(vec![ MoveValue::U8(64), @@ -407,13 +407,13 @@ mod move_to_json_tests { // option some let mv = MoveValue::Struct(MoveStruct::WithTypes { - type_: StructTag { + _type_: StructTag { address: CORE_CODE_ADDRESS, module: ident_str!("option").into(), name: ident_str!("Option").into(), type_args: vec![], }, - fields: vec![( + _fields: vec![( ident_str!("vec").into(), MoveValue::Vector(vec![MoveValue::U8(123)]), )], @@ -423,26 +423,26 @@ mod move_to_json_tests { // option none let mv = MoveValue::Struct(MoveStruct::WithTypes { - type_: StructTag { + _type_: StructTag { address: CORE_CODE_ADDRESS, module: ident_str!("option").into(), name: ident_str!("Option").into(), type_args: vec![], }, - fields: vec![(ident_str!("vec").into(), MoveValue::Vector(vec![]))], + _fields: vec![(ident_str!("vec").into(), MoveValue::Vector(vec![]))], }); let val = convert_move_value_to_json_value(&mv, 1).unwrap(); assert_eq!(val, json!(null)); // fixed_point32 let mv = MoveValue::Struct(MoveStruct::WithTypes { - type_: StructTag { + _type_: StructTag { address: CORE_CODE_ADDRESS, module: ident_str!("fixed_point32").into(), name: ident_str!("FixedPoint32").into(), type_args: vec![], }, - fields: vec![( + _fields: vec![( ident_str!("val").into(), MoveValue::U64((123 << 32) / 2), // 61.5 )], @@ -452,13 +452,13 @@ mod move_to_json_tests { // fixed_point64 let mv = MoveValue::Struct(MoveStruct::WithTypes { - type_: StructTag { + _type_: StructTag { address: CORE_CODE_ADDRESS, module: ident_str!("fixed_point64").into(), name: ident_str!("FixedPoint64").into(), type_args: vec![], }, - fields: vec![( + _fields: vec![( ident_str!("val").into(), MoveValue::U128((123 << 64) / 2), // 61.5 )], @@ -468,22 +468,22 @@ mod move_to_json_tests { // bigdecimal let mv = MoveValue::Struct(MoveStruct::WithTypes { - type_: StructTag { + _type_: StructTag { address: CORE_CODE_ADDRESS, module: ident_str!("bigdecimal").into(), name: ident_str!("BigDecimal").into(), type_args: vec![], }, - fields: vec![( + _fields: vec![( ident_str!("bytes").into(), MoveValue::Struct(MoveStruct::WithTypes { - type_: StructTag { + _type_: StructTag { address: CORE_CODE_ADDRESS, module: ident_str!("biguint").into(), name: ident_str!("BigUint").into(), type_args: vec![], }, - fields: vec![( + _fields: vec![( ident_str!("bytes").into(), MoveValue::Vector(vec![ MoveValue::U8(64), @@ -502,13 +502,13 @@ mod move_to_json_tests { // object let addr = AccountAddress::random(); let mv = MoveValue::Struct(MoveStruct::WithTypes { - type_: StructTag { + _type_: StructTag { address: CORE_CODE_ADDRESS, module: ident_str!("object").into(), name: ident_str!("Object").into(), type_args: vec![], }, - fields: vec![( + _fields: vec![( ident_str!("val").into(), MoveValue::Address(addr), // 61.5 )], @@ -518,13 +518,13 @@ mod move_to_json_tests { // json value let mv = MoveValue::Struct(MoveStruct::WithTypes { - type_: StructTag { + _type_: StructTag { address: CORE_CODE_ADDRESS, module: ident_str!("json").into(), name: ident_str!("JSONValue").into(), type_args: vec![], }, - fields: vec![( + _fields: vec![( ident_str!("val").into(), MoveValue::Vector(vec![ MoveValue::U8(34), @@ -541,23 +541,23 @@ mod move_to_json_tests { // json object let mv = MoveValue::Struct(MoveStruct::WithTypes { - type_: StructTag { + _type_: StructTag { address: CORE_CODE_ADDRESS, module: ident_str!("json").into(), name: ident_str!("JSONObject").into(), type_args: vec![], }, - fields: vec![( + _fields: vec![( ident_str!("elems").into(), MoveValue::Vector(vec![ MoveValue::Struct(MoveStruct::WithTypes { - type_: StructTag { + _type_: StructTag { address: CORE_CODE_ADDRESS, module: ident_str!("json").into(), name: ident_str!("Element").into(), type_args: vec![], }, - fields: vec![ + _fields: vec![ ( ident_str!("key").into(), MoveValue::Vector(vec![ @@ -581,13 +581,13 @@ mod move_to_json_tests { ], }), MoveValue::Struct(MoveStruct::WithTypes { - type_: StructTag { + _type_: StructTag { address: CORE_CODE_ADDRESS, module: ident_str!("json").into(), name: ident_str!("Element").into(), type_args: vec![], }, - fields: vec![ + _fields: vec![ ( ident_str!("key").into(), MoveValue::Vector(vec![MoveValue::U8(102)]), diff --git a/crates/natives/src/account.rs b/crates/natives/src/account.rs index 24822d2b..3279aac2 100644 --- a/crates/natives/src/account.rs +++ b/crates/natives/src/account.rs @@ -247,7 +247,7 @@ fn native_create_signer( context.charge(gas_params.account_create_signer_base_cost)?; let address = safely_pop_arg!(arguments, AccountAddress); - Ok(smallvec![Value::signer(address)]) + Ok(smallvec![Value::master_signer(address)]) } /*************************************************************************************************** diff --git a/crates/natives/src/event.rs b/crates/natives/src/event.rs index eae453e2..2a6252ba 100644 --- a/crates/natives/src/event.rs +++ b/crates/natives/src/event.rs @@ -18,6 +18,9 @@ use move_vm_types::{ }; use smallvec::{smallvec, SmallVec}; +#[cfg(feature = "testing")] +use move_vm_types::value_serde::ValueSerDeContext; + // See stdlib/error.move const ECATEGORY_INVALID_ARGUMENT: u64 = 0x1; @@ -118,24 +121,36 @@ fn native_emit_event( )) })?; - let ctx = context.extensions_mut().get_mut::(); - // Cache the emitted event for testing. #[cfg(feature = "testing")] { - let blob = msg.simple_serialize(&layout).ok_or_else(|| { - SafeNativeError::InvariantViolation(PartialVMError::new( - StatusCode::VALUE_SERIALIZATION_ERROR, - )) - })?; - - ctx.events_for_testing.push((blob, type_tag.clone())); + let blob = match ValueSerDeContext::new() + .with_legacy_signer() + .with_func_args_deserialization(context.function_value_extension()) + .serialize(&msg, &layout)? + { + Some(blob) => blob, + None => { + return Err(SafeNativeError::InvariantViolation(PartialVMError::new( + StatusCode::VALUE_SERIALIZATION_ERROR, + ))); + } + }; + context + .extensions_mut() + .get_mut::() + .events_for_testing + .push((blob, type_tag.clone())); } - ctx.events.push(( - ContractEvent::new(type_tag, serde_value.to_string()), - annotated_layout, - )); + context + .extensions_mut() + .get_mut::() + .events + .push(( + ContractEvent::new(type_tag, serde_value.to_string()), + annotated_layout, + )); Ok(smallvec![]) } @@ -152,16 +167,21 @@ fn native_emitted_events( let ty = &ty_args[0]; let ty_tag = context.type_to_type_tag(ty)?; let ty_layout = context.type_to_type_layout(ty)?; - let ctx = context.extensions_mut().get_mut::(); + let ctx = context.extensions().get::(); let events = ctx .emitted_events(&ty_tag) .into_iter() .map(|blob| { - Value::simple_deserialize(blob, &ty_layout).ok_or_else(|| { - SafeNativeError::InvariantViolation(PartialVMError::new( + match ValueSerDeContext::new() + .with_legacy_signer() + .with_func_args_deserialization(context.function_value_extension()) + .deserialize(blob, &ty_layout) + { + Some(val) => Ok(val), + None => Err(SafeNativeError::InvariantViolation(PartialVMError::new( StatusCode::VALUE_DESERIALIZATION_ERROR, - )) - }) + ))), + } }) .collect::>>()?; diff --git a/crates/natives/src/from_bcs.rs b/crates/natives/src/from_bcs.rs index 0f5683d5..427265ae 100644 --- a/crates/natives/src/from_bcs.rs +++ b/crates/natives/src/from_bcs.rs @@ -1,6 +1,8 @@ use move_core_types::gas_algebra::NumBytes; use move_vm_runtime::native_functions::NativeFunction; -use move_vm_types::{loaded_data::runtime_types::Type, values::Value}; +use move_vm_types::{ + loaded_data::runtime_types::Type, value_serde::ValueSerDeContext, values::Value, +}; use smallvec::{smallvec, SmallVec}; use std::collections::VecDeque; @@ -42,7 +44,11 @@ fn native_from_bytes( + gas_params.from_bcs_from_bytes_unit * NumBytes::new(bytes.len() as u64), )?; - let val = match Value::simple_deserialize(&bytes, &layout) { + let val = match ValueSerDeContext::new() + .with_legacy_signer() + .with_func_args_deserialization(context.function_value_extension()) + .deserialize(&bytes, &layout) + { Some(val) => val, None => { return Err(SafeNativeError::Abort { diff --git a/crates/natives/src/move_stdlib/bcs.rs b/crates/natives/src/move_stdlib/bcs.rs index d8a8dd90..2c60b82d 100644 --- a/crates/natives/src/move_stdlib/bcs.rs +++ b/crates/natives/src/move_stdlib/bcs.rs @@ -9,7 +9,7 @@ use move_vm_runtime::native_functions::NativeFunction; use move_vm_types::{ loaded_data::runtime_types::Type, natives::function::PartialVMResult, - value_serde::serialized_size_allowing_delayed_values, + value_serde::ValueSerDeContext, values::{values_impl::Reference, Value}, }; use smallvec::{smallvec, SmallVec}; @@ -68,7 +68,12 @@ fn native_to_bytes( // serialize value let val = ref_to_val.read_ref()?; - let serialized_value = match val.simple_serialize(&layout) { + + let serialized_value = match ValueSerDeContext::new() + .with_legacy_signer() + .with_func_args_deserialization(context.function_value_extension()) + .serialize(&val, &layout)? + { Some(serialized_value) => serialized_value, None => { context.charge(gas_params.bcs_to_bytes_failure)?; @@ -135,7 +140,12 @@ fn serialized_size_impl( // implement it in a more efficient way. let value = reference.read_ref()?; let ty_layout = context.type_to_type_layout(ty)?; - serialized_size_allowing_delayed_values(&value, &ty_layout) + + ValueSerDeContext::new() + .with_legacy_signer() + .with_func_args_deserialization(context.function_value_extension()) + .with_delayed_fields_serde() + .serialized_size(&value, &ty_layout) } /*************************************************************************************************** diff --git a/crates/natives/src/move_stdlib/unit_test.rs b/crates/natives/src/move_stdlib/unit_test.rs index 9bc2dba7..f60bbed4 100644 --- a/crates/natives/src/move_stdlib/unit_test.rs +++ b/crates/natives/src/move_stdlib/unit_test.rs @@ -37,7 +37,7 @@ fn native_create_signers_for_testing( let num_signers = safely_pop_arg!(arguments, u64); let signers = Value::vector_for_testing_only( - (0..num_signers).map(|i| Value::signer(AccountAddress::new(to_le_bytes(i)))), + (0..num_signers).map(|i| Value::master_signer(AccountAddress::new(to_le_bytes(i)))), ); Ok(smallvec![signers]) diff --git a/crates/natives/src/string_utils.rs b/crates/natives/src/string_utils.rs index 3b4ea10b..0e8ac118 100644 --- a/crates/natives/src/string_utils.rs +++ b/crates/natives/src/string_utils.rs @@ -6,7 +6,7 @@ use move_core_types::{ account_address::AccountAddress, language_storage::TypeTag, u256, - value::{MoveFieldLayout, MoveStructLayout, MoveTypeLayout}, + value::{MoveFieldLayout, MoveStructLayout, MoveTypeLayout, MASTER_ADDRESS_FIELD_OFFSET}, }; use move_vm_runtime::native_functions::NativeFunction; use move_vm_types::{ @@ -188,7 +188,8 @@ fn native_format_impl( let addr = val .value_as::()? .unpack()? - .next() + // The second field of a signer is always the master address regardless of which variants. + .nth(MASTER_ADDRESS_FIELD_OFFSET) .unwrap() .value_as::()?; @@ -386,7 +387,6 @@ fn native_format( abort_code: EUNABLE_TO_FORMAT_DELAYED_FIELD, }); } - let ty = context .deref() .type_to_fully_annotated_layout(&ty_args[0])?; diff --git a/crates/natives/src/table.rs b/crates/natives/src/table.rs index c6c540f3..7eca0ed0 100644 --- a/crates/natives/src/table.rs +++ b/crates/natives/src/table.rs @@ -10,6 +10,7 @@ use move_core_types::{ vm_status::StatusCode, }; use move_vm_runtime::native_functions::{NativeContext, NativeFunctionTable}; +use move_vm_types::value_serde::{FunctionValueExtension, ValueSerDeContext}; use move_vm_types::values::{Struct, Vector}; use move_vm_types::{ loaded_data::runtime_types::Type, @@ -27,6 +28,7 @@ use std::{ use crate::interface::{ RawSafeNative, SafeNativeBuilder, SafeNativeContext, SafeNativeError, SafeNativeResult, }; + use crate::safely_pop_arg; /// UID prefix is used to generate unique address from the txn hash. @@ -118,7 +120,10 @@ impl<'a> NativeTableContext<'a> { } /// Computes the change set from a NativeTableContext. - pub fn into_change_set(self) -> PartialVMResult { + pub fn into_change_set( + self, + function_extension: Option<&dyn FunctionValueExtension>, + ) -> PartialVMResult { let NativeTableContext { table_data, .. } = self; let TableData { new_tables, @@ -141,11 +146,11 @@ impl<'a> NativeTableContext<'a> { match op { Op::New(val) => { - let bytes = serialize(&value_layout, &val)?; + let bytes = serialize(function_extension, &value_layout, &val)?; entries.insert(key, Op::New(bytes)); } Op::Modify(val) => { - let bytes = serialize(&value_layout, &val)?; + let bytes = serialize(function_extension, &value_layout, &val)?; entries.insert(key, Op::Modify(bytes)); } Op::Delete => { @@ -201,19 +206,25 @@ impl TableData { impl Table { fn get_or_create_global_value( &mut self, - context: &NativeTableContext, + context: &NativeContext, key: Vec, ) -> PartialVMResult<(&mut GlobalValue, Option>)> { Ok(match self.content.entry(key) { Entry::Vacant(entry) => { let (gv, loaded) = match context + .extensions() + .get::() .resolver .resolve_table_entry(&self.handle, entry.key()) .map_err(|err| { partial_extension_error(format!("remote table resolver failure: {}", err)) })? { Some(val_bytes) => { - let val = deserialize(&self.value_layout, &val_bytes)?; + let val = deserialize( + Some(context.function_value_extension()), + &self.value_layout, + &val_bytes, + )?; ( GlobalValue::cached(val)?, Some(NumBytes::new(val_bytes.len() as u64)), @@ -356,10 +367,14 @@ fn native_add_box( let table = table_data.get_or_create_table(context, handle, &ty_args[0], &ty_args[2])?; - let key_bytes = serialize(&table.key_layout, &key)?; + let key_bytes = serialize( + Some(context.function_value_extension()), + &table.key_layout, + &key, + )?; let key_cost = gas_params.add_box_per_byte_serialized * NumBytes::new(key_bytes.len() as u64); - let (gv, loaded) = table.get_or_create_global_value(table_context, key_bytes)?; + let (gv, loaded) = table.get_or_create_global_value(context, key_bytes)?; let res = match gv.move_to(val) { Ok(_) => Ok(smallvec![]), @@ -397,11 +412,15 @@ fn native_borrow_box( let table = table_data.get_or_create_table(context, handle, &ty_args[0], &ty_args[2])?; - let key_bytes = serialize(&table.key_layout, &key)?; + let key_bytes = serialize( + Some(context.function_value_extension()), + &table.key_layout, + &key, + )?; let key_cost = gas_params.borrow_box_per_byte_serialized * NumBytes::new(key_bytes.len() as u64); - let (gv, loaded) = table.get_or_create_global_value(table_context, key_bytes)?; + let (gv, loaded) = table.get_or_create_global_value(context, key_bytes)?; let res = match gv.borrow_global() { Ok(ref_val) => Ok(smallvec![ref_val]), @@ -439,11 +458,15 @@ fn native_contains_box( let table = table_data.get_or_create_table(context, handle, &ty_args[0], &ty_args[2])?; - let key_bytes = serialize(&table.key_layout, &key)?; + let key_bytes = serialize( + Some(context.function_value_extension()), + &table.key_layout, + &key, + )?; let key_cost = gas_params.contains_box_per_byte_serialized * NumBytes::new(key_bytes.len() as u64); - let (gv, loaded) = table.get_or_create_global_value(table_context, key_bytes)?; + let (gv, loaded) = table.get_or_create_global_value(context, key_bytes)?; let exists = Value::bool(gv.exists()?); @@ -476,11 +499,15 @@ fn native_remove_box( let table = table_data.get_or_create_table(context, handle, &ty_args[0], &ty_args[2])?; - let key_bytes = serialize(&table.key_layout, &key)?; + let key_bytes = serialize( + Some(context.function_value_extension()), + &table.key_layout, + &key, + )?; let key_cost = gas_params.remove_box_per_byte_serialized * NumBytes::new(key_bytes.len() as u64); - let (gv, loaded) = table.get_or_create_global_value(table_context, key_bytes)?; + let (gv, loaded) = table.get_or_create_global_value(context, key_bytes)?; let res = match gv.move_from() { Ok(val) => Ok(smallvec![val]), @@ -706,13 +733,30 @@ fn get_iterator_id(table_iter: &StructRef) -> PartialVMResult { Ok(iterator_id) } -fn serialize(layout: &MoveTypeLayout, val: &Value) -> PartialVMResult> { - val.simple_serialize(layout) +fn serialize( + function_extension: Option<&dyn FunctionValueExtension>, + layout: &MoveTypeLayout, + val: &Value, +) -> PartialVMResult> { + let mut ctx = ValueSerDeContext::new().with_legacy_signer(); + if let Some(fext) = function_extension { + ctx = ctx.with_func_args_deserialization(fext) + } + ctx.serialize(val, layout)? .ok_or_else(|| partial_extension_error("cannot serialize table key or value")) } -fn deserialize(layout: &MoveTypeLayout, bytes: &[u8]) -> PartialVMResult { - Value::simple_deserialize(bytes, layout) +fn deserialize( + function_extension: Option<&dyn FunctionValueExtension>, + layout: &MoveTypeLayout, + bytes: &[u8], +) -> PartialVMResult { + let mut ctx = ValueSerDeContext::new().with_legacy_signer(); + if let Some(function_extension) = function_extension { + ctx = ctx.with_func_args_deserialization(function_extension) + } + + ctx.deserialize(bytes, layout) .ok_or_else(|| partial_extension_error("cannot deserialize table key or value")) } @@ -809,9 +853,13 @@ fn load_table_entry( let table = table_data.get_or_create_table(context, handle, key_type, value_type)?; let key_layout = table.key_layout.clone(); - let (gv, loaded) = table.get_or_create_global_value(table_context, key_bytes.clone())?; + let (gv, loaded) = table.get_or_create_global_value(context, key_bytes.clone())?; let (key_value, serialized) = if gv.exists()? { - let key = deserialize(&key_layout, &key_bytes)?; + let key = deserialize( + Some(context.function_value_extension()), + &key_layout, + &key_bytes, + )?; let value = gv.borrow_global()?; ( Some((key, value)), diff --git a/crates/storage/src/code_scale.rs b/crates/storage/src/code_scale.rs index eda0b95b..912928ac 100644 --- a/crates/storage/src/code_scale.rs +++ b/crates/storage/src/code_scale.rs @@ -8,7 +8,6 @@ use move_vm_runtime::Script; use move_vm_types::code::{Code, ModuleCode}; use crate::module_cache::BytesWithHash; -use crate::module_cache::NoVersion; use crate::state_view::Checksum; pub struct ScriptScale; @@ -41,13 +40,13 @@ impl ScriptWrapper { #[derive(Clone)] pub struct ModuleWrapper { - pub module_code: Arc>, + pub module_code: Arc>, pub size: usize, } impl ModuleWrapper { pub fn new( - module_code: Arc>, + module_code: Arc>, size: usize, ) -> Self { Self { module_code, size } diff --git a/crates/storage/src/code_storage.rs b/crates/storage/src/code_storage.rs index 2f512ae8..415a774e 100644 --- a/crates/storage/src/code_storage.rs +++ b/crates/storage/src/code_storage.rs @@ -7,8 +7,8 @@ use move_binary_format::{errors::VMResult, file_format::CompiledScript, Compiled use move_core_types::{account_address::AccountAddress, identifier::IdentStr, metadata::Metadata}; use move_vm_runtime::{ ambassador_impl_ModuleStorage, ambassador_impl_WithRuntimeEnvironment, - logging::expect_no_verification_errors, CodeStorage, Module, ModuleStorage, RuntimeEnvironment, - Script, WithRuntimeEnvironment, + logging::expect_no_verification_errors, CodeStorage, Function, Module, ModuleStorage, + RuntimeEnvironment, Script, WithRuntimeEnvironment, }; use move_vm_types::{code::ModuleBytesStorage, module_linker_error, sha3_256}; use std::sync::Arc; @@ -21,6 +21,11 @@ use crate::{ state_view::ChecksumStorage, }; +use move_binary_format::errors::PartialVMResult; +use move_core_types::language_storage::TypeTag; +use move_vm_types::loaded_data::runtime_types::StructType; +use move_vm_types::loaded_data::runtime_types::Type; + /// Code storage that stores both modules and scripts (not thread-safe). #[allow(clippy::duplicated_attributes)] #[derive(Delegate)] diff --git a/crates/storage/src/initia_storage.rs b/crates/storage/src/initia_storage.rs index f6d788eb..3ff9f91f 100644 --- a/crates/storage/src/initia_storage.rs +++ b/crates/storage/src/initia_storage.rs @@ -8,13 +8,17 @@ use crate::{ }; use ambassador::Delegate; use bytes::Bytes; +use move_binary_format::errors::PartialVMResult; use move_binary_format::{errors::VMResult, file_format::CompiledScript, CompiledModule}; +use move_core_types::language_storage::TypeTag; use move_core_types::{account_address::AccountAddress, identifier::IdentStr, metadata::Metadata}; use move_vm_runtime::{ ambassador_impl_CodeStorage, ambassador_impl_ModuleStorage, - ambassador_impl_WithRuntimeEnvironment, CodeStorage, Module, ModuleStorage, RuntimeEnvironment, - Script, WithRuntimeEnvironment, + ambassador_impl_WithRuntimeEnvironment, CodeStorage, Function, Module, ModuleStorage, + RuntimeEnvironment, Script, WithRuntimeEnvironment, }; +use move_vm_types::loaded_data::runtime_types::StructType; +use move_vm_types::loaded_data::runtime_types::Type; use std::sync::Arc; #[derive(Delegate)] diff --git a/crates/storage/src/module_cache.rs b/crates/storage/src/module_cache.rs index 4a94aac7..e5cfbc47 100644 --- a/crates/storage/src/module_cache.rs +++ b/crates/storage/src/module_cache.rs @@ -77,7 +77,6 @@ impl InitiaModuleCache { deserialized_code: CompiledModule, allocated_size: usize, extension: Arc, - version: NoVersion, ) -> VMResult<()> { // cache is too small to hold this module if self.capacity < allocated_size { @@ -96,11 +95,7 @@ impl InitiaModuleCache { Some(_) => Ok(()), None => { let module_id = deserialized_code.self_id(); - let module = Arc::new(ModuleCode::from_deserialized( - deserialized_code, - extension, - version, - )); + let module = Arc::new(ModuleCode::from_deserialized(deserialized_code, extension)); // NOTE: We are not handling the error here, because we are sure that the // allocated size is less than the capacity. @@ -118,15 +113,14 @@ impl InitiaModuleCache { verified_code: Module, allocated_size: usize, extension: Arc, - version: NoVersion, - ) -> VMResult>> { + ) -> VMResult>> { let mut module_cache = self.module_cache.lock(); match module_cache.get(&key) { Some(module_wrapper) if module_wrapper.module_code.code().is_verified() => { Ok(module_wrapper.module_code.clone()) } _ => { - let module = Arc::new(ModuleCode::from_verified(verified_code, extension, version)); + let module = Arc::new(ModuleCode::from_verified(verified_code, extension)); if self.capacity >= allocated_size { // NOTE: We are not handling the error here, because we are sure that the // allocated size is less than the capacity. @@ -155,7 +149,6 @@ impl InitiaModuleCache { Deserialized = CompiledModule, Verified = Module, Extension = BytesWithHash, - Version = NoVersion, >, ) -> VMResult> { let mut module_cache = self.module_cache.lock(); diff --git a/crates/storage/src/module_storage.rs b/crates/storage/src/module_storage.rs index 10758f54..13a00d2b 100644 --- a/crates/storage/src/module_storage.rs +++ b/crates/storage/src/module_storage.rs @@ -4,23 +4,30 @@ use crate::{ allocator::get_size, code_scale::ModuleWrapper, - module_cache::{BytesWithHash, InitiaModuleCache, NoVersion}, + module_cache::{BytesWithHash, InitiaModuleCache}, state_view::{Checksum, ChecksumStorage}, }; use bytes::Bytes; use move_binary_format::{ - errors::{Location, PartialVMError, VMResult}, + errors::{Location, PartialVMError, PartialVMResult, VMResult}, CompiledModule, }; use move_core_types::{ - account_address::AccountAddress, identifier::IdentStr, language_storage::ModuleId, - metadata::Metadata, vm_status::StatusCode, + account_address::AccountAddress, + identifier::IdentStr, + language_storage::{ModuleId, TypeTag}, + metadata::Metadata, + vm_status::StatusCode, }; use move_vm_runtime::{Module, ModuleStorage, RuntimeEnvironment, WithRuntimeEnvironment}; +use move_vm_types::code::WithSize; +use move_vm_types::sha3_256; use move_vm_types::{ code::{ModuleBytesStorage, ModuleCode, ModuleCodeBuilder, WithBytes, WithHash}, + loaded_data::runtime_types::Type, module_cyclic_dependency_error, module_linker_error, + value_serde::FunctionValueExtension, }; use std::{borrow::Borrow, collections::HashSet, ops::Deref, sync::Arc}; @@ -144,14 +151,11 @@ impl<'s, S: ModuleBytesStorage + ChecksumStorage> ModuleCodeBuilder for InitiaMo type Extension = BytesWithHash; type Key = ModuleId; type Verified = Module; - type Version = NoVersion; fn build( &self, key: &Self::Key, - ) -> VMResult< - Option>, - > { + ) -> VMResult>> { let bytes = match self .base_storage .fetch_module_bytes(key.address(), key.name())? @@ -168,10 +172,12 @@ impl<'s, S: ModuleBytesStorage + ChecksumStorage> ModuleCodeBuilder for InitiaMo None => return Ok(None), }; - let (compiled_module, _, hash) = self + let compiled_module = self .runtime_environment() .deserialize_into_compiled_module(&bytes)?; + let hash = sha3_256(&bytes); + if checksum != hash { return Err( PartialVMError::new(StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR) @@ -181,7 +187,7 @@ impl<'s, S: ModuleBytesStorage + ChecksumStorage> ModuleCodeBuilder for InitiaMo } let extension = Arc::new(BytesWithHash::new(bytes, hash)); - let module = ModuleCode::from_deserialized(compiled_module, extension, NoVersion); + let module = ModuleCode::from_deserialized(compiled_module, extension); Ok(Some(module)) } } @@ -406,11 +412,60 @@ fn visit_dependencies_and_verify( verified_code, allocated_size_for_verified + unverified_module_wrapper.size, module.extension().clone(), - module.version(), )?; Ok(module.code().verified().clone()) } +/// Avoids the orphan rule to implement external [FunctionValueExtension] for any generic type that +/// implements [ModuleStorage]. +pub struct FunctionValueExtensionAdapter<'a> { + pub(crate) module_storage: &'a dyn ModuleStorage, +} + +pub trait AsFunctionValueExtension { + fn as_function_value_extension(&self) -> FunctionValueExtensionAdapter; +} + +impl AsFunctionValueExtension for T { + fn as_function_value_extension(&self) -> FunctionValueExtensionAdapter { + FunctionValueExtensionAdapter { + module_storage: self, + } + } +} + +impl<'a> FunctionValueExtension for FunctionValueExtensionAdapter<'a> { + fn get_function_arg_tys( + &self, + module_id: &ModuleId, + function_name: &IdentStr, + substitution_ty_arg_tags: Vec, + ) -> PartialVMResult> { + let substitution_ty_args = substitution_ty_arg_tags + .into_iter() + .map(|tag| self.module_storage.fetch_ty(&tag)) + .collect::>>()?; + + let (_, function) = self + .module_storage + .fetch_function_definition(module_id.address(), module_id.name(), function_name) + .map_err(|err| err.to_partial())?; + + let ty_builder = &self + .module_storage + .runtime_environment() + .vm_config() + .ty_builder; + function + .param_tys() + .iter() + .map(|ty_to_substitute| { + ty_builder.create_ty_with_subst(ty_to_substitute, &substitution_ty_args) + }) + .collect::>>() + } +} + /// Represents owned or borrowed types, similar to [std::borrow::Cow] but without enforcing /// [ToOwned] trait bound on types it stores. We use it to be able to construct different storages /// that capture or borrow underlying byte storage. diff --git a/crates/storage/src/state_view_impl.rs b/crates/storage/src/state_view_impl.rs index fafa8395..2930b5e6 100644 --- a/crates/storage/src/state_view_impl.rs +++ b/crates/storage/src/state_view_impl.rs @@ -146,7 +146,8 @@ impl<'s, S: StateView> CompiledModuleView for StateViewImpl<'s, S> { let bytes = self.get_module(id)?; let module = match bytes { Some(bytes) => { - CompiledModule::deserialize_with_config(&bytes, &self.deserialize_config).map_err(|e| anyhow::anyhow!(e.to_string()))? + CompiledModule::deserialize_with_config(&bytes, &self.deserialize_config) + .map_err(|e| anyhow::anyhow!(e.to_string()))? } None => return Ok(None), }; diff --git a/crates/vm/src/initia_vm.rs b/crates/vm/src/initia_vm.rs index 4002ba73..0e13a701 100644 --- a/crates/vm/src/initia_vm.rs +++ b/crates/vm/src/initia_vm.rs @@ -87,7 +87,7 @@ impl InitiaVM { pub fn new(initia_vm_config: InitiaVMConfig) -> Self { let gas_params = NativeGasParameters::initial(); let misc_params = MiscGasParameters::initial(); - + let vm_config = VMConfig { verifier_config: verifier_config(), use_loader_v2: true, diff --git a/crates/vm/src/publish.rs b/crates/vm/src/publish.rs index 08ffbc5a..b6c98b11 100644 --- a/crates/vm/src/publish.rs +++ b/crates/vm/src/publish.rs @@ -67,7 +67,7 @@ impl<'r, 'l> SessionExt<'r, 'l> { let staging_module_storage = StagingModuleStorage::create_with_compat_config( &publisher, - Compatibility::new(true, false), + Compatibility::new(true, false, false), code_storage, module_bundle.into_bytes(), )?; diff --git a/crates/vm/src/session.rs b/crates/vm/src/session.rs index 9ddf25ba..422660e7 100644 --- a/crates/vm/src/session.rs +++ b/crates/vm/src/session.rs @@ -1,7 +1,6 @@ use std::{ collections::BTreeMap, ops::{Deref, DerefMut}, - sync::Arc, }; use bytes::Bytes; @@ -23,17 +22,16 @@ use initia_move_types::{ write_set::{WriteOp, WriteSet}, }; +use initia_move_storage::module_storage::AsFunctionValueExtension; use move_binary_format::errors::{Location, PartialVMError, PartialVMResult, VMResult}; use move_core_types::{ effects::Op, + identifier::Identifier, language_storage::{ModuleId, TypeTag}, vm_status::StatusCode, }; use move_vm_runtime::{session::Session, ModuleStorage}; -use move_vm_types::{ - loaded_data::runtime_types::{StructNameIndex, StructType, Type}, - sha3_256, -}; +use move_vm_types::{loaded_data::runtime_types::Type, sha3_256}; pub type SessionOutput<'r> = ( Vec, @@ -64,7 +62,7 @@ impl<'r, 'l> SessionExt<'r, 'l> { let table_context: NativeTableContext = extensions.remove::(); let table_change_set = table_context - .into_change_set() + .into_change_set(Some(&module_storage.as_function_value_extension())) .map_err(|e| e.finish(Location::Undefined))?; let cosmos_context: NativeCosmosContext = extensions.remove::(); @@ -128,12 +126,12 @@ impl<'r, 'l> SessionExt<'r, 'l> { } impl StructResolver for SessionExt<'_, '_> { - fn get_struct_type( + fn get_struct_name( &self, - index: StructNameIndex, + ty: &Type, module_storage: &impl ModuleStorage, - ) -> Option> { - self.inner.fetch_struct_ty_by_idx(index, module_storage) + ) -> PartialVMResult> { + self.inner.get_struct_name(ty, module_storage) } fn type_to_type_tag( diff --git a/crates/vm/src/verifier/transaction_arg_validation.rs b/crates/vm/src/verifier/transaction_arg_validation.rs index b3bea33b..c7f428b7 100644 --- a/crates/vm/src/verifier/transaction_arg_validation.rs +++ b/crates/vm/src/verifier/transaction_arg_validation.rs @@ -215,11 +215,14 @@ pub(crate) fn is_valid_txn_arg( match ty { Bool | U8 | U16 | U32 | U64 | U128 | U256 | Address => true, Vector(inner) => is_valid_txn_arg(session, module_storage, inner, allowed_structs), - Struct { idx, .. } | StructInstantiation { idx, .. } => session - .fetch_struct_ty_by_idx(*idx, module_storage) - .is_some_and(|st| { - let full_name = format!("{}::{}", st.module.short_str_lossless(), st.name); - allowed_structs.contains_key(&full_name) + Struct { .. } | StructInstantiation { .. } => session + .get_struct_name(ty, module_storage) + .is_ok_and(|st| match st { + Some(st) => { + let full_name = format!("{}::{}", st.0.short_str_lossless(), st.1); + allowed_structs.contains_key(&full_name) + } + None => false, }), Signer | Reference(_) | MutableReference(_) | TyParam(_) => false, } @@ -375,12 +378,13 @@ pub(crate) fn recursively_construct_arg( len -= 1; } } - Struct { idx, .. } | StructInstantiation { idx, .. } => { + Struct { .. } | StructInstantiation { .. } => { let st = session - .fetch_struct_ty_by_idx(*idx, module_storage) + .get_struct_name(ty, module_storage) + .map_err(|e| e.finish(Location::Undefined))? .ok_or_else(invalid_signature)?; - let full_name = format!("{}::{}", st.module.short_str_lossless(), st.name); + let full_name = format!("{}::{}", st.0.short_str_lossless(), st.1); let constructor = allowed_structs .get(&full_name) .ok_or_else(invalid_signature)?; diff --git a/libmovevm/src/move_api/bytecode.rs b/libmovevm/src/move_api/bytecode.rs index 62212820..c753a9e1 100644 --- a/libmovevm/src/move_api/bytecode.rs +++ b/libmovevm/src/move_api/bytecode.rs @@ -84,6 +84,10 @@ pub trait Bytecode { mutable: true, to: Box::new(self.new_move_type(t.borrow())), }, + SignatureToken::Function(..) => { + // TODO + unimplemented!("signature token function to API MoveType") + } } } diff --git a/libmovevm/src/move_api/move_types.rs b/libmovevm/src/move_api/move_types.rs index c34fc742..b6ea3421 100644 --- a/libmovevm/src/move_api/move_types.rs +++ b/libmovevm/src/move_api/move_types.rs @@ -4,12 +4,11 @@ use initia_move_types::module::Module; use move_binary_format::{ access::ModuleAccess, deserializer::DeserializerConfig, - file_format::{ - Ability, AbilitySet, CompiledModule, CompiledScript, StructTypeParameter, Visibility, - }, + file_format::{CompiledModule, CompiledScript, StructTypeParameter, Visibility}, }; use move_core_types::{ self, + ability::{Ability, AbilitySet}, account_address::AccountAddress, identifier::Identifier, language_storage::{ModuleId, StructTag, TypeTag}, @@ -1227,8 +1226,8 @@ pub fn verify_identifier(identifier: &str) -> anyhow::Result<()> { mod tests { use super::*; - use move_binary_format::file_format::AbilitySet; use move_core_types::{ + ability::AbilitySet, account_address::AccountAddress, identifier::Identifier, language_storage::{StructTag, TypeTag}, diff --git a/precompile/binaries/minlib/account.mv b/precompile/binaries/minlib/account.mv index ac74d88f..3138da40 100644 Binary files a/precompile/binaries/minlib/account.mv and b/precompile/binaries/minlib/account.mv differ diff --git a/precompile/binaries/minlib/ascii.mv b/precompile/binaries/minlib/ascii.mv index bd763871..86fb14c1 100644 Binary files a/precompile/binaries/minlib/ascii.mv and b/precompile/binaries/minlib/ascii.mv differ diff --git a/precompile/binaries/minlib/bigdecimal.mv b/precompile/binaries/minlib/bigdecimal.mv index 159ecb77..73bf59fd 100644 Binary files a/precompile/binaries/minlib/bigdecimal.mv and b/precompile/binaries/minlib/bigdecimal.mv differ diff --git a/precompile/binaries/minlib/biguint.mv b/precompile/binaries/minlib/biguint.mv index 5df3f7a4..0fcd32e3 100644 Binary files a/precompile/binaries/minlib/biguint.mv and b/precompile/binaries/minlib/biguint.mv differ diff --git a/precompile/binaries/minlib/bit_vector.mv b/precompile/binaries/minlib/bit_vector.mv index bc6fbc4c..62ae7d03 100644 Binary files a/precompile/binaries/minlib/bit_vector.mv and b/precompile/binaries/minlib/bit_vector.mv differ diff --git a/precompile/binaries/minlib/capability.mv b/precompile/binaries/minlib/capability.mv index 8aa96019..9b759b35 100644 Binary files a/precompile/binaries/minlib/capability.mv and b/precompile/binaries/minlib/capability.mv differ diff --git a/precompile/binaries/minlib/code.mv b/precompile/binaries/minlib/code.mv index 06ca1615..913001a6 100644 Binary files a/precompile/binaries/minlib/code.mv and b/precompile/binaries/minlib/code.mv differ diff --git a/precompile/binaries/minlib/coin.mv b/precompile/binaries/minlib/coin.mv index 5cfbc974..f55b3429 100644 Binary files a/precompile/binaries/minlib/coin.mv and b/precompile/binaries/minlib/coin.mv differ diff --git a/precompile/binaries/minlib/collection.mv b/precompile/binaries/minlib/collection.mv index 07ce7f53..a63e63dc 100644 Binary files a/precompile/binaries/minlib/collection.mv and b/precompile/binaries/minlib/collection.mv differ diff --git a/precompile/binaries/minlib/comparator.mv b/precompile/binaries/minlib/comparator.mv index 8ef60db2..9bf9dfa0 100644 Binary files a/precompile/binaries/minlib/comparator.mv and b/precompile/binaries/minlib/comparator.mv differ diff --git a/precompile/binaries/minlib/compare.mv b/precompile/binaries/minlib/compare.mv index 1256b190..d4c91e08 100644 Binary files a/precompile/binaries/minlib/compare.mv and b/precompile/binaries/minlib/compare.mv differ diff --git a/precompile/binaries/minlib/cosmos.mv b/precompile/binaries/minlib/cosmos.mv index 02aab079..d528592a 100644 Binary files a/precompile/binaries/minlib/cosmos.mv and b/precompile/binaries/minlib/cosmos.mv differ diff --git a/precompile/binaries/minlib/dex.mv b/precompile/binaries/minlib/dex.mv index f081c756..abf28974 100644 Binary files a/precompile/binaries/minlib/dex.mv and b/precompile/binaries/minlib/dex.mv differ diff --git a/precompile/binaries/minlib/dispatchable_fungible_asset.mv b/precompile/binaries/minlib/dispatchable_fungible_asset.mv index 8ddf36a4..49aec94c 100644 Binary files a/precompile/binaries/minlib/dispatchable_fungible_asset.mv and b/precompile/binaries/minlib/dispatchable_fungible_asset.mv differ diff --git a/precompile/binaries/minlib/ed25519.mv b/precompile/binaries/minlib/ed25519.mv index 81d32d13..2431769e 100644 Binary files a/precompile/binaries/minlib/ed25519.mv and b/precompile/binaries/minlib/ed25519.mv differ diff --git a/precompile/binaries/minlib/error.mv b/precompile/binaries/minlib/error.mv index 97f7360c..714db97b 100644 Binary files a/precompile/binaries/minlib/error.mv and b/precompile/binaries/minlib/error.mv differ diff --git a/precompile/binaries/minlib/fixed_point32.mv b/precompile/binaries/minlib/fixed_point32.mv index 46998389..6a8334ca 100644 Binary files a/precompile/binaries/minlib/fixed_point32.mv and b/precompile/binaries/minlib/fixed_point32.mv differ diff --git a/precompile/binaries/minlib/fixed_point64.mv b/precompile/binaries/minlib/fixed_point64.mv index 0401e7cf..26707195 100644 Binary files a/precompile/binaries/minlib/fixed_point64.mv and b/precompile/binaries/minlib/fixed_point64.mv differ diff --git a/precompile/binaries/minlib/from_bcs.mv b/precompile/binaries/minlib/from_bcs.mv index 2c030eb8..93aebdca 100644 Binary files a/precompile/binaries/minlib/from_bcs.mv and b/precompile/binaries/minlib/from_bcs.mv differ diff --git a/precompile/binaries/minlib/fungible_asset.mv b/precompile/binaries/minlib/fungible_asset.mv index 550f2f18..1b37beee 100644 Binary files a/precompile/binaries/minlib/fungible_asset.mv and b/precompile/binaries/minlib/fungible_asset.mv differ diff --git a/precompile/binaries/minlib/guid.mv b/precompile/binaries/minlib/guid.mv index 1b532b8d..514da171 100644 Binary files a/precompile/binaries/minlib/guid.mv and b/precompile/binaries/minlib/guid.mv differ diff --git a/precompile/binaries/minlib/hex.mv b/precompile/binaries/minlib/hex.mv index ac7d6c0e..d4884267 100644 Binary files a/precompile/binaries/minlib/hex.mv and b/precompile/binaries/minlib/hex.mv differ diff --git a/precompile/binaries/minlib/initia_nft.mv b/precompile/binaries/minlib/initia_nft.mv index b7c9afc7..e1ed6529 100644 Binary files a/precompile/binaries/minlib/initia_nft.mv and b/precompile/binaries/minlib/initia_nft.mv differ diff --git a/precompile/binaries/minlib/json.mv b/precompile/binaries/minlib/json.mv index 51431a89..ca859865 100644 Binary files a/precompile/binaries/minlib/json.mv and b/precompile/binaries/minlib/json.mv differ diff --git a/precompile/binaries/minlib/math128.mv b/precompile/binaries/minlib/math128.mv index 99ccb71b..09152cec 100644 Binary files a/precompile/binaries/minlib/math128.mv and b/precompile/binaries/minlib/math128.mv differ diff --git a/precompile/binaries/minlib/math64.mv b/precompile/binaries/minlib/math64.mv index ec22cfbf..0abdd85a 100644 Binary files a/precompile/binaries/minlib/math64.mv and b/precompile/binaries/minlib/math64.mv differ diff --git a/precompile/binaries/minlib/multisig.mv b/precompile/binaries/minlib/multisig.mv index 71550f9c..d816b61f 100644 Binary files a/precompile/binaries/minlib/multisig.mv and b/precompile/binaries/minlib/multisig.mv differ diff --git a/precompile/binaries/minlib/multisig_v2.mv b/precompile/binaries/minlib/multisig_v2.mv index b7554715..0fee7cf5 100644 Binary files a/precompile/binaries/minlib/multisig_v2.mv and b/precompile/binaries/minlib/multisig_v2.mv differ diff --git a/precompile/binaries/minlib/nft.mv b/precompile/binaries/minlib/nft.mv index af22c911..9f8076e3 100644 Binary files a/precompile/binaries/minlib/nft.mv and b/precompile/binaries/minlib/nft.mv differ diff --git a/precompile/binaries/minlib/object.mv b/precompile/binaries/minlib/object.mv index 4a7c9c7c..33e23adf 100644 Binary files a/precompile/binaries/minlib/object.mv and b/precompile/binaries/minlib/object.mv differ diff --git a/precompile/binaries/minlib/object_code_deployment.mv b/precompile/binaries/minlib/object_code_deployment.mv index e1fdf2b7..2714e50a 100644 Binary files a/precompile/binaries/minlib/object_code_deployment.mv and b/precompile/binaries/minlib/object_code_deployment.mv differ diff --git a/precompile/binaries/minlib/option.mv b/precompile/binaries/minlib/option.mv index 2e75c7b8..fc56339e 100644 Binary files a/precompile/binaries/minlib/option.mv and b/precompile/binaries/minlib/option.mv differ diff --git a/precompile/binaries/minlib/primary_fungible_store.mv b/precompile/binaries/minlib/primary_fungible_store.mv index d120e781..84931f7c 100644 Binary files a/precompile/binaries/minlib/primary_fungible_store.mv and b/precompile/binaries/minlib/primary_fungible_store.mv differ diff --git a/precompile/binaries/minlib/property_map.mv b/precompile/binaries/minlib/property_map.mv index f9dc5967..e415c6e5 100644 Binary files a/precompile/binaries/minlib/property_map.mv and b/precompile/binaries/minlib/property_map.mv differ diff --git a/precompile/binaries/minlib/royalty.mv b/precompile/binaries/minlib/royalty.mv index ebc23375..004a8525 100644 Binary files a/precompile/binaries/minlib/royalty.mv and b/precompile/binaries/minlib/royalty.mv differ diff --git a/precompile/binaries/minlib/secp256k1.mv b/precompile/binaries/minlib/secp256k1.mv index d290f138..267106e0 100644 Binary files a/precompile/binaries/minlib/secp256k1.mv and b/precompile/binaries/minlib/secp256k1.mv differ diff --git a/precompile/binaries/minlib/simple_map.mv b/precompile/binaries/minlib/simple_map.mv index 147ee396..998e8836 100644 Binary files a/precompile/binaries/minlib/simple_map.mv and b/precompile/binaries/minlib/simple_map.mv differ diff --git a/precompile/binaries/minlib/simple_nft.mv b/precompile/binaries/minlib/simple_nft.mv index 20c655e9..9c69d36b 100644 Binary files a/precompile/binaries/minlib/simple_nft.mv and b/precompile/binaries/minlib/simple_nft.mv differ diff --git a/precompile/binaries/minlib/soul_bound_token.mv b/precompile/binaries/minlib/soul_bound_token.mv index 5fd76206..e1aa468d 100644 Binary files a/precompile/binaries/minlib/soul_bound_token.mv and b/precompile/binaries/minlib/soul_bound_token.mv differ diff --git a/precompile/binaries/minlib/string.mv b/precompile/binaries/minlib/string.mv index f2f46ef1..af32c575 100644 Binary files a/precompile/binaries/minlib/string.mv and b/precompile/binaries/minlib/string.mv differ diff --git a/precompile/binaries/minlib/string_utils.mv b/precompile/binaries/minlib/string_utils.mv index ab190016..ea4c6948 100644 Binary files a/precompile/binaries/minlib/string_utils.mv and b/precompile/binaries/minlib/string_utils.mv differ diff --git a/precompile/binaries/minlib/table.mv b/precompile/binaries/minlib/table.mv index 50b1c00c..6252a883 100644 Binary files a/precompile/binaries/minlib/table.mv and b/precompile/binaries/minlib/table.mv differ diff --git a/precompile/binaries/minlib/table_key.mv b/precompile/binaries/minlib/table_key.mv index 2bd90154..ee84130e 100644 Binary files a/precompile/binaries/minlib/table_key.mv and b/precompile/binaries/minlib/table_key.mv differ diff --git a/precompile/binaries/minlib/vector.mv b/precompile/binaries/minlib/vector.mv index 989ab5e2..edce2a87 100644 Binary files a/precompile/binaries/minlib/vector.mv and b/precompile/binaries/minlib/vector.mv differ diff --git a/precompile/binaries/minlib/vip_score.mv b/precompile/binaries/minlib/vip_score.mv index bd89797d..72fb2a14 100644 Binary files a/precompile/binaries/minlib/vip_score.mv and b/precompile/binaries/minlib/vip_score.mv differ diff --git a/precompile/binaries/stdlib/account.mv b/precompile/binaries/stdlib/account.mv index e2238c5b..cb07d8c7 100644 Binary files a/precompile/binaries/stdlib/account.mv and b/precompile/binaries/stdlib/account.mv differ diff --git a/precompile/binaries/stdlib/ascii.mv b/precompile/binaries/stdlib/ascii.mv index bd763871..86fb14c1 100644 Binary files a/precompile/binaries/stdlib/ascii.mv and b/precompile/binaries/stdlib/ascii.mv differ diff --git a/precompile/binaries/stdlib/bigdecimal.mv b/precompile/binaries/stdlib/bigdecimal.mv index 159ecb77..73bf59fd 100644 Binary files a/precompile/binaries/stdlib/bigdecimal.mv and b/precompile/binaries/stdlib/bigdecimal.mv differ diff --git a/precompile/binaries/stdlib/biguint.mv b/precompile/binaries/stdlib/biguint.mv index 5df3f7a4..0fcd32e3 100644 Binary files a/precompile/binaries/stdlib/biguint.mv and b/precompile/binaries/stdlib/biguint.mv differ diff --git a/precompile/binaries/stdlib/bit_vector.mv b/precompile/binaries/stdlib/bit_vector.mv index bc6fbc4c..62ae7d03 100644 Binary files a/precompile/binaries/stdlib/bit_vector.mv and b/precompile/binaries/stdlib/bit_vector.mv differ diff --git a/precompile/binaries/stdlib/capability.mv b/precompile/binaries/stdlib/capability.mv index 8aa96019..9b759b35 100644 Binary files a/precompile/binaries/stdlib/capability.mv and b/precompile/binaries/stdlib/capability.mv differ diff --git a/precompile/binaries/stdlib/code.mv b/precompile/binaries/stdlib/code.mv index 06ca1615..913001a6 100644 Binary files a/precompile/binaries/stdlib/code.mv and b/precompile/binaries/stdlib/code.mv differ diff --git a/precompile/binaries/stdlib/coin.mv b/precompile/binaries/stdlib/coin.mv index 7a99fd15..912845cd 100644 Binary files a/precompile/binaries/stdlib/coin.mv and b/precompile/binaries/stdlib/coin.mv differ diff --git a/precompile/binaries/stdlib/collection.mv b/precompile/binaries/stdlib/collection.mv index 07ce7f53..a63e63dc 100644 Binary files a/precompile/binaries/stdlib/collection.mv and b/precompile/binaries/stdlib/collection.mv differ diff --git a/precompile/binaries/stdlib/comparator.mv b/precompile/binaries/stdlib/comparator.mv index 8ef60db2..9bf9dfa0 100644 Binary files a/precompile/binaries/stdlib/comparator.mv and b/precompile/binaries/stdlib/comparator.mv differ diff --git a/precompile/binaries/stdlib/compare.mv b/precompile/binaries/stdlib/compare.mv index 1256b190..d4c91e08 100644 Binary files a/precompile/binaries/stdlib/compare.mv and b/precompile/binaries/stdlib/compare.mv differ diff --git a/precompile/binaries/stdlib/cosmos.mv b/precompile/binaries/stdlib/cosmos.mv index 02aab079..d528592a 100644 Binary files a/precompile/binaries/stdlib/cosmos.mv and b/precompile/binaries/stdlib/cosmos.mv differ diff --git a/precompile/binaries/stdlib/dex.mv b/precompile/binaries/stdlib/dex.mv index f081c756..abf28974 100644 Binary files a/precompile/binaries/stdlib/dex.mv and b/precompile/binaries/stdlib/dex.mv differ diff --git a/precompile/binaries/stdlib/dispatchable_fungible_asset.mv b/precompile/binaries/stdlib/dispatchable_fungible_asset.mv index 8ddf36a4..49aec94c 100644 Binary files a/precompile/binaries/stdlib/dispatchable_fungible_asset.mv and b/precompile/binaries/stdlib/dispatchable_fungible_asset.mv differ diff --git a/precompile/binaries/stdlib/ed25519.mv b/precompile/binaries/stdlib/ed25519.mv index 81d32d13..2431769e 100644 Binary files a/precompile/binaries/stdlib/ed25519.mv and b/precompile/binaries/stdlib/ed25519.mv differ diff --git a/precompile/binaries/stdlib/error.mv b/precompile/binaries/stdlib/error.mv index 97f7360c..714db97b 100644 Binary files a/precompile/binaries/stdlib/error.mv and b/precompile/binaries/stdlib/error.mv differ diff --git a/precompile/binaries/stdlib/fixed_point32.mv b/precompile/binaries/stdlib/fixed_point32.mv index 46998389..6a8334ca 100644 Binary files a/precompile/binaries/stdlib/fixed_point32.mv and b/precompile/binaries/stdlib/fixed_point32.mv differ diff --git a/precompile/binaries/stdlib/fixed_point64.mv b/precompile/binaries/stdlib/fixed_point64.mv index 0401e7cf..26707195 100644 Binary files a/precompile/binaries/stdlib/fixed_point64.mv and b/precompile/binaries/stdlib/fixed_point64.mv differ diff --git a/precompile/binaries/stdlib/from_bcs.mv b/precompile/binaries/stdlib/from_bcs.mv index 2c030eb8..93aebdca 100644 Binary files a/precompile/binaries/stdlib/from_bcs.mv and b/precompile/binaries/stdlib/from_bcs.mv differ diff --git a/precompile/binaries/stdlib/fungible_asset.mv b/precompile/binaries/stdlib/fungible_asset.mv index 804ff553..d7325d94 100644 Binary files a/precompile/binaries/stdlib/fungible_asset.mv and b/precompile/binaries/stdlib/fungible_asset.mv differ diff --git a/precompile/binaries/stdlib/guid.mv b/precompile/binaries/stdlib/guid.mv index 1b532b8d..514da171 100644 Binary files a/precompile/binaries/stdlib/guid.mv and b/precompile/binaries/stdlib/guid.mv differ diff --git a/precompile/binaries/stdlib/hex.mv b/precompile/binaries/stdlib/hex.mv index ac7d6c0e..d4884267 100644 Binary files a/precompile/binaries/stdlib/hex.mv and b/precompile/binaries/stdlib/hex.mv differ diff --git a/precompile/binaries/stdlib/initia_nft.mv b/precompile/binaries/stdlib/initia_nft.mv index b7c9afc7..e1ed6529 100644 Binary files a/precompile/binaries/stdlib/initia_nft.mv and b/precompile/binaries/stdlib/initia_nft.mv differ diff --git a/precompile/binaries/stdlib/json.mv b/precompile/binaries/stdlib/json.mv index 51431a89..ca859865 100644 Binary files a/precompile/binaries/stdlib/json.mv and b/precompile/binaries/stdlib/json.mv differ diff --git a/precompile/binaries/stdlib/math128.mv b/precompile/binaries/stdlib/math128.mv index 99ccb71b..09152cec 100644 Binary files a/precompile/binaries/stdlib/math128.mv and b/precompile/binaries/stdlib/math128.mv differ diff --git a/precompile/binaries/stdlib/math64.mv b/precompile/binaries/stdlib/math64.mv index ec22cfbf..0abdd85a 100644 Binary files a/precompile/binaries/stdlib/math64.mv and b/precompile/binaries/stdlib/math64.mv differ diff --git a/precompile/binaries/stdlib/minitswap.mv b/precompile/binaries/stdlib/minitswap.mv index 3fc4a17d..d647d7f2 100644 Binary files a/precompile/binaries/stdlib/minitswap.mv and b/precompile/binaries/stdlib/minitswap.mv differ diff --git a/precompile/binaries/stdlib/multisig.mv b/precompile/binaries/stdlib/multisig.mv index 71550f9c..d816b61f 100644 Binary files a/precompile/binaries/stdlib/multisig.mv and b/precompile/binaries/stdlib/multisig.mv differ diff --git a/precompile/binaries/stdlib/multisig_v2.mv b/precompile/binaries/stdlib/multisig_v2.mv index b7554715..0fee7cf5 100644 Binary files a/precompile/binaries/stdlib/multisig_v2.mv and b/precompile/binaries/stdlib/multisig_v2.mv differ diff --git a/precompile/binaries/stdlib/nft.mv b/precompile/binaries/stdlib/nft.mv index af22c911..9f8076e3 100644 Binary files a/precompile/binaries/stdlib/nft.mv and b/precompile/binaries/stdlib/nft.mv differ diff --git a/precompile/binaries/stdlib/object.mv b/precompile/binaries/stdlib/object.mv index 4a7c9c7c..33e23adf 100644 Binary files a/precompile/binaries/stdlib/object.mv and b/precompile/binaries/stdlib/object.mv differ diff --git a/precompile/binaries/stdlib/object_code_deployment.mv b/precompile/binaries/stdlib/object_code_deployment.mv index 08fb72af..a84b87df 100644 Binary files a/precompile/binaries/stdlib/object_code_deployment.mv and b/precompile/binaries/stdlib/object_code_deployment.mv differ diff --git a/precompile/binaries/stdlib/option.mv b/precompile/binaries/stdlib/option.mv index 2e75c7b8..fc56339e 100644 Binary files a/precompile/binaries/stdlib/option.mv and b/precompile/binaries/stdlib/option.mv differ diff --git a/precompile/binaries/stdlib/primary_fungible_store.mv b/precompile/binaries/stdlib/primary_fungible_store.mv index d120e781..84931f7c 100644 Binary files a/precompile/binaries/stdlib/primary_fungible_store.mv and b/precompile/binaries/stdlib/primary_fungible_store.mv differ diff --git a/precompile/binaries/stdlib/property_map.mv b/precompile/binaries/stdlib/property_map.mv index f9dc5967..e415c6e5 100644 Binary files a/precompile/binaries/stdlib/property_map.mv and b/precompile/binaries/stdlib/property_map.mv differ diff --git a/precompile/binaries/stdlib/royalty.mv b/precompile/binaries/stdlib/royalty.mv index ebc23375..004a8525 100644 Binary files a/precompile/binaries/stdlib/royalty.mv and b/precompile/binaries/stdlib/royalty.mv differ diff --git a/precompile/binaries/stdlib/secp256k1.mv b/precompile/binaries/stdlib/secp256k1.mv index d290f138..267106e0 100644 Binary files a/precompile/binaries/stdlib/secp256k1.mv and b/precompile/binaries/stdlib/secp256k1.mv differ diff --git a/precompile/binaries/stdlib/simple_map.mv b/precompile/binaries/stdlib/simple_map.mv index 147ee396..998e8836 100644 Binary files a/precompile/binaries/stdlib/simple_map.mv and b/precompile/binaries/stdlib/simple_map.mv differ diff --git a/precompile/binaries/stdlib/simple_nft.mv b/precompile/binaries/stdlib/simple_nft.mv index 20c655e9..9c69d36b 100644 Binary files a/precompile/binaries/stdlib/simple_nft.mv and b/precompile/binaries/stdlib/simple_nft.mv differ diff --git a/precompile/binaries/stdlib/soul_bound_token.mv b/precompile/binaries/stdlib/soul_bound_token.mv index 5fd76206..e1aa468d 100644 Binary files a/precompile/binaries/stdlib/soul_bound_token.mv and b/precompile/binaries/stdlib/soul_bound_token.mv differ diff --git a/precompile/binaries/stdlib/stableswap.mv b/precompile/binaries/stdlib/stableswap.mv index aa9ba5a1..a7f009ac 100644 Binary files a/precompile/binaries/stdlib/stableswap.mv and b/precompile/binaries/stdlib/stableswap.mv differ diff --git a/precompile/binaries/stdlib/staking.mv b/precompile/binaries/stdlib/staking.mv index 5ddc08cb..dbbd6f14 100644 Binary files a/precompile/binaries/stdlib/staking.mv and b/precompile/binaries/stdlib/staking.mv differ diff --git a/precompile/binaries/stdlib/string.mv b/precompile/binaries/stdlib/string.mv index f2f46ef1..af32c575 100644 Binary files a/precompile/binaries/stdlib/string.mv and b/precompile/binaries/stdlib/string.mv differ diff --git a/precompile/binaries/stdlib/string_utils.mv b/precompile/binaries/stdlib/string_utils.mv index ab190016..ea4c6948 100644 Binary files a/precompile/binaries/stdlib/string_utils.mv and b/precompile/binaries/stdlib/string_utils.mv differ diff --git a/precompile/binaries/stdlib/table.mv b/precompile/binaries/stdlib/table.mv index 50b1c00c..6252a883 100644 Binary files a/precompile/binaries/stdlib/table.mv and b/precompile/binaries/stdlib/table.mv differ diff --git a/precompile/binaries/stdlib/table_key.mv b/precompile/binaries/stdlib/table_key.mv index 2bd90154..ee84130e 100644 Binary files a/precompile/binaries/stdlib/table_key.mv and b/precompile/binaries/stdlib/table_key.mv differ diff --git a/precompile/binaries/stdlib/vector.mv b/precompile/binaries/stdlib/vector.mv index 989ab5e2..edce2a87 100644 Binary files a/precompile/binaries/stdlib/vector.mv and b/precompile/binaries/stdlib/vector.mv differ diff --git a/precompile/modules/initia_stdlib/sources/json.move b/precompile/modules/initia_stdlib/sources/json.move index 5e9b1c9d..ce7e5c86 100644 --- a/precompile/modules/initia_stdlib/sources/json.move +++ b/precompile/modules/initia_stdlib/sources/json.move @@ -191,7 +191,7 @@ module initia_std::json { let json = marshal(&obj); assert!( json - == b"{\"@type\":\"/cosmos.gov.v1.MsgVote\",\"a\":\"42\",\"b\":true,\"bigdecimal\":\"0.0123\",\"biguint\":\"42\",\"c\":\"010203\",\"d\":\"0x1\",\"e\":{\"a\":\"42\",\"b\":true,\"c\":\"010203\"},\"f\":null,\"move\":\"move\",\"signer\":\"signer\"}", + == b"{\"a\":\"42\",\"b\":true,\"c\":\"010203\",\"d\":\"0x1\",\"e\":{\"a\":\"42\",\"b\":true,\"c\":\"010203\"},\"f\":null,\"@type\":\"/cosmos.gov.v1.MsgVote\",\"move\":\"move\",\"signer\":\"signer\",\"biguint\":\"42\",\"bigdecimal\":\"0.0123\"}", 1 ); @@ -247,7 +247,7 @@ module initia_std::json { let json5 = marshal(&json_obj); assert!( json5 - == b"{\"@type\":\"/cosmos.gov.v1.MsgVote\",\"a\":\"42\",\"b\":true,\"bigdecimal\":\"0.0123\",\"biguint\":\"42\",\"c\":\"hello\",\"d\":\"0x1\",\"e\":{\"a\":\"42\",\"b\":true,\"c\":\"010203\"},\"f\":null,\"move\":\"move\",\"signer\":\"signer\"}", + == b"{\"a\":\"42\",\"b\":true,\"c\":\"hello\",\"d\":\"0x1\",\"e\":{\"a\":\"42\",\"b\":true,\"c\":\"010203\"},\"f\":null,\"@type\":\"/cosmos.gov.v1.MsgVote\",\"move\":\"move\",\"signer\":\"signer\",\"biguint\":\"42\",\"bigdecimal\":\"0.0123\"}", 9 ); } diff --git a/precompile/modules/initia_stdlib/sources/minitswap.move b/precompile/modules/initia_stdlib/sources/minitswap.move index a6cc62ae..994eb030 100644 --- a/precompile/modules/initia_stdlib/sources/minitswap.move +++ b/precompile/modules/initia_stdlib/sources/minitswap.move @@ -3377,7 +3377,7 @@ module initia_std::minitswap { assert!( memo == string::utf8( - b"{\"evm\":null,\"move\":{\"async_callback\":{\"id\":1,\"module_address\":\"0x1\",\"module_name\":\"minitswap\"},\"message\":{\"args\":[\"CG9wX2Rlbm9t\",\"QEIPAAAAAAA=\",\"CHJlY2VpdmVy\"],\"function_name\":\"minitswap_hook\",\"module_address\":\"0x1\",\"module_name\":\"minitswap_hook\",\"type_args\":[]}},\"wasm\":null}" + b"{\"move\":{\"message\":{\"module_address\":\"0x1\",\"module_name\":\"minitswap_hook\",\"function_name\":\"minitswap_hook\",\"type_args\":[],\"args\":[\"CG9wX2Rlbm9t\",\"QEIPAAAAAAA=\",\"CHJlY2VpdmVy\"]},\"async_callback\":{\"id\":1,\"module_address\":\"0x1\",\"module_name\":\"minitswap\"}},\"wasm\":null,\"evm\":null}" ), 1 ); @@ -3396,7 +3396,7 @@ module initia_std::minitswap { assert!( memo == string::utf8( - b"{\"evm\":null,\"move\":{\"async_callback\":{\"id\":1,\"module_address\":\"0x1\",\"module_name\":\"minitswap\"},\"message\":null},\"wasm\":{\"message\":{\"contracts\":\"cosmwasm_contract_addr\",\"funds\":[{\"amount\":\"1000000\",\"denom\":\"op_denom\"}],\"msg\":{\"minitswap_hook\":{\"receiver\":\"receiver\"}}}}}" + b"{\"move\":{\"message\":null,\"async_callback\":{\"id\":1,\"module_address\":\"0x1\",\"module_name\":\"minitswap\"}},\"wasm\":{\"message\":{\"contracts\":\"cosmwasm_contract_addr\",\"funds\":[{\"denom\":\"op_denom\",\"amount\":\"1000000\"}],\"msg\":{\"minitswap_hook\":{\"receiver\":\"receiver\"}}}},\"evm\":null}" ), 3 ); diff --git a/precompile/modules/minitia_stdlib/sources/json.move b/precompile/modules/minitia_stdlib/sources/json.move index d91b7a1c..a89f4a37 100644 --- a/precompile/modules/minitia_stdlib/sources/json.move +++ b/precompile/modules/minitia_stdlib/sources/json.move @@ -191,7 +191,7 @@ module minitia_std::json { let json = marshal(&obj); assert!( json - == b"{\"@type\":\"/cosmos.gov.v1.MsgVote\",\"a\":\"42\",\"b\":true,\"bigdecimal\":\"0.0123\",\"biguint\":\"42\",\"c\":\"010203\",\"d\":\"0x1\",\"e\":{\"a\":\"42\",\"b\":true,\"c\":\"010203\"},\"f\":null,\"move\":\"move\",\"signer\":\"signer\"}", + == b"{\"a\":\"42\",\"b\":true,\"c\":\"010203\",\"d\":\"0x1\",\"e\":{\"a\":\"42\",\"b\":true,\"c\":\"010203\"},\"f\":null,\"@type\":\"/cosmos.gov.v1.MsgVote\",\"move\":\"move\",\"signer\":\"signer\",\"biguint\":\"42\",\"bigdecimal\":\"0.0123\"}", 1 ); @@ -247,7 +247,7 @@ module minitia_std::json { let json5 = marshal(&json_obj); assert!( json5 - == b"{\"@type\":\"/cosmos.gov.v1.MsgVote\",\"a\":\"42\",\"b\":true,\"bigdecimal\":\"0.0123\",\"biguint\":\"42\",\"c\":\"hello\",\"d\":\"0x1\",\"e\":{\"a\":\"42\",\"b\":true,\"c\":\"010203\"},\"f\":null,\"move\":\"move\",\"signer\":\"signer\"}", + == b"{\"a\":\"42\",\"b\":true,\"c\":\"hello\",\"d\":\"0x1\",\"e\":{\"a\":\"42\",\"b\":true,\"c\":\"010203\"},\"f\":null,\"@type\":\"/cosmos.gov.v1.MsgVote\",\"move\":\"move\",\"signer\":\"signer\",\"biguint\":\"42\",\"bigdecimal\":\"0.0123\"}", 9 ); }