diff --git a/Cargo.lock b/Cargo.lock index 2bb3de25a..2508f2204 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,9 +24,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.61" +version = "1.0.62" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "508b352bb5c066aac251f6daf6b36eccd03e8a88e8081cd44959ea277a3af9a8" +checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305" [[package]] name = "arrayref" @@ -86,10 +86,11 @@ dependencies = [ [[package]] name = "async-io" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5e18f61464ae81cde0a23e713ae8fd299580c54d697a35820cfd0625b8b0e07" +checksum = "0ab006897723d9352f63e2b13047177c3982d8d79709d713ce7747a8f19fd1b0" dependencies = [ + "autocfg", "concurrent-queue", "futures-lite", "libc", @@ -274,9 +275,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" [[package]] name = "byteorder" @@ -405,9 +406,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +checksum = "1079fb8528d9f9c888b1e8aa651e6e079ade467323d58f75faf1d30b1808f540" dependencies = [ "libc", ] @@ -593,9 +594,9 @@ dependencies = [ [[package]] name = "either" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "event-listener" @@ -1080,7 +1081,7 @@ dependencies = [ [[package]] name = "fvm_ipld_amt" version = "0.4.2" -source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#4033ef252296209269fa5478e28d934d98bd884a" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#433a63f6d017c6c47e3a158a14e57c9aadedb7a4" dependencies = [ "ahash", "anyhow", @@ -1096,7 +1097,7 @@ dependencies = [ [[package]] name = "fvm_ipld_bitfield" version = "0.5.2" -source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#4033ef252296209269fa5478e28d934d98bd884a" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#433a63f6d017c6c47e3a158a14e57c9aadedb7a4" dependencies = [ "cs_serde_bytes", "fvm_ipld_encoding", @@ -1108,7 +1109,7 @@ dependencies = [ [[package]] name = "fvm_ipld_blockstore" version = "0.1.1" -source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#4033ef252296209269fa5478e28d934d98bd884a" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#433a63f6d017c6c47e3a158a14e57c9aadedb7a4" dependencies = [ "anyhow", "cid", @@ -1133,7 +1134,7 @@ dependencies = [ [[package]] name = "fvm_ipld_encoding" version = "0.2.2" -source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#4033ef252296209269fa5478e28d934d98bd884a" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#433a63f6d017c6c47e3a158a14e57c9aadedb7a4" dependencies = [ "anyhow", "cid", @@ -1150,7 +1151,7 @@ dependencies = [ [[package]] name = "fvm_ipld_hamt" version = "0.5.1" -source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#4033ef252296209269fa5478e28d934d98bd884a" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#433a63f6d017c6c47e3a158a14e57c9aadedb7a4" dependencies = [ "anyhow", "byteorder", @@ -1170,7 +1171,7 @@ dependencies = [ [[package]] name = "fvm_sdk" version = "2.0.0-alpha.1" -source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#4033ef252296209269fa5478e28d934d98bd884a" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#433a63f6d017c6c47e3a158a14e57c9aadedb7a4" dependencies = [ "cid", "fvm_ipld_encoding", @@ -1184,7 +1185,7 @@ dependencies = [ [[package]] name = "fvm_shared" version = "0.9.0" -source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#4033ef252296209269fa5478e28d934d98bd884a" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=master#433a63f6d017c6c47e3a158a14e57c9aadedb7a4" dependencies = [ "anyhow", "bimap", @@ -1497,6 +1498,7 @@ dependencies = [ "core2", "digest 0.10.3", "multihash-derive", + "ripemd", "serde", "serde-big-array", "sha2 0.10.2", @@ -1770,6 +1772,15 @@ version = "0.6.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +[[package]] +name = "ripemd" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1facec54cb5e0dc08553501fa740091086d0259ad0067e0d4103448e4cb22ed3" +dependencies = [ + "digest 0.10.3", +] + [[package]] name = "rlp" version = "0.5.1" diff --git a/actors/evm/src/interpreter/execution.rs b/actors/evm/src/interpreter/execution.rs index c19a23c2c..d86e0b4d2 100644 --- a/actors/evm/src/interpreter/execution.rs +++ b/actors/evm/src/interpreter/execution.rs @@ -79,9 +79,9 @@ pub fn execute<'r, BS: Blockstore, RT: Runtime>( OpCode::SHR => bitwise::shr(&mut runtime.stack), OpCode::SAR => bitwise::sar(&mut runtime.stack), OpCode::KECCAK256 => hash::keccak256(runtime)?, - OpCode::ADDRESS => context::address(runtime, system)?, + OpCode::ADDRESS => context::address(runtime, system), OpCode::BALANCE => storage::balance(runtime, system)?, - OpCode::CALLER => context::caller(runtime, system)?, + OpCode::CALLER => context::caller(runtime, system), OpCode::CALLVALUE => context::call_value(runtime, system), OpCode::CALLDATALOAD => call::calldataload(runtime), OpCode::CALLDATASIZE => call::calldatasize(runtime), diff --git a/actors/evm/src/interpreter/instructions/context.rs b/actors/evm/src/interpreter/instructions/context.rs index a0c5d91fd..8a7bb64f8 100644 --- a/actors/evm/src/interpreter/instructions/context.rs +++ b/actors/evm/src/interpreter/instructions/context.rs @@ -14,10 +14,10 @@ pub fn blockhash<'r, BS: Blockstore, RT: Runtime>( #[inline] pub fn caller<'r, BS: Blockstore, RT: Runtime>( - _state: &mut ExecutionState, - _platform: &'r System<'r, BS, RT>, -) -> Result<(), StatusCode> { - todo!() + state: &mut ExecutionState, + platform: &'r System<'r, BS, RT>, +) { + state.stack.push(U256::from(platform.rt.message().caller().id().unwrap())) } #[inline] @@ -30,10 +30,10 @@ pub fn call_value<'r, BS: Blockstore, RT: Runtime>( #[inline] pub fn address<'r, BS: Blockstore, RT: Runtime>( - _state: &mut ExecutionState, - _platform: &'r System<'r, BS, RT>, -) -> Result<(), StatusCode> { - todo!() + state: &mut ExecutionState, + platform: &'r System<'r, BS, RT>, +) { + state.stack.push(U256::from(platform.rt.message().receiver().id().unwrap())) } #[inline] @@ -41,7 +41,7 @@ pub fn origin<'r, BS: Blockstore, RT: Runtime>( state: &mut ExecutionState, platform: &'r System<'r, BS, RT>, ) { - state.stack.push(U256::from(platform.rt.message().caller().id().unwrap())) + state.stack.push(U256::from(platform.rt.message().origin().id().unwrap())) } #[inline] diff --git a/actors/evm/tests/basic.rs b/actors/evm/tests/basic.rs index c79dd5494..b13cb8d79 100644 --- a/actors/evm/tests/basic.rs +++ b/actors/evm/tests/basic.rs @@ -18,6 +18,7 @@ fn basic_contract_construction_and_invocation() { // invoke constructor rt.actor_code_cids.insert(contract, *EVM_ACTOR_CODE_ID); rt.expect_validate_caller_any(); + rt.set_origin(contract); let result = rt .call::( @@ -33,7 +34,7 @@ fn basic_contract_construction_and_invocation() { solidity_params.append(&mut hex::decode("f8b2cb4f").unwrap()); // function selector // caller id address in U256 form let mut arg0 = vec![0u8; 32]; - //arg0[31] = 100; + arg0[31] = 100; // the contract address solidity_params.append(&mut arg0); let params = evm::InvokeParams { input_data: RawBytes::from(solidity_params) }; diff --git a/runtime/src/runtime/fvm.rs b/runtime/src/runtime/fvm.rs index 71c290b86..1c57f593e 100644 --- a/runtime/src/runtime/fvm.rs +++ b/runtime/src/runtime/fvm.rs @@ -85,6 +85,10 @@ impl MessageInfo for FvmMessage { Address::new_id(fvm::message::caller()) } + fn origin(&self) -> Address { + Address::new_id(fvm::message::origin()) + } + fn receiver(&self) -> Address { Address::new_id(fvm::message::receiver()) } diff --git a/runtime/src/runtime/mod.rs b/runtime/src/runtime/mod.rs index 6bc25d61d..f94edf5f2 100644 --- a/runtime/src/runtime/mod.rs +++ b/runtime/src/runtime/mod.rs @@ -169,6 +169,9 @@ pub trait MessageInfo { /// The address of the immediate calling actor. Always an ID-address. fn caller(&self) -> Address; + /// The address of the origin of the current invocation. Always an ID-address + fn origin(&self) -> Address; + /// The address of the actor receiving the message. Always an ID-address. fn receiver(&self) -> Address; diff --git a/runtime/src/test_utils.rs b/runtime/src/test_utils.rs index bb9f4ea50..64a3d66c8 100644 --- a/runtime/src/test_utils.rs +++ b/runtime/src/test_utils.rs @@ -113,6 +113,7 @@ pub struct MockRuntime { pub receiver: Address, pub caller: Address, pub caller_type: Cid, + pub origin: Address, pub value_received: TokenAmount, pub hash_func: Box [u8; 32]>, pub network_version: NetworkVersion, @@ -258,6 +259,7 @@ impl Default for MockRuntime { receiver: Address::new_id(0), caller: Address::new_id(0), caller_type: Default::default(), + origin: Address::new_id(0), value_received: Default::default(), hash_func: Box::new(blake2b_256), network_version: NetworkVersion::V0, @@ -423,6 +425,10 @@ impl MockRuntime { self.actor_code_cids.insert(address, code_id); } + pub fn set_origin(&mut self, address: Address) { + self.origin = address; + } + pub fn set_address_actor_type(&mut self, address: Address, actor_type: Cid) { self.actor_code_cids.insert(address, actor_type); } @@ -658,6 +664,9 @@ impl MessageInfo for MockRuntime { fn caller(&self) -> Address { self.caller } + fn origin(&self) -> Address { + self.origin + } fn receiver(&self) -> Address { self.receiver } diff --git a/test_vm/src/lib.rs b/test_vm/src/lib.rs index a6e21c639..c581e0464 100644 --- a/test_vm/src/lib.rs +++ b/test_vm/src/lib.rs @@ -520,6 +520,9 @@ impl MessageInfo for InvocationCtx<'_, '_> { fn caller(&self) -> Address { self.msg.from } + fn origin(&self) -> Address { + self.resolve_address(&self.top.originator_stable_addr).unwrap() + } fn receiver(&self) -> Address { self.to() }