Skip to content

Commit

Permalink
Sload fix (#69)
Browse files Browse the repository at this point in the history
* move SLOAD gas calculation to gasSLoadEIP2929

* re-add gasSLoad, used by SSTORE

* make requested changes
  • Loading branch information
jwasinger authored Feb 3, 2022
1 parent c94b925 commit 7f5f975
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/vm/operations_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/params"
trieUtils "github.com/ethereum/go-ethereum/trie/utils"
)

func makeGasSStoreFunc(clearingRefund uint64) gasFunc {
Expand Down Expand Up @@ -103,14 +104,23 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc {
func gasSLoadEIP2929(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
loc := stack.peek()
slot := common.Hash(loc.Bytes32())
var gasUsed uint64

if evm.chainConfig.IsCancun(evm.Context.BlockNumber) {
where := stack.Back(0)
addr := contract.Address()
index := trieUtils.GetTreeKeyStorageSlot(addr[:], where)
gasUsed += evm.Accesses.TouchAddressOnReadAndComputeGas(index)
}

// Check slot presence in the access list
if _, slotPresent := evm.StateDB.SlotInAccessList(contract.Address(), slot); !slotPresent {
// If the caller cannot afford the cost, this change will be rolled back
// If he does afford it, we can skip checking the same thing later on, during execution
evm.StateDB.AddSlotToAccessList(contract.Address(), slot)
return params.ColdSloadCostEIP2929, nil
return gasUsed + params.ColdSloadCostEIP2929, nil
}
return params.WarmStorageReadCostEIP2929, nil
return gasUsed + params.WarmStorageReadCostEIP2929, nil
}

// gasExtCodeCopyEIP2929 implements extcodecopy according to EIP-2929
Expand Down

0 comments on commit 7f5f975

Please sign in to comment.