Skip to content

Commit

Permalink
charge proper warm costs (#497)
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign authored Sep 13, 2024
1 parent 219510d commit 218365f
Showing 1 changed file with 10 additions and 3 deletions.
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
if gas, overflow = math.SafeAdd(gas, wgas); overflow {
return 0, ErrGasUintOverflow
}
Expand Down

0 comments on commit 218365f

Please sign in to comment.