Skip to content

Commit

Permalink
fix(levm): remove consumed gas from environment (#1487)
Browse files Browse the repository at this point in the history
**Motivation**

<!-- Why does this pull request exist? What are its goals? -->

**Description**

<!-- A clear and concise general description of the changes this PR
introduces -->
- We only want to keep track of the consumed gas in the current
callframe. We don't need to keep track of it in the environment.
- This change will allow us to implement accurate behavior related to
gas consumption in XCALL and CREATE opcodes.

Note that the gas consumed by the first callframe will indeed be the gas
consumed by total execution, because the gas consume by child CallFrames
will be added to the "father". (It is not as straightforward but that's
the idea).
This change doesn't fix nor break any test, but will be useful for
following changes

<!-- Link to issues: Resolves #111, Resolves #222 -->

Closes #issue_number
  • Loading branch information
JereSalo authored Dec 12, 2024
1 parent c3bbbfd commit f8a476f
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 124 deletions.
1 change: 0 additions & 1 deletion cmd/ef_tests/levm/runner/levm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ pub fn prepare_vm_for_tx(vector: &TestVector, test: &EFTest) -> Result<VM, EFTes
tx.to.clone(),
Environment {
origin: tx.sender,
consumed_gas: U256::default(),
refunded_gas: U256::default(),
gas_limit: tx.gas_limit,
block_number: test.env.current_number,
Expand Down
2 changes: 0 additions & 2 deletions crates/vm/levm/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub struct Environment {
/// The sender address of the transaction that originated
/// this execution.
pub origin: Address,
pub consumed_gas: U256,
pub refunded_gas: U256,
pub gas_limit: U256,
pub block_number: U256,
Expand All @@ -28,7 +27,6 @@ impl Environment {
pub fn default_from_address(origin: Address) -> Self {
Self {
origin,
consumed_gas: U256::zero(),
refunded_gas: U256::default(),
gas_limit: U256::MAX,
block_number: Default::default(),
Expand Down
6 changes: 0 additions & 6 deletions crates/vm/levm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ impl VM {
.saturating_sub(current_call_frame.gas_used);
current_call_frame.gas_used =
current_call_frame.gas_used.saturating_add(left_gas);
self.env.consumed_gas = self.env.consumed_gas.saturating_add(left_gas);
}

self.restore_state(backup_db, backup_substate, backup_refunded_gas);
Expand Down Expand Up @@ -1115,11 +1114,6 @@ impl VM {
}

current_call_frame.gas_used = potential_consumed_gas;
self.env.consumed_gas = self
.env
.consumed_gas
.checked_add(gas)
.ok_or(OutOfGasError::ConsumedGasOverflow)?;

Ok(())
}
Expand Down
Loading

0 comments on commit f8a476f

Please sign in to comment.