EIP-6780: Fix self destruct operation (#1777)
This commit is contained in:
parent
dd074d4df8
commit
6848b2010b
|
@ -515,6 +515,7 @@ proc deleteAccount*(ac: AccountsCache, address: EthAddress) =
|
||||||
acc.kill()
|
acc.kill()
|
||||||
|
|
||||||
proc selfDestruct*(ac: AccountsCache, address: EthAddress) =
|
proc selfDestruct*(ac: AccountsCache, address: EthAddress) =
|
||||||
|
ac.setBalance(address, 0.u256)
|
||||||
ac.savePoint.selfDestruct.incl address
|
ac.savePoint.selfDestruct.incl address
|
||||||
|
|
||||||
proc selfDestruct6780*(ac: AccountsCache, address: EthAddress) =
|
proc selfDestruct6780*(ac: AccountsCache, address: EthAddress) =
|
||||||
|
|
|
@ -369,18 +369,19 @@ proc execSelfDestruct*(c: Computation, beneficiary: EthAddress)
|
||||||
c.vmState.mutateStateDB:
|
c.vmState.mutateStateDB:
|
||||||
let localBalance = c.getBalance(c.msg.contractAddress)
|
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
|
# Register the account to be deleted
|
||||||
if c.fork >= FkCancun:
|
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)
|
db.selfDestruct6780(c.msg.contractAddress)
|
||||||
else:
|
else:
|
||||||
|
# Transfer to beneficiary
|
||||||
|
db.addBalance(beneficiary, localBalance)
|
||||||
db.selfDestruct(c.msg.contractAddress)
|
db.selfDestruct(c.msg.contractAddress)
|
||||||
|
|
||||||
trace "SELFDESTRUCT",
|
trace "SELFDESTRUCT",
|
||||||
|
|
|
@ -220,18 +220,20 @@ proc copyCode(host: TransactionHost, address: HostAddress,
|
||||||
|
|
||||||
proc selfDestruct(host: TransactionHost, address, beneficiary: HostAddress) {.show.} =
|
proc selfDestruct(host: TransactionHost, address, beneficiary: HostAddress) {.show.} =
|
||||||
host.vmState.mutateStateDB:
|
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:
|
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)
|
db.selfDestruct6780(address)
|
||||||
else:
|
else:
|
||||||
|
# Transfer to beneficiary
|
||||||
|
db.addBalance(beneficiary, localBalance)
|
||||||
db.selfDestruct(address)
|
db.selfDestruct(address)
|
||||||
|
|
||||||
template call(host: TransactionHost, msg: EvmcMessage): EvmcResult =
|
template call(host: TransactionHost, msg: EvmcMessage): EvmcResult =
|
||||||
|
|
Loading…
Reference in New Issue