From 9ab8f5cfbfd2a8aa2657a073fcc757ca275bc2eb Mon Sep 17 00:00:00 2001 From: Raz0r Date: Fri, 21 Jun 2024 03:30:09 +0300 Subject: [PATCH] support EXTCODEHASH (#511) --- src/evm/host.rs | 10 +++++----- src/evm/onchain/mod.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/evm/host.rs b/src/evm/host.rs index 5aa28479..1a060c4e 100644 --- a/src/evm/host.rs +++ b/src/evm/host.rs @@ -1229,11 +1229,11 @@ where } } - fn code_hash(&mut self, _address: EVMAddress) -> Option<(B256, bool)> { - Some(( - B256::from_str("0x0000000000000000000000000000000000000000000000000000000000000000").unwrap(), - true, - )) + fn code_hash(&mut self, address: EVMAddress) -> Option<(B256, bool)> { + match self.code.get(&address) { + Some(code) => Some((code.hash(), true)), + None => Some((B256::zero(), true)), + } } fn sload(&mut self, address: EVMAddress, index: EVMU256) -> Option<(EVMU256, bool)> { diff --git a/src/evm/onchain/mod.rs b/src/evm/onchain/mod.rs index 2fdaf82d..474b7c4d 100644 --- a/src/evm/onchain/mod.rs +++ b/src/evm/onchain/mod.rs @@ -260,8 +260,8 @@ where 0x46 => { host.env.tx.chain_id = Some(self.endpoint.chain_id as u64); } - // CALL | CALLCODE | DELEGATECALL | STATICCALL | EXTCODESIZE | EXTCODECOPY - 0xf1 | 0xf2 | 0xf4 | 0xfa | 0x3b | 0x3c => { + // CALL | CALLCODE | DELEGATECALL | STATICCALL | EXTCODESIZE | EXTCODECOPY | EXTCODEHASH + 0xf1 | 0xf2 | 0xf4 | 0xfa | 0x3b | 0x3c | 0x3f => { let caller = interp.contract.address; let address = match *interp.instruction_pointer { 0xf1 | 0xf2 => { @@ -275,7 +275,7 @@ where interp.stack.peek(1).unwrap() } 0xf4 | 0xfa => interp.stack.peek(1).unwrap(), - 0x3b | 0x3c => interp.stack.peek(0).unwrap(), + 0x3b | 0x3c | 0x3f => interp.stack.peek(0).unwrap(), _ => unreachable!(), };