Skip to content

Commit

Permalink
fix gas charge (#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishqjasoria authored Sep 6, 2024
1 parent bf16263 commit b8bc851
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions core/vm/operations_verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,20 @@ var (

func gasSelfdestructEIP4762(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
beneficiaryAddr := common.Address(stack.peek().Bytes20())
if _, isPrecompile := evm.precompile(beneficiaryAddr); isPrecompile {
return 0, nil
}

contractAddr := contract.Address()

statelessGas := evm.Accesses.TouchBasicData(contractAddr[:], false)
balanceIsZero := evm.StateDB.GetBalance(contractAddr).Sign() == 0

if _, isPrecompile := evm.precompile(beneficiaryAddr); isPrecompile && balanceIsZero {
return statelessGas, nil
}

if contractAddr != beneficiaryAddr {
statelessGas += evm.Accesses.TouchBasicData(beneficiaryAddr[:], false)
}
// Charge write costs if it transfers value
if evm.StateDB.GetBalance(contractAddr).Sign() != 0 {
if !balanceIsZero {
statelessGas += evm.Accesses.TouchBasicData(contractAddr[:], true)
if contractAddr != beneficiaryAddr {
statelessGas += evm.Accesses.TouchBasicData(beneficiaryAddr[:], true)
Expand Down

0 comments on commit b8bc851

Please sign in to comment.