Skip to content

Commit

Permalink
Wrap all calls to interpreter.gas.erase_cost with checks if USE_GAS i…
Browse files Browse the repository at this point in the history
…s enabled (#346)

Co-authored-by: Christian Koopmann <christian@MTMAC0057.local>
  • Loading branch information
ckoopmann and Christian Koopmann committed Jan 27, 2023
1 parent 72355f4 commit 329fd94
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions crates/interpreter/src/instructions/host.rs
Expand Up @@ -274,12 +274,16 @@ pub fn create<const IS_CREATE2: bool, SPEC: Spec>(
match return_reason {
return_ok!() => {
push_b256!(interpreter, address.unwrap_or_default().into());
interpreter.gas.erase_cost(gas.remaining());
interpreter.gas.record_refund(gas.refunded());
if crate::USE_GAS {
interpreter.gas.erase_cost(gas.remaining());
interpreter.gas.record_refund(gas.refunded());
}
}
return_revert!() => {
push_b256!(interpreter, B256::zero());
interpreter.gas.erase_cost(gas.remaining());
if crate::USE_GAS {
interpreter.gas.erase_cost(gas.remaining());
}
}
InstructionResult::FatalExternalError => {
interpreter.instruction_result = InstructionResult::FatalExternalError;
Expand Down Expand Up @@ -463,15 +467,19 @@ pub fn call_inner<SPEC: Spec>(
match reason {
return_ok!() => {
// return unspend gas.
interpreter.gas.erase_cost(gas.remaining());
interpreter.gas.record_refund(gas.refunded());
if crate::USE_GAS {
interpreter.gas.erase_cost(gas.remaining());
interpreter.gas.record_refund(gas.refunded());
}
interpreter
.memory
.set(out_offset, &interpreter.return_data_buffer[..target_len]);
push!(interpreter, U256::from(1));
}
return_revert!() => {
interpreter.gas.erase_cost(gas.remaining());
if crate::USE_GAS {
interpreter.gas.erase_cost(gas.remaining());
}
interpreter
.memory
.set(out_offset, &interpreter.return_data_buffer[..target_len]);
Expand Down

0 comments on commit 329fd94

Please sign in to comment.