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

View File

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