From a70db583757e93872d6b3b68d6004c04c9f1cc04 Mon Sep 17 00:00:00 2001 From: Eric Bogard Date: Tue, 25 Jun 2024 17:46:49 -0700 Subject: [PATCH 1/6] Add bytecode address to Contract struct --- crates/interpreter/src/interpreter.rs | 1 + crates/interpreter/src/interpreter/contract.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/crates/interpreter/src/interpreter.rs b/crates/interpreter/src/interpreter.rs index 07ab0439d9..a3429c3114 100644 --- a/crates/interpreter/src/interpreter.rs +++ b/crates/interpreter/src/interpreter.rs @@ -111,6 +111,7 @@ impl Interpreter { Contract::new( Bytes::new(), bytecode, + crate::primitives::Address::default(), None, crate::primitives::Address::default(), crate::primitives::Address::default(), diff --git a/crates/interpreter/src/interpreter/contract.rs b/crates/interpreter/src/interpreter/contract.rs index 49e511f66e..0fa620d3ae 100644 --- a/crates/interpreter/src/interpreter/contract.rs +++ b/crates/interpreter/src/interpreter/contract.rs @@ -15,6 +15,8 @@ pub struct Contract { /// Bytecode contains contract code, size of original code, analysis with gas block and jump table. /// Note that current code is extended with push padding and STOP at end. pub bytecode: Bytecode, + /// Address of the account the bytecode was loaded from. + pub bytecode_address: Address, /// Bytecode hash for legacy. For EOF this would be None. pub hash: Option, /// Target address of the account. Storage of this address is going to be modified. @@ -31,6 +33,7 @@ impl Contract { pub fn new( input: Bytes, bytecode: Bytecode, + bytecode_address: Address, hash: Option, target_address: Address, caller: Address, @@ -41,6 +44,7 @@ impl Contract { Self { input, bytecode, + bytecode_address, hash, target_address, caller, @@ -58,6 +62,7 @@ impl Contract { Self::new( env.tx.data.clone(), bytecode, + contract_address, hash, contract_address, env.tx.caller, @@ -76,6 +81,7 @@ impl Contract { Self::new( input, bytecode, + call_context.bytecode_address, hash, call_context.target_address, call_context.caller, From f60b8a2a881a4ce04a43b54a5e9e9daf4b8755ba Mon Sep 17 00:00:00 2001 From: Eric Bogard Date: Tue, 25 Jun 2024 17:57:40 -0700 Subject: [PATCH 2/6] Explicit comment --- crates/interpreter/src/interpreter/contract.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/interpreter/src/interpreter/contract.rs b/crates/interpreter/src/interpreter/contract.rs index 0fa620d3ae..9a057e9144 100644 --- a/crates/interpreter/src/interpreter/contract.rs +++ b/crates/interpreter/src/interpreter/contract.rs @@ -15,7 +15,8 @@ pub struct Contract { /// Bytecode contains contract code, size of original code, analysis with gas block and jump table. /// Note that current code is extended with push padding and STOP at end. pub bytecode: Bytecode, - /// Address of the account the bytecode was loaded from. + /// Address of the account the bytecode was loaded from. This can be different from target_address + /// in the case of DELEGATECALL or CALLCODE pub bytecode_address: Address, /// Bytecode hash for legacy. For EOF this would be None. pub hash: Option, From 36962b6ecf4f9aba9f49993f7a47e11d5bc62fd4 Mon Sep 17 00:00:00 2001 From: Eric Bogard Date: Tue, 25 Jun 2024 18:05:51 -0700 Subject: [PATCH 3/6] Add new param to additional constructor calls --- crates/revm/src/context/inner_evm_context.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/revm/src/context/inner_evm_context.rs b/crates/revm/src/context/inner_evm_context.rs index 32c2826a05..bb175c161b 100644 --- a/crates/revm/src/context/inner_evm_context.rs +++ b/crates/revm/src/context/inner_evm_context.rs @@ -337,6 +337,7 @@ impl InnerEvmContext { input.clone(), // fine to clone as it is Bytes. Bytecode::Eof(Arc::new(initcode.clone())), + created_address, None, created_address, inputs.caller, @@ -475,6 +476,7 @@ impl InnerEvmContext { let contract = Contract::new( Bytes::new(), bytecode, + created_address, Some(init_code_hash), created_address, inputs.caller, From edc11fa68f50630c34974df743c4e16253aa9878 Mon Sep 17 00:00:00 2001 From: Eric Bogard Date: Tue, 25 Jun 2024 18:13:05 -0700 Subject: [PATCH 4/6] Reorder arguments to make more sense --- crates/interpreter/src/interpreter.rs | 2 +- crates/interpreter/src/interpreter/contract.rs | 14 +++++++------- crates/revm/src/context/inner_evm_context.rs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/interpreter/src/interpreter.rs b/crates/interpreter/src/interpreter.rs index a3429c3114..995e376403 100644 --- a/crates/interpreter/src/interpreter.rs +++ b/crates/interpreter/src/interpreter.rs @@ -111,10 +111,10 @@ impl Interpreter { Contract::new( Bytes::new(), bytecode, - crate::primitives::Address::default(), None, crate::primitives::Address::default(), crate::primitives::Address::default(), + crate::primitives::Address::default(), U256::ZERO, ), 0, diff --git a/crates/interpreter/src/interpreter/contract.rs b/crates/interpreter/src/interpreter/contract.rs index 9a057e9144..9f2a1ae3dd 100644 --- a/crates/interpreter/src/interpreter/contract.rs +++ b/crates/interpreter/src/interpreter/contract.rs @@ -15,13 +15,13 @@ pub struct Contract { /// Bytecode contains contract code, size of original code, analysis with gas block and jump table. /// Note that current code is extended with push padding and STOP at end. pub bytecode: Bytecode, - /// Address of the account the bytecode was loaded from. This can be different from target_address - /// in the case of DELEGATECALL or CALLCODE - pub bytecode_address: Address, /// Bytecode hash for legacy. For EOF this would be None. pub hash: Option, /// Target address of the account. Storage of this address is going to be modified. pub target_address: Address, + /// Address of the account the bytecode was loaded from. This can be different from target_address + /// in the case of DELEGATECALL or CALLCODE + pub bytecode_address: Address, /// Caller of the EVM. pub caller: Address, /// Value send to contract from transaction or from CALL opcodes. @@ -34,9 +34,9 @@ impl Contract { pub fn new( input: Bytes, bytecode: Bytecode, - bytecode_address: Address, hash: Option, target_address: Address, + bytecode_address: Address, caller: Address, call_value: U256, ) -> Self { @@ -45,9 +45,9 @@ impl Contract { Self { input, bytecode, - bytecode_address, hash, target_address, + bytecode_address, caller, call_value, } @@ -63,9 +63,9 @@ impl Contract { Self::new( env.tx.data.clone(), bytecode, - contract_address, hash, contract_address, + contract_address, env.tx.caller, env.tx.value, ) @@ -82,9 +82,9 @@ impl Contract { Self::new( input, bytecode, - call_context.bytecode_address, hash, call_context.target_address, + call_context.bytecode_address, call_context.caller, call_context.call_value(), ) diff --git a/crates/revm/src/context/inner_evm_context.rs b/crates/revm/src/context/inner_evm_context.rs index bb175c161b..457b937684 100644 --- a/crates/revm/src/context/inner_evm_context.rs +++ b/crates/revm/src/context/inner_evm_context.rs @@ -337,9 +337,9 @@ impl InnerEvmContext { input.clone(), // fine to clone as it is Bytes. Bytecode::Eof(Arc::new(initcode.clone())), - created_address, None, created_address, + created_address, inputs.caller, inputs.value, ); @@ -476,9 +476,9 @@ impl InnerEvmContext { let contract = Contract::new( Bytes::new(), bytecode, - created_address, Some(init_code_hash), created_address, + created_address, inputs.caller, inputs.value, ); From a9db64401377219728b92034cb75557b62dc10ae Mon Sep 17 00:00:00 2001 From: Eric Bogard Date: Sat, 29 Jun 2024 13:15:22 -0700 Subject: [PATCH 5/6] make optional and set to None when creation call --- crates/interpreter/src/interpreter.rs | 2 +- crates/interpreter/src/interpreter/contract.rs | 8 ++++---- crates/revm/src/context/inner_evm_context.rs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/interpreter/src/interpreter.rs b/crates/interpreter/src/interpreter.rs index 995e376403..47e041473f 100644 --- a/crates/interpreter/src/interpreter.rs +++ b/crates/interpreter/src/interpreter.rs @@ -113,7 +113,7 @@ impl Interpreter { bytecode, None, crate::primitives::Address::default(), - crate::primitives::Address::default(), + None, crate::primitives::Address::default(), U256::ZERO, ), diff --git a/crates/interpreter/src/interpreter/contract.rs b/crates/interpreter/src/interpreter/contract.rs index 9f2a1ae3dd..6ebc821716 100644 --- a/crates/interpreter/src/interpreter/contract.rs +++ b/crates/interpreter/src/interpreter/contract.rs @@ -21,7 +21,7 @@ pub struct Contract { pub target_address: Address, /// Address of the account the bytecode was loaded from. This can be different from target_address /// in the case of DELEGATECALL or CALLCODE - pub bytecode_address: Address, + pub bytecode_address: Option
, /// Caller of the EVM. pub caller: Address, /// Value send to contract from transaction or from CALL opcodes. @@ -36,7 +36,7 @@ impl Contract { bytecode: Bytecode, hash: Option, target_address: Address, - bytecode_address: Address, + bytecode_address: Option
, caller: Address, call_value: U256, ) -> Self { @@ -65,7 +65,7 @@ impl Contract { bytecode, hash, contract_address, - contract_address, + None, env.tx.caller, env.tx.value, ) @@ -84,7 +84,7 @@ impl Contract { bytecode, hash, call_context.target_address, - call_context.bytecode_address, + Some(call_context.bytecode_address), call_context.caller, call_context.call_value(), ) diff --git a/crates/revm/src/context/inner_evm_context.rs b/crates/revm/src/context/inner_evm_context.rs index 457b937684..4893f8cef2 100644 --- a/crates/revm/src/context/inner_evm_context.rs +++ b/crates/revm/src/context/inner_evm_context.rs @@ -339,7 +339,7 @@ impl InnerEvmContext { Bytecode::Eof(Arc::new(initcode.clone())), None, created_address, - created_address, + None, inputs.caller, inputs.value, ); @@ -478,7 +478,7 @@ impl InnerEvmContext { bytecode, Some(init_code_hash), created_address, - created_address, + None, inputs.caller, inputs.value, ); From f5d164947e47e6942135015c8a680c0dc020a0a5 Mon Sep 17 00:00:00 2001 From: Eric Bogard Date: Sun, 30 Jun 2024 13:21:40 -0700 Subject: [PATCH 6/6] Add bytecode address if TxKind is Call. --- crates/interpreter/src/interpreter/contract.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/interpreter/src/interpreter/contract.rs b/crates/interpreter/src/interpreter/contract.rs index 6ebc821716..304b700446 100644 --- a/crates/interpreter/src/interpreter/contract.rs +++ b/crates/interpreter/src/interpreter/contract.rs @@ -60,12 +60,16 @@ impl Contract { TxKind::Call(caller) => caller, TxKind::Create => Address::ZERO, }; + let bytecode_address = match env.tx.transact_to { + TxKind::Call(caller) => Some(caller), + TxKind::Create => None, + }; Self::new( env.tx.data.clone(), bytecode, hash, contract_address, - None, + bytecode_address, env.tx.caller, env.tx.value, )