Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(EIP-7623): adjuct floor gas check order #1990

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bins/revme/src/cmd/statetest/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ pub struct Test {
/// Logs root
pub logs: B256,

/// Output state.
///
/// Note: Not used.
#[serde(default)]
state: HashMap<Address, AccountInfo>,

/// Tx bytes
pub txbytes: Option<Bytes>,
}
Expand Down
12 changes: 12 additions & 0 deletions crates/interpreter/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ impl Gas {
self.limit - self.remaining
}

/// Returns the total amount of gas spent, minus the refunded gas.
#[inline]
pub const fn spent_sub_refunded(&self) -> u64 {
self.spent().saturating_sub(self.refunded as u64)
}

/// Returns the amount of gas remaining.
#[inline]
pub const fn remaining(&self) -> u64 {
Expand Down Expand Up @@ -115,6 +121,12 @@ impl Gas {
self.refunded = refund;
}

/// Set a spent value. This overrides the current spent value.
#[inline]
pub fn set_spent(&mut self, spent: u64) {
self.remaining = self.limit.saturating_sub(spent);
}

/// Records an explicit cost.
///
/// Returns `false` if the gas limit is exceeded.
Expand Down
15 changes: 9 additions & 6 deletions crates/revm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,16 +380,19 @@ impl<EXT, DB: Database> Evm<'_, EXT, DB> {
.execution()
.last_frame_return(ctx, &mut result)?;

let post_exec = self.handler.post_execution();

// calculate final refund and add EIP-7702 refund to gas.
post_exec.refund(ctx, result.gas_mut(), eip7702_gas_refund);

// EIP-7623: Increase calldata cost
// spend at least a gas_floor amount of gas.
let gas_result = result.gas_mut();
if gas_result.spent() < gas.floor_gas {
let _ = gas_result.record_cost(gas.floor_gas - gas_result.spent());
if result.gas().spent_sub_refunded() < gas.floor_gas {
result.gas_mut().set_spent(gas.floor_gas);
// clear refund
result.gas_mut().set_refund(0);
}

let post_exec = self.handler.post_execution();
// calculate final refund and add EIP-7702 refund to gas.
post_exec.refund(ctx, result.gas_mut(), eip7702_gas_refund);
// Reimburse the caller
post_exec.reimburse_caller(ctx, result.gas())?;
// Reward beneficiary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,30 @@
"data": 0,
"gas": 0,
"value": 0
},
"state": {
"0x0000000000000000000000000000000000001000": {
"nonce": "0x01",
"balance": "0x04",
"code": "0x5854505854",
"storage": {}
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"nonce": "0x01",
"balance": "0x2cd931",
"code": "0x",
"storage": {}
}
}
}
]
},
"_info": {
"hash": "0x398e2b06c420d105024fdaf2cb8d718dca2263da0a1c71b97119cc3bf156a611",
"hash": "0x813518336344739b9f7d43d8bead1ec6bb7f6bd22c3abdb95ba468734b8ddd82",
"comment": "`execution-spec-tests` generated test",
"filling-transition-tool": "ethereum-spec-evm-resolver 0.0.1",
"description": "Test function documentation:\n\n Test type 1 transaction.",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.0.0/tests/berlin/eip2930_access_list/test_acl.py#L15",
"description": "Test function documentation:\nTest type 1 transaction.",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.2.0/tests/berlin/eip2930_access_list/test_acl.py#L19",
"fixture_format": "state_test",
"reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2930.md",
"reference-spec-version": "c9db53a936c5c9cbe2db32ba0d1b86c4c6e73534"
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,38 @@
"data": 0,
"gas": 0,
"value": 0
},
"state": {
"0x0000000000000000000000000000000000001000": {
"nonce": "0x01",
"balance": "0x00",
"code": "0x5b601660015560015c6001556001600255",
"storage": {
"0x02": "0x01"
}
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"nonce": "0x01",
"balance": "0x6124fee993b55c0a",
"code": "0x",
"storage": {}
},
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
"nonce": "0x00",
"balance": "0x01fdfd",
"code": "0x",
"storage": {}
}
}
}
]
},
"_info": {
"hash": "0x9db83db0df5dc0d207f7be69086ea2780b9bf761eaf2a922845bdf5a20503b45",
"hash": "0x907856fb2fd8fd6db58331b8cfabefd8362f41f84559c932a04908cf799c6c25",
"comment": "`execution-spec-tests` generated test",
"filling-transition-tool": "ethereum-spec-evm-resolver 0.0.1",
"description": "Test function documentation:\n\n Ported .json vectors:\n\n (18_tloadAfterStoreFiller.yml)\n tload from same slot after store returns 0",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.0.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L242",
"description": "Test function documentation:\n\n Ported .json vectors.\n\n (18_tloadAfterStoreFiller.yml)\n tload from same slot after store returns 0",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.2.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L242",
"fixture_format": "state_test",
"reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1153.md",
"reference-spec-version": "6f0be621c76a05a7b3aaf0e9297afd425c26e9d0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,40 @@
"data": 0,
"gas": 0,
"value": 0
},
"state": {
"0x0000000000000000000000000000000000001000": {
"nonce": "0x01",
"balance": "0x00",
"code": "0x5b600260105d5a6000525a60005260105c5a60205260205160005103600155600b600154036001555a60005260055c5a60205260205160005103600255600b600254036002556001600355",
"storage": {
"0x01": "0x64",
"0x02": "0x64",
"0x03": "0x01"
}
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"nonce": "0x01",
"balance": "0x6124fee993b3c58e",
"code": "0x",
"storage": {}
},
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
"nonce": "0x00",
"balance": "0x0277ef",
"code": "0x",
"storage": {}
}
}
}
]
},
"_info": {
"hash": "0x25c7427d05323eab3eb7ace72ee30c37ec6b1c64f1ee9219fb36ec51883e2368",
"hash": "0x974539d594f3f8191c54b8285a265213987b79d5c39f0954a4e1d108ab89571d",
"comment": "`execution-spec-tests` generated test",
"filling-transition-tool": "ethereum-spec-evm-resolver 0.0.1",
"description": "Test function documentation:\n\n Ported .json vectors:\n\n (16_tloadGasFiller.yml)\n tload costs 100 gas same as a warm sload",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.0.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L164",
"description": "Test function documentation:\n\n Ported .json vectors.\n\n (16_tloadGasFiller.yml)\n tload costs 100 gas same as a warm sload",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.2.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L164",
"fixture_format": "state_test",
"reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1153.md",
"reference-spec-version": "6f0be621c76a05a7b3aaf0e9297afd425c26e9d0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,38 @@
"data": 0,
"gas": 0,
"value": 0
},
"state": {
"0x0000000000000000000000000000000000001000": {
"nonce": "0x01",
"balance": "0x00",
"code": "0x5b605860035d60005c6001556001600255",
"storage": {
"0x02": "0x01"
}
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"nonce": "0x01",
"balance": "0x6124fee993b55c0a",
"code": "0x",
"storage": {}
},
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
"nonce": "0x00",
"balance": "0x01fdfd",
"code": "0x",
"storage": {}
}
}
}
]
},
"_info": {
"hash": "0x70b84abbb25422c8ec79d0e844a1086ca01f6e674a6ac9c3f655f6aa533b13c0",
"hash": "0x0b991da24446dc1d4e6cf599d8fe4aa2a0de97ff70d310f4f49c5f26b3dc3da3",
"comment": "`execution-spec-tests` generated test",
"filling-transition-tool": "ethereum-spec-evm-resolver 0.0.1",
"description": "Test function documentation:\n\n Ported .json vectors:\n\n (03_tloadAfterStoreIs0Filler.yml)\n Loading any other slot after storing to a slot returns 0.",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.0.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L116",
"description": "Test function documentation:\n\n Ported .json vectors.\n\n (03_tloadAfterStoreIs0Filler.yml)\n Loading any other slot after storing to a slot returns 0.",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.2.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L116",
"fixture_format": "state_test",
"reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1153.md",
"reference-spec-version": "6f0be621c76a05a7b3aaf0e9297afd425c26e9d0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,38 @@
"data": 0,
"gas": 0,
"value": 0
},
"state": {
"0x0000000000000000000000000000000000001000": {
"nonce": "0x01",
"balance": "0x00",
"code": "0x5b60005c6001556001600255",
"storage": {
"0x02": "0x01"
}
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"nonce": "0x01",
"balance": "0x6124fee993b5602e",
"code": "0x",
"storage": {}
},
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
"nonce": "0x00",
"balance": "0x01fcbf",
"code": "0x",
"storage": {}
}
}
}
]
},
"_info": {
"hash": "0x5f3bda498f29736003610e0931bbc1ec87f1fb292213fecbaa2c451fbcb80440",
"hash": "0x84c9704997d246938432528d5afa7ca81039bbdc74265db3a7ce27cb6d0318b8",
"comment": "`execution-spec-tests` generated test",
"filling-transition-tool": "ethereum-spec-evm-resolver 0.0.1",
"description": "Test function documentation:\n\n Ported .json vectors:\n\n (01_tloadBeginningTxnFiller.yml)\n load arbitrary value is 0 at beginning of transaction",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.0.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L19",
"description": "Test function documentation:\n\n Ported .json vectors.\n\n (01_tloadBeginningTxnFiller.yml)\n load arbitrary value is 0 at beginning of transaction",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.2.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L19",
"fixture_format": "state_test",
"reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1153.md",
"reference-spec-version": "6f0be621c76a05a7b3aaf0e9297afd425c26e9d0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,40 @@
"data": 0,
"gas": 0,
"value": 0
},
"state": {
"0x0000000000000000000000000000000000001000": {
"nonce": "0x01",
"balance": "0x00",
"code": "0x5b605860025d60025c60005560025c6001556001600255",
"storage": {
"0x00": "0x58",
"0x01": "0x58",
"0x02": "0x01"
}
},
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"nonce": "0x01",
"balance": "0x6124fee993b3d916",
"code": "0x",
"storage": {}
},
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
"nonce": "0x00",
"balance": "0x027213",
"code": "0x",
"storage": {}
}
}
}
]
},
"_info": {
"hash": "0xe2854bcacd16c70e7c34855e78ee61d35fda473f2e4e7d1a59b955503150bc0a",
"hash": "0x680e3ee2dc47e38f3e96aa1ace24844fb8a5208b24a7e8c9ebbb85a05ac2aba3",
"comment": "`execution-spec-tests` generated test",
"filling-transition-tool": "ethereum-spec-evm-resolver 0.0.1",
"description": "Test function documentation:\n\n Ported .json vectors:\n\n (02_tloadAfterTstoreFiller.yml)\n tload from same slot after tstore returns correct value",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.0.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L64",
"description": "Test function documentation:\n\n Ported .json vectors.\n\n (02_tloadAfterTstoreFiller.yml)\n tload from same slot after tstore returns correct value",
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.2.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L64",
"fixture_format": "state_test",
"reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1153.md",
"reference-spec-version": "6f0be621c76a05a7b3aaf0e9297afd425c26e9d0"
Expand Down
Loading
Loading