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

charge proper warm costs #497

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all 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
13 changes: 10 additions & 3 deletions core/vm/operations_verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func gasBalance4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, mem
func gasExtCodeSize4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
address := stack.peek().Bytes20()
if _, isPrecompile := evm.precompile(address); isPrecompile {
return 0, nil
return params.WarmStorageReadCostEIP2929, nil
}
wgas := evm.Accesses.TouchBasicData(address[:], false)
if wgas == 0 {
Expand All @@ -62,7 +62,7 @@ func gasExtCodeSize4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory,
func gasExtCodeHash4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
address := stack.peek().Bytes20()
if _, isPrecompile := evm.precompile(address); isPrecompile || evm.isSystemContract(address) {
return 0, nil
return params.WarmStorageReadCostEIP2929, nil
}
codehashgas := evm.Accesses.TouchCodeHash(address[:], false)
if codehashgas == 0 {
Expand All @@ -79,6 +79,10 @@ func makeCallVariantGasEIP4762(oldCalculator gasFunc) gasFunc {
}
target := common.Address(stack.Back(1).Bytes20())
if _, isPrecompile := evm.precompile(target); isPrecompile {
var overflow bool
if gas, overflow = math.SafeAdd(gas, params.WarmStorageReadCostEIP2929); overflow {
return 0, ErrGasUintOverflow
}
return gas, nil
}
// The charging for the value transfer is done BEFORE subtracting
Expand Down Expand Up @@ -138,14 +142,17 @@ func gasExtCodeCopyEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Memo
addr := common.Address(stack.peek().Bytes20())

if _, isPrecompile := evm.precompile(addr); isPrecompile {
var overflow bool
if gas, overflow = math.SafeAdd(gas, params.WarmStorageReadCostEIP2929); overflow {
return 0, ErrGasUintOverflow
}
return gas, nil
}
wgas := evm.Accesses.TouchBasicData(addr[:], false)
if wgas == 0 {
wgas = params.WarmStorageReadCostEIP2929
}
var overflow bool
// We charge (cold-warm), since 'warm' is already charged as constantGas
Copy link
Collaborator Author

@jsign jsign Sep 13, 2024

Choose a reason for hiding this comment

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

@gballet, if I looked correctly, for the verkle fork there aren't constant gas costs? Or maybe I misinterpreted the comment.

Link

Copy link
Owner

Choose a reason for hiding this comment

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

yeah that's incorrect. There was a time when it was, but this comment should have been deleted a long time ago.

if gas, overflow = math.SafeAdd(gas, wgas); overflow {
return 0, ErrGasUintOverflow
}
Expand Down
Loading