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

fix self destruct gas charges #483

Merged
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: 8 additions & 5 deletions core/vm/operations_verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

While it's true that this touch should have not practical effect, I'd still keep it after the precompile if.

balanceIsZero := evm.StateDB.GetBalance(contractAddr).Sign() == 0

if _, isPrecompile := evm.precompile(beneficiaryAddr); isPrecompile && balanceIsZero {
Copy link
Author

Choose a reason for hiding this comment

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

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
Loading