Skip to content

Commit 246f483

Browse files
authored
feat(EIP-7623): adjuct floor gas check order (#1990)
* feat(EIP-7623): adjuct floor gas check order * serde default
1 parent 10d3e1d commit 246f483

File tree

174 files changed

+179372
-7962
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+179372
-7962
lines changed

bins/revme/src/cmd/statetest/models/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ pub struct Test {
4545
/// Logs root
4646
pub logs: B256,
4747

48+
/// Output state.
49+
///
50+
/// Note: Not used.
51+
#[serde(default)]
52+
state: HashMap<Address, AccountInfo>,
53+
4854
/// Tx bytes
4955
pub txbytes: Option<Bytes>,
5056
}

crates/interpreter/src/gas.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ impl Gas {
6666
self.limit - self.remaining
6767
}
6868

69+
/// Returns the total amount of gas spent, minus the refunded gas.
70+
#[inline]
71+
pub const fn spent_sub_refunded(&self) -> u64 {
72+
self.spent().saturating_sub(self.refunded as u64)
73+
}
74+
6975
/// Returns the amount of gas remaining.
7076
#[inline]
7177
pub const fn remaining(&self) -> u64 {
@@ -115,6 +121,12 @@ impl Gas {
115121
self.refunded = refund;
116122
}
117123

124+
/// Set a spent value. This overrides the current spent value.
125+
#[inline]
126+
pub fn set_spent(&mut self, spent: u64) {
127+
self.remaining = self.limit.saturating_sub(spent);
128+
}
129+
118130
/// Records an explicit cost.
119131
///
120132
/// Returns `false` if the gas limit is exceeded.

crates/revm/src/evm.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,16 +380,19 @@ impl<EXT, DB: Database> Evm<'_, EXT, DB> {
380380
.execution()
381381
.last_frame_return(ctx, &mut result)?;
382382

383+
let post_exec = self.handler.post_execution();
384+
385+
// calculate final refund and add EIP-7702 refund to gas.
386+
post_exec.refund(ctx, result.gas_mut(), eip7702_gas_refund);
387+
383388
// EIP-7623: Increase calldata cost
384389
// spend at least a gas_floor amount of gas.
385-
let gas_result = result.gas_mut();
386-
if gas_result.spent() < gas.floor_gas {
387-
let _ = gas_result.record_cost(gas.floor_gas - gas_result.spent());
390+
if result.gas().spent_sub_refunded() < gas.floor_gas {
391+
result.gas_mut().set_spent(gas.floor_gas);
392+
// clear refund
393+
result.gas_mut().set_refund(0);
388394
}
389395

390-
let post_exec = self.handler.post_execution();
391-
// calculate final refund and add EIP-7702 refund to gas.
392-
post_exec.refund(ctx, result.gas_mut(), eip7702_gas_refund);
393396
// Reimburse the caller
394397
post_exec.reimburse_caller(ctx, result.gas())?;
395398
// Reward beneficiary

tests/pectra_devnet5/state_tests/berlin/eip2930_access_list/acl/access_list.json

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,30 @@
6060
"data": 0,
6161
"gas": 0,
6262
"value": 0
63+
},
64+
"state": {
65+
"0x0000000000000000000000000000000000001000": {
66+
"nonce": "0x01",
67+
"balance": "0x04",
68+
"code": "0x5854505854",
69+
"storage": {}
70+
},
71+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
72+
"nonce": "0x01",
73+
"balance": "0x2cd931",
74+
"code": "0x",
75+
"storage": {}
76+
}
6377
}
6478
}
6579
]
6680
},
6781
"_info": {
68-
"hash": "0x398e2b06c420d105024fdaf2cb8d718dca2263da0a1c71b97119cc3bf156a611",
82+
"hash": "0x813518336344739b9f7d43d8bead1ec6bb7f6bd22c3abdb95ba468734b8ddd82",
6983
"comment": "`execution-spec-tests` generated test",
7084
"filling-transition-tool": "ethereum-spec-evm-resolver 0.0.1",
71-
"description": "Test function documentation:\n\n Test type 1 transaction.",
72-
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.0.0/tests/berlin/eip2930_access_list/test_acl.py#L15",
85+
"description": "Test function documentation:\nTest type 1 transaction.",
86+
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.2.0/tests/berlin/eip2930_access_list/test_acl.py#L19",
7387
"fixture_format": "state_test",
7488
"reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2930.md",
7589
"reference-spec-version": "c9db53a936c5c9cbe2db32ba0d1b86c4c6e73534"

tests/pectra_devnet5/state_tests/byzantium/eip198_modexp_precompile/modexp/modexp.json

Lines changed: 488 additions & 48 deletions
Large diffs are not rendered by default.

tests/pectra_devnet5/state_tests/cancun/eip1153_tstore/basic_tload/basic_tload_after_store.json

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,38 @@
5252
"data": 0,
5353
"gas": 0,
5454
"value": 0
55+
},
56+
"state": {
57+
"0x0000000000000000000000000000000000001000": {
58+
"nonce": "0x01",
59+
"balance": "0x00",
60+
"code": "0x5b601660015560015c6001556001600255",
61+
"storage": {
62+
"0x02": "0x01"
63+
}
64+
},
65+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
66+
"nonce": "0x01",
67+
"balance": "0x6124fee993b55c0a",
68+
"code": "0x",
69+
"storage": {}
70+
},
71+
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
72+
"nonce": "0x00",
73+
"balance": "0x01fdfd",
74+
"code": "0x",
75+
"storage": {}
76+
}
5577
}
5678
}
5779
]
5880
},
5981
"_info": {
60-
"hash": "0x9db83db0df5dc0d207f7be69086ea2780b9bf761eaf2a922845bdf5a20503b45",
82+
"hash": "0x907856fb2fd8fd6db58331b8cfabefd8362f41f84559c932a04908cf799c6c25",
6183
"comment": "`execution-spec-tests` generated test",
6284
"filling-transition-tool": "ethereum-spec-evm-resolver 0.0.1",
63-
"description": "Test function documentation:\n\n Ported .json vectors:\n\n (18_tloadAfterStoreFiller.yml)\n tload from same slot after store returns 0",
64-
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.0.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L242",
85+
"description": "Test function documentation:\n\n Ported .json vectors.\n\n (18_tloadAfterStoreFiller.yml)\n tload from same slot after store returns 0",
86+
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.2.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L242",
6587
"fixture_format": "state_test",
6688
"reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1153.md",
6789
"reference-spec-version": "6f0be621c76a05a7b3aaf0e9297afd425c26e9d0"

tests/pectra_devnet5/state_tests/cancun/eip1153_tstore/basic_tload/basic_tload_gasprice.json

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,40 @@
5353
"data": 0,
5454
"gas": 0,
5555
"value": 0
56+
},
57+
"state": {
58+
"0x0000000000000000000000000000000000001000": {
59+
"nonce": "0x01",
60+
"balance": "0x00",
61+
"code": "0x5b600260105d5a6000525a60005260105c5a60205260205160005103600155600b600154036001555a60005260055c5a60205260205160005103600255600b600254036002556001600355",
62+
"storage": {
63+
"0x01": "0x64",
64+
"0x02": "0x64",
65+
"0x03": "0x01"
66+
}
67+
},
68+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
69+
"nonce": "0x01",
70+
"balance": "0x6124fee993b3c58e",
71+
"code": "0x",
72+
"storage": {}
73+
},
74+
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
75+
"nonce": "0x00",
76+
"balance": "0x0277ef",
77+
"code": "0x",
78+
"storage": {}
79+
}
5680
}
5781
}
5882
]
5983
},
6084
"_info": {
61-
"hash": "0x25c7427d05323eab3eb7ace72ee30c37ec6b1c64f1ee9219fb36ec51883e2368",
85+
"hash": "0x974539d594f3f8191c54b8285a265213987b79d5c39f0954a4e1d108ab89571d",
6286
"comment": "`execution-spec-tests` generated test",
6387
"filling-transition-tool": "ethereum-spec-evm-resolver 0.0.1",
64-
"description": "Test function documentation:\n\n Ported .json vectors:\n\n (16_tloadGasFiller.yml)\n tload costs 100 gas same as a warm sload",
65-
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.0.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L164",
88+
"description": "Test function documentation:\n\n Ported .json vectors.\n\n (16_tloadGasFiller.yml)\n tload costs 100 gas same as a warm sload",
89+
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.2.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L164",
6690
"fixture_format": "state_test",
6791
"reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1153.md",
6892
"reference-spec-version": "6f0be621c76a05a7b3aaf0e9297afd425c26e9d0"

tests/pectra_devnet5/state_tests/cancun/eip1153_tstore/basic_tload/basic_tload_other_after_tstore.json

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,38 @@
5252
"data": 0,
5353
"gas": 0,
5454
"value": 0
55+
},
56+
"state": {
57+
"0x0000000000000000000000000000000000001000": {
58+
"nonce": "0x01",
59+
"balance": "0x00",
60+
"code": "0x5b605860035d60005c6001556001600255",
61+
"storage": {
62+
"0x02": "0x01"
63+
}
64+
},
65+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
66+
"nonce": "0x01",
67+
"balance": "0x6124fee993b55c0a",
68+
"code": "0x",
69+
"storage": {}
70+
},
71+
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
72+
"nonce": "0x00",
73+
"balance": "0x01fdfd",
74+
"code": "0x",
75+
"storage": {}
76+
}
5577
}
5678
}
5779
]
5880
},
5981
"_info": {
60-
"hash": "0x70b84abbb25422c8ec79d0e844a1086ca01f6e674a6ac9c3f655f6aa533b13c0",
82+
"hash": "0x0b991da24446dc1d4e6cf599d8fe4aa2a0de97ff70d310f4f49c5f26b3dc3da3",
6183
"comment": "`execution-spec-tests` generated test",
6284
"filling-transition-tool": "ethereum-spec-evm-resolver 0.0.1",
63-
"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.",
64-
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.0.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L116",
85+
"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.",
86+
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.2.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L116",
6587
"fixture_format": "state_test",
6688
"reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1153.md",
6789
"reference-spec-version": "6f0be621c76a05a7b3aaf0e9297afd425c26e9d0"

tests/pectra_devnet5/state_tests/cancun/eip1153_tstore/basic_tload/basic_tload_transaction_begin.json

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,38 @@
5252
"data": 0,
5353
"gas": 0,
5454
"value": 0
55+
},
56+
"state": {
57+
"0x0000000000000000000000000000000000001000": {
58+
"nonce": "0x01",
59+
"balance": "0x00",
60+
"code": "0x5b60005c6001556001600255",
61+
"storage": {
62+
"0x02": "0x01"
63+
}
64+
},
65+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
66+
"nonce": "0x01",
67+
"balance": "0x6124fee993b5602e",
68+
"code": "0x",
69+
"storage": {}
70+
},
71+
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
72+
"nonce": "0x00",
73+
"balance": "0x01fcbf",
74+
"code": "0x",
75+
"storage": {}
76+
}
5577
}
5678
}
5779
]
5880
},
5981
"_info": {
60-
"hash": "0x5f3bda498f29736003610e0931bbc1ec87f1fb292213fecbaa2c451fbcb80440",
82+
"hash": "0x84c9704997d246938432528d5afa7ca81039bbdc74265db3a7ce27cb6d0318b8",
6183
"comment": "`execution-spec-tests` generated test",
6284
"filling-transition-tool": "ethereum-spec-evm-resolver 0.0.1",
63-
"description": "Test function documentation:\n\n Ported .json vectors:\n\n (01_tloadBeginningTxnFiller.yml)\n load arbitrary value is 0 at beginning of transaction",
64-
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.0.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L19",
85+
"description": "Test function documentation:\n\n Ported .json vectors.\n\n (01_tloadBeginningTxnFiller.yml)\n load arbitrary value is 0 at beginning of transaction",
86+
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.2.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L19",
6587
"fixture_format": "state_test",
6688
"reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1153.md",
6789
"reference-spec-version": "6f0be621c76a05a7b3aaf0e9297afd425c26e9d0"

tests/pectra_devnet5/state_tests/cancun/eip1153_tstore/basic_tload/basic_tload_works.json

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,40 @@
5353
"data": 0,
5454
"gas": 0,
5555
"value": 0
56+
},
57+
"state": {
58+
"0x0000000000000000000000000000000000001000": {
59+
"nonce": "0x01",
60+
"balance": "0x00",
61+
"code": "0x5b605860025d60025c60005560025c6001556001600255",
62+
"storage": {
63+
"0x00": "0x58",
64+
"0x01": "0x58",
65+
"0x02": "0x01"
66+
}
67+
},
68+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
69+
"nonce": "0x01",
70+
"balance": "0x6124fee993b3d916",
71+
"code": "0x",
72+
"storage": {}
73+
},
74+
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
75+
"nonce": "0x00",
76+
"balance": "0x027213",
77+
"code": "0x",
78+
"storage": {}
79+
}
5680
}
5781
}
5882
]
5983
},
6084
"_info": {
61-
"hash": "0xe2854bcacd16c70e7c34855e78ee61d35fda473f2e4e7d1a59b955503150bc0a",
85+
"hash": "0x680e3ee2dc47e38f3e96aa1ace24844fb8a5208b24a7e8c9ebbb85a05ac2aba3",
6286
"comment": "`execution-spec-tests` generated test",
6387
"filling-transition-tool": "ethereum-spec-evm-resolver 0.0.1",
64-
"description": "Test function documentation:\n\n Ported .json vectors:\n\n (02_tloadAfterTstoreFiller.yml)\n tload from same slot after tstore returns correct value",
65-
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.0.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L64",
88+
"description": "Test function documentation:\n\n Ported .json vectors.\n\n (02_tloadAfterTstoreFiller.yml)\n tload from same slot after tstore returns correct value",
89+
"url": "https://github.com/ethereum/execution-spec-tests/blob/pectra-devnet-5@v1.2.0/tests/cancun/eip1153_tstore/test_basic_tload.py#L64",
6690
"fixture_format": "state_test",
6791
"reference-spec": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1153.md",
6892
"reference-spec-version": "6f0be621c76a05a7b3aaf0e9297afd425c26e9d0"

0 commit comments

Comments
 (0)