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

Sload fix #69

Merged
Merged
Changes from 2 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
17 changes: 15 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,26 @@ 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
gasUsed += params.ColdSloadCostEIP2929
} else {
gasUsed += params.WarmStorageReadCostEIP2929
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gasUsed += params.ColdSloadCostEIP2929
} else {
gasUsed += params.WarmStorageReadCostEIP2929
return gasUsed + params.ColdSloadCostEIP2929, nil
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in two parts because of a weird issue in the github interface. Anyhow, prefer returning early to } else {, that's another one of these go-ism that, I'm told, make it such a great language.

}
return params.WarmStorageReadCostEIP2929, nil

return gasUsed, nil
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return gasUsed, nil
return gasUsed + params.WarmStorageReadCostEIP2929, nil

}

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