fixes clearStorage bug

This commit is contained in:
andri lim 2020-01-15 09:33:08 +07:00 committed by zah
parent 89d1834d52
commit 16a938d3fa
3 changed files with 14 additions and 17 deletions

View File

@ -7,7 +7,7 @@
import import
strformat, strformat,
chronicles, eth/[common, rlp], eth/trie/[hexary, db], chronicles, eth/[common, rlp], eth/trie/[hexary, db, trie_defs],
../constants, ../utils, storage_types ../constants, ../utils, storage_types
logScope: logScope:
@ -93,10 +93,9 @@ template getAccountTrie(db: AccountStateDB, account: Account): auto =
# see nim-eth#9 # see nim-eth#9
initSecureHexaryTrie(trieDB(db), account.storageRoot, false) initSecureHexaryTrie(trieDB(db), account.storageRoot, false)
# XXX: https://github.com/status-im/nimbus/issues/142#issuecomment-420583181 proc clearStorage*(db: var AccountStateDB, address: EthAddress) =
proc setStorageRoot*(db: var AccountStateDB, address: EthAddress, storageRoot: Hash256) =
var account = db.getAccount(address) var account = db.getAccount(address)
account.storageRoot = storageRoot account.storageRoot = emptyRlpHash
db.setAccount(address, account) db.setAccount(address, account)
proc getStorageRoot*(db: AccountStateDB, address: EthAddress): Hash256 = proc getStorageRoot*(db: AccountStateDB, address: EthAddress): Hash256 =

View File

@ -12,7 +12,7 @@ import
./interpreter/[opcode_values, gas_meter, gas_costs, vm_forks], ./interpreter/[opcode_values, gas_meter, gas_costs, vm_forks],
./code_stream, ./memory, ./message, ./stack, ../db/[state_db, db_chain], ./code_stream, ./memory, ./message, ./stack, ../db/[state_db, db_chain],
../utils/header, stew/[byteutils, ranges], precompiles, ../utils/header, stew/[byteutils, ranges], precompiles,
transaction_tracer, eth/trie/trie_defs transaction_tracer
logScope: logScope:
topics = "vm computation" topics = "vm computation"
@ -50,10 +50,6 @@ template isError*(c: Computation): bool =
func shouldBurnGas*(c: Computation): bool = func shouldBurnGas*(c: Computation): bool =
c.isError and c.error.burnsGas c.isError and c.error.burnsGas
func bytesToHex(x: openarray[byte]): string {.inline.} =
## TODO: use seq[byte] for raw data and delete this proc
foldl(x, a & b.int.toHex(2).toLowerAscii, "0x")
func output*(c: Computation): seq[byte] = func output*(c: Computation): seq[byte] =
c.rawOutput c.rawOutput
@ -148,14 +144,12 @@ proc applyMessage*(c: Computation, opCode: static[Op]) =
defer: defer:
c.dispose() c.dispose()
# EIP161 nonce incrementation
when opCode in {Create, Create2}: when opCode in {Create, Create2}:
if c.fork >= FkSpurious: c.vmState.mutateStateDb:
c.vmState.mutateStateDb: db.clearStorage(c.msg.contractAddress)
if c.fork >= FkSpurious:
# EIP161 nonce incrementation
db.incNonce(c.msg.contractAddress) db.incNonce(c.msg.contractAddress)
if c.fork >= FkByzantium:
# RevertInCreateInInit.json
db.setStorageRoot(c.msg.contractAddress, emptyRlpHash)
when opCode in {CallCode, Call, Create}: when opCode in {CallCode, Call, Create}:
c.transferBalance(opCode) c.transferBalance(opCode)

View File

@ -6,12 +6,16 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms. # at your option. This file may not be copied, modified, or distributed except according to those terms.
import import
unittest2, strformat, strutils, tables, json, os, times, unittest2, strformat, strutils, tables, json, os, times, sequtils,
stew/byteutils, stew/ranges/typedranges, eth/[rlp, common], eth/trie/db, stew/byteutils, stew/ranges/typedranges, eth/[rlp, common], eth/trie/db,
./test_helpers, ./test_allowed_to_fail, ../nimbus/vm/interpreter, ./test_helpers, ./test_allowed_to_fail, ../nimbus/vm/interpreter,
../nimbus/[constants, vm_state, vm_types, utils], ../nimbus/[constants, vm_state, vm_types, utils],
../nimbus/db/[db_chain, state_db] ../nimbus/db/[db_chain, state_db]
func bytesToHex(x: openarray[byte]): string {.inline.} =
## TODO: use seq[byte] for raw data and delete this proc
foldl(x, a & b.int.toHex(2).toLowerAscii, "0x")
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus)
proc vmJsonMain*() = proc vmJsonMain*() =
@ -78,7 +82,7 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
fail() fail()
let expectedOutput = fixture{"out"}.getStr let expectedOutput = fixture{"out"}.getStr
check(computation.outputHex == expectedOutput) check(computation.output.bytesToHex == expectedOutput)
let gasMeter = computation.gasMeter let gasMeter = computation.gasMeter
let expectedGasRemaining = fixture{"gas"}.getHexadecimalInt let expectedGasRemaining = fixture{"gas"}.getHexadecimalInt