diff --git a/interpreter/src/eval/system.rs b/interpreter/src/eval/system.rs index 204d31260..90f3b501b 100644 --- a/interpreter/src/eval/system.rs +++ b/interpreter/src/eval/system.rs @@ -48,7 +48,6 @@ pub fn balance, H: RuntimeEnvironment + RuntimeBackend, T handler: &mut H, ) -> Control { pop!(machine, address); - handler.mark_hot(address.into(), None); push_u256!(machine, handler.balance(address.into())); Control::Continue @@ -128,7 +127,6 @@ pub fn extcodesize, H: RuntimeEnvironment + RuntimeBacken handler: &mut H, ) -> Control { pop!(machine, address); - handler.mark_hot(address.into(), None); let code_size = handler.code_size(address.into()); push_u256!(machine, code_size); @@ -140,7 +138,6 @@ pub fn extcodehash, H: RuntimeEnvironment + RuntimeBacken handler: &mut H, ) -> Control { pop!(machine, address); - handler.mark_hot(address.into(), None); let code_hash = handler.code_hash(address.into()); push!(machine, code_hash); @@ -153,8 +150,6 @@ pub fn extcodecopy, H: RuntimeEnvironment + RuntimeBacken ) -> Control { pop!(machine, address); pop_u256!(machine, memory_offset, code_offset, len); - - handler.mark_hot(address.into(), None); try_or_fail!(machine.memory.resize_offset(memory_offset, len)); let code = handler.code(address.into()); @@ -264,7 +259,6 @@ pub fn sload, H: RuntimeEnvironment + RuntimeBackend, Tr> handler: &mut H, ) -> Control { pop!(machine, index); - handler.mark_hot(machine.state.as_ref().context.address, Some(index)); let value = handler.storage(machine.state.as_ref().context.address, index); push!(machine, value); @@ -276,7 +270,6 @@ pub fn sstore, H: RuntimeEnvironment + RuntimeBackend, Tr handler: &mut H, ) -> Control { pop!(machine, index, value); - handler.mark_hot(machine.state.as_ref().context.address, Some(index)); match handler.set_storage(machine.state.as_ref().context.address, index, value) { Ok(()) => Control::Continue, diff --git a/src/standard/gasometer/mod.rs b/src/standard/gasometer/mod.rs index e4ec94067..1fe727162 100644 --- a/src/standard/gasometer/mod.rs +++ b/src/standard/gasometer/mod.rs @@ -303,40 +303,59 @@ fn dynamic_opcode_cost( Opcode::EXTCODESIZE => { let target = stack.peek(0)?.into(); - GasCost::ExtCodeSize { - target_is_cold: handler.is_cold(target, None), - } + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + + GasCost::ExtCodeSize { target_is_cold } } Opcode::BALANCE => { let target = stack.peek(0)?.into(); - GasCost::Balance { - target_is_cold: handler.is_cold(target, None), - } + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + + GasCost::Balance { target_is_cold } } Opcode::BLOCKHASH => GasCost::BlockHash, Opcode::EXTCODEHASH if config.has_ext_code_hash => { let target = stack.peek(0)?.into(); - GasCost::ExtCodeHash { - target_is_cold: handler.is_cold(target, None), - } + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + + GasCost::ExtCodeHash { target_is_cold } } Opcode::EXTCODEHASH => GasCost::Invalid(opcode), Opcode::CALLCODE => { let target = stack.peek(1)?.into(); + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + GasCost::CallCode { value: U256::from_big_endian(&stack.peek(2)?[..]), gas: U256::from_big_endian(&stack.peek(0)?[..]), - target_is_cold: handler.is_cold(target, None), + target_is_cold, target_exists: { handler.exists(target) }, } } Opcode::STATICCALL => { let target = stack.peek(1)?.into(); + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + GasCost::StaticCall { gas: U256::from_big_endian(&stack.peek(0)?[..]), - target_is_cold: handler.is_cold(target, None), + target_is_cold, target_exists: { handler.exists(target) }, } } @@ -345,8 +364,13 @@ fn dynamic_opcode_cost( }, Opcode::EXTCODECOPY => { let target = stack.peek(0)?.into(); + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + GasCost::ExtCodeCopy { - target_is_cold: handler.is_cold(target, None), + target_is_cold, len: U256::from_big_endian(&stack.peek(3)?[..]), } } @@ -358,16 +382,24 @@ fn dynamic_opcode_cost( }, Opcode::SLOAD => { let index = stack.peek(0)?; - GasCost::SLoad { - target_is_cold: handler.is_cold(address, Some(index)), - } + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(address, Some(index)); + handler.mark_hot(address, Some(index)); + + GasCost::SLoad { target_is_cold } } Opcode::DELEGATECALL if config.has_delegate_call => { let target = stack.peek(1)?.into(); + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + GasCost::DelegateCall { gas: U256::from_big_endian(&stack.peek(0)?[..]), - target_is_cold: handler.is_cold(target, None), + target_is_cold, target_exists: { handler.exists(target) }, } } @@ -383,11 +415,15 @@ fn dynamic_opcode_cost( let index = stack.peek(0)?; let value = stack.peek(1)?; + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(address, Some(index)); + handler.mark_hot(address, Some(index)); + GasCost::SStore { original: handler.original_storage(address, index), current: handler.storage(address, index), new: value, - target_is_cold: handler.is_cold(address, Some(index)), + target_is_cold, } } Opcode::LOG0 if !is_static => GasCost::Log { @@ -416,9 +452,14 @@ fn dynamic_opcode_cost( }, Opcode::SUICIDE if !is_static => { let target = stack.peek(0)?.into(); + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + GasCost::Suicide { value: handler.balance(address), - target_is_cold: handler.is_cold(target, None), + target_is_cold, target_exists: { handler.exists(target) }, already_removed: handler.deleted(address), } @@ -428,10 +469,15 @@ fn dynamic_opcode_cost( || (is_static && U256::from_big_endian(&stack.peek(2)?[..]) == U256::zero()) => { let target = stack.peek(1)?.into(); + + // https://eips.ethereum.org/EIPS/eip-2929 + let target_is_cold = handler.is_cold(target, None); + handler.mark_hot(target, None); + GasCost::Call { value: U256::from_big_endian(&stack.peek(2)?[..]), gas: U256::from_big_endian(&stack.peek(0)?[..]), - target_is_cold: handler.is_cold(target, None), + target_is_cold, target_exists: { handler.exists(target) }, } }