EIP-6780: Fix self destruct operation (#1777)

This commit is contained in:
andri lim 2023-09-26 09:03:21 +07:00 committed by GitHub
parent dd074d4df8
commit 6848b2010b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 16 deletions

View File

@ -515,6 +515,7 @@ proc deleteAccount*(ac: AccountsCache, address: EthAddress) =
acc.kill()
proc selfDestruct*(ac: AccountsCache, address: EthAddress) =
ac.setBalance(address, 0.u256)
ac.savePoint.selfDestruct.incl address
proc selfDestruct6780*(ac: AccountsCache, address: EthAddress) =

View File

@ -369,18 +369,19 @@ proc execSelfDestruct*(c: Computation, beneficiary: EthAddress)
c.vmState.mutateStateDB:
let localBalance = c.getBalance(c.msg.contractAddress)
# Transfer to beneficiary
db.addBalance(beneficiary, localBalance)
# Zero the balance of the address being deleted.
# This must come after sending to beneficiary in case the
# contract named itself as the beneficiary.
db.setBalance(c.msg.contractAddress, 0.u256)
# Register the account to be deleted
if c.fork >= FkCancun:
# Zeroing contract balance except beneficiary
# is the same address
db.subBalance(c.msg.contractAddress, localBalance)
# Transfer to beneficiary
db.addBalance(beneficiary, localBalance)
db.selfDestruct6780(c.msg.contractAddress)
else:
# Transfer to beneficiary
db.addBalance(beneficiary, localBalance)
db.selfDestruct(c.msg.contractAddress)
trace "SELFDESTRUCT",

View File

@ -220,18 +220,20 @@ proc copyCode(host: TransactionHost, address: HostAddress,
proc selfDestruct(host: TransactionHost, address, beneficiary: HostAddress) {.show.} =
host.vmState.mutateStateDB:
let closingBalance = db.getBalance(address)
let localBalance = db.getBalance(address)
# Transfer to beneficiary
db.addBalance(beneficiary, closingBalance)
# Zero balance of account being deleted.
# This must come after sending to the beneficiary in case the
# contract named itself as the beneficiary.
db.setBalance(address, 0.u256)
if host.vmState.fork >= FkCancun:
# Zeroing contract balance except beneficiary
# is the same address
db.subBalance(address, localBalance)
# Transfer to beneficiary
db.addBalance(beneficiary, localBalance)
db.selfDestruct6780(address)
else:
# Transfer to beneficiary
db.addBalance(beneficiary, localBalance)
db.selfDestruct(address)
template call(host: TransactionHost, msg: EvmcMessage): EvmcResult =