@@ -27,17 +27,22 @@ import (
27
27
28
28
func makeGasSStoreFunc (clearingRefund uint64 ) gasFunc {
29
29
return func (evm * EVM , contract * Contract , stack * Stack , mem * Memory , memorySize uint64 ) (uint64 , error ) {
30
- // If we fail the minimum gas availability invariant, fail (0)
31
- if contract .Gas <= params .SstoreSentryGasEIP2200 {
32
- return 0 , errors .New ("not enough gas for reentrancy sentry" )
33
- }
34
30
// Gas sentry honoured, do the actual gas calculation based on the stored value
35
31
var (
36
32
y , x = stack .Back (1 ), stack .peek ()
37
33
slot = common .Hash (x .Bytes32 ())
38
34
current = evm .StateDB .GetState (contract .Address (), slot )
39
35
cost = uint64 (0 )
40
36
)
37
+
38
+ // Try updating the witness of SSTORE at first to align with reth's witness implementation.
39
+ original := evm .StateDB .GetCommittedState (contract .Address (), x .Bytes32 ())
40
+
41
+ // If we fail the minimum gas availability invariant, fail (0)
42
+ if contract .Gas <= params .SstoreSentryGasEIP2200 {
43
+ return 0 , errors .New ("not enough gas for reentrancy sentry" )
44
+ }
45
+
41
46
// Check slot presence in the access list
42
47
if addrPresent , slotPresent := evm .StateDB .SlotInAccessList (contract .Address (), slot ); ! slotPresent {
43
48
cost = params .ColdSloadCostEIP2929
@@ -57,7 +62,6 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc {
57
62
// return params.SloadGasEIP2200, nil
58
63
return cost + params .WarmStorageReadCostEIP2929 , nil // SLOAD_GAS
59
64
}
60
- original := evm .StateDB .GetCommittedState (contract .Address (), x .Bytes32 ())
61
65
if original == current {
62
66
if original == (common.Hash {}) { // create slot (2.1.1)
63
67
return cost + params .SstoreSetGasEIP2200 , nil
@@ -109,6 +113,14 @@ func gasSLoadEIP2929(evm *EVM, contract *Contract, stack *Stack, mem *Memory, me
109
113
// If the caller cannot afford the cost, this change will be rolled back
110
114
// If he does afford it, we can skip checking the same thing later on, during execution
111
115
evm .StateDB .AddSlotToAccessList (contract .Address (), slot )
116
+
117
+ // Try updating the witness of SLOAD to align with reth's witness implementation.
118
+ // Another place that needs to change is when calculating the gas cost after Frontier and before EIP-2929.
119
+ // Frontier gas cost simply uses params.SloadGasFrontier (i.e., 50 gas), so changing the gas cost there
120
+ // might affect code cleanliness. Usually, this won't be a problem because EIP-2929 is enabled by default.
121
+ // Thus, adding the SLOAD witness before EIP-2929 is left as a TODO here.
122
+ evm .StateDB .GetCommittedState (contract .Address (), loc .Bytes32 ())
123
+
112
124
return params .ColdSloadCostEIP2929 , nil
113
125
}
114
126
return params .WarmStorageReadCostEIP2929 , nil
0 commit comments