@@ -27,17 +27,22 @@ import (
2727
2828func makeGasSStoreFunc (clearingRefund uint64 ) gasFunc {
2929 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- }
3430 // Gas sentry honoured, do the actual gas calculation based on the stored value
3531 var (
3632 y , x = stack .Back (1 ), stack .peek ()
3733 slot = common .Hash (x .Bytes32 ())
3834 current = evm .StateDB .GetState (contract .Address (), slot )
3935 cost = uint64 (0 )
4036 )
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+
4146 // Check slot presence in the access list
4247 if addrPresent , slotPresent := evm .StateDB .SlotInAccessList (contract .Address (), slot ); ! slotPresent {
4348 cost = params .ColdSloadCostEIP2929
@@ -57,7 +62,6 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc {
5762 // return params.SloadGasEIP2200, nil
5863 return cost + params .WarmStorageReadCostEIP2929 , nil // SLOAD_GAS
5964 }
60- original := evm .StateDB .GetCommittedState (contract .Address (), x .Bytes32 ())
6165 if original == current {
6266 if original == (common.Hash {}) { // create slot (2.1.1)
6367 return cost + params .SstoreSetGasEIP2200 , nil
@@ -109,6 +113,14 @@ func gasSLoadEIP2929(evm *EVM, contract *Contract, stack *Stack, mem *Memory, me
109113 // If the caller cannot afford the cost, this change will be rolled back
110114 // If he does afford it, we can skip checking the same thing later on, during execution
111115 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+
112124 return params .ColdSloadCostEIP2929 , nil
113125 }
114126 return params .WarmStorageReadCostEIP2929 , nil
0 commit comments