fix self destruct problem

This commit is contained in:
andri lim 2019-02-23 20:08:59 +07:00 committed by zah
parent d21d0814c6
commit f5e54b8d4f
2 changed files with 20 additions and 16 deletions

View File

@ -69,17 +69,17 @@ proc traceOpCodeStarted*(tracer: var TransactionTracer, c: BaseComputation, op:
if TracerFlags.EnableAccount in tracer.flags:
case op
of Call, CallCode, DelegateCall, StaticCall:
assert(c.stack.values.len > 2)
if c.stack.values.len > 2:
tracer.accounts.incl c.stack[^2, EthAddress]
of ExtCodeCopy, ExtCodeSize, Balance, SelfDestruct:
assert(c.stack.values.len > 1)
if c.stack.values.len > 1:
tracer.accounts.incl c.stack[^1, EthAddress]
else:
discard
if TracerFlags.DisableStorage notin tracer.flags:
if op == Sstore:
assert(c.stack.values.len > 1)
if c.stack.values.len > 1:
tracer.rememberStorageKey(c.msg.depth, c.stack[^1, Uint256])
result = tracer.trace["structLogs"].len - 1

View File

@ -80,7 +80,6 @@ proc applyCreateTransaction*(t: Transaction, vmState: BaseVMState, sender: EthAd
if execComputation(c):
var db = vmState.accountDb
db.addBalance(contractAddress, t.value)
# XXX: copy/pasted from GST fixture
# TODO: more merging/refactoring/etc
@ -99,6 +98,10 @@ proc applyCreateTransaction*(t: Transaction, vmState: BaseVMState, sender: EthAd
# This apparently is not supposed to actually consume the gas, just be able to,
# for purposes of accounting. Py-EVM apparently does consume the gas, but it is
# not matching observed blockchain balances if consumeGas is called.
if db.accountExists(contractAddress):
# make changes only if it not selfdestructed
db.addBalance(contractAddress, t.value)
if gasRemaining >= codeCost.u256:
db.setCode(contractAddress, c.output.toRange)
else:
@ -106,8 +109,9 @@ proc applyCreateTransaction*(t: Transaction, vmState: BaseVMState, sender: EthAd
# https://github.com/ethereum/py-evm/blob/master/eth/vm/forks/homestead/computation.py
codeCost = 0
db.setCode(contractAddress, ByteRange())
db.addBalance(sender, (t.gasLimit.u256 - gasUsed2 - codeCost.u256)*t.gasPrice.u256)
return (gasUsed2 + codeCost.u256) * t.gasPrice.u256
db.addBalance(sender, (t.gasLimit.u256 - gasUsed2 - codeCost.u256 + gasRefund) * t.gasPrice.u256)
return (gasUsed2 + codeCost.u256 - gasRefund) * t.gasPrice.u256
else:
# FIXME: don't do this revert, but rather only subBalance correctly
# the if transactionfailed at end is what is supposed to pick it up