Skip to content

Commit

Permalink
move eip2929 fix to a different PR
Browse files Browse the repository at this point in the history
  • Loading branch information
RomarQ committed May 8, 2024
1 parent da6ac37 commit c436723
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 66 deletions.
7 changes: 7 additions & 0 deletions interpreter/src/eval/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn balance<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, T
handler: &mut H,
) -> Control<Tr> {
pop!(machine, address);
handler.mark_hot(address.into(), None);
push_u256!(machine, handler.balance(address.into()));

Control::Continue
Expand Down Expand Up @@ -126,6 +127,7 @@ pub fn extcodesize<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBacken
handler: &mut H,
) -> Control<Tr> {
pop!(machine, address);
handler.mark_hot(address.into(), None);
let code_size = handler.code_size(address.into());
push_u256!(machine, code_size);

Expand All @@ -137,6 +139,7 @@ pub fn extcodehash<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBacken
handler: &mut H,
) -> Control<Tr> {
pop!(machine, address);
handler.mark_hot(address.into(), None);
let code_hash = handler.code_hash(address.into());
push!(machine, code_hash);

Expand All @@ -149,6 +152,8 @@ pub fn extcodecopy<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBacken
) -> Control<Tr> {
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());
Expand Down Expand Up @@ -258,6 +263,7 @@ pub fn sload<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr>
handler: &mut H,
) -> Control<Tr> {
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);

Expand All @@ -269,6 +275,7 @@ pub fn sstore<S: AsRef<RuntimeState>, H: RuntimeEnvironment + RuntimeBackend, Tr
handler: &mut H,
) -> Control<Tr> {
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,
Expand Down
85 changes: 19 additions & 66 deletions src/standard/gasometer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,59 +302,40 @@ fn dynamic_opcode_cost<H: RuntimeBackend>(

Opcode::EXTCODESIZE => {
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::ExtCodeSize { target_is_cold }
GasCost::ExtCodeSize {
target_is_cold: handler.is_cold(target, None),
}
}
Opcode::BALANCE => {
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::Balance { target_is_cold }
GasCost::Balance {
target_is_cold: handler.is_cold(target, None),
}
}
Opcode::BLOCKHASH => GasCost::BlockHash,

Opcode::EXTCODEHASH if config.has_ext_code_hash => {
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::ExtCodeHash { target_is_cold }
GasCost::ExtCodeHash {
target_is_cold: handler.is_cold(target, None),
}
}
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,
target_is_cold: handler.is_cold(target, None),
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,
target_is_cold: handler.is_cold(target, None),
target_exists: { handler.exists(target) },
}
}
Expand All @@ -363,13 +344,8 @@ fn dynamic_opcode_cost<H: RuntimeBackend>(
},
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,
target_is_cold: handler.is_cold(target, None),
len: U256::from_big_endian(&stack.peek(3)?[..]),
}
}
Expand All @@ -381,25 +357,17 @@ fn dynamic_opcode_cost<H: RuntimeBackend>(
},
Opcode::SLOAD => {
let index = stack.peek(0)?;

// 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 }
GasCost::SLoad {
target_is_cold: handler.is_cold(address, Some(index)),
}
}
Opcode::TLOAD => GasCost::TLoad,

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,
target_is_cold: handler.is_cold(target, None),
target_exists: { handler.exists(target) },
}
}
Expand All @@ -414,16 +382,11 @@ fn dynamic_opcode_cost<H: RuntimeBackend>(
Opcode::SSTORE if !is_static => {
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,
target_is_cold: handler.is_cold(address, Some(index)),
}
}
Opcode::TSTORE if !is_static => GasCost::TStore,
Expand Down Expand Up @@ -453,14 +416,9 @@ fn dynamic_opcode_cost<H: RuntimeBackend>(
},
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,
target_is_cold: handler.is_cold(target, None),
target_exists: { handler.exists(target) },
already_removed: handler.deleted(address),
}
Expand All @@ -470,15 +428,10 @@ fn dynamic_opcode_cost<H: RuntimeBackend>(
|| (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,
target_is_cold: handler.is_cold(target, None),
target_exists: { handler.exists(target) },
}
}
Expand Down

0 comments on commit c436723

Please sign in to comment.