mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 13:24:21 +00:00
fixes clearStorage bug
This commit is contained in:
parent
89d1834d52
commit
16a938d3fa
@ -7,7 +7,7 @@
|
||||
|
||||
import
|
||||
strformat,
|
||||
chronicles, eth/[common, rlp], eth/trie/[hexary, db],
|
||||
chronicles, eth/[common, rlp], eth/trie/[hexary, db, trie_defs],
|
||||
../constants, ../utils, storage_types
|
||||
|
||||
logScope:
|
||||
@ -93,10 +93,9 @@ template getAccountTrie(db: AccountStateDB, account: Account): auto =
|
||||
# see nim-eth#9
|
||||
initSecureHexaryTrie(trieDB(db), account.storageRoot, false)
|
||||
|
||||
# XXX: https://github.com/status-im/nimbus/issues/142#issuecomment-420583181
|
||||
proc setStorageRoot*(db: var AccountStateDB, address: EthAddress, storageRoot: Hash256) =
|
||||
proc clearStorage*(db: var AccountStateDB, address: EthAddress) =
|
||||
var account = db.getAccount(address)
|
||||
account.storageRoot = storageRoot
|
||||
account.storageRoot = emptyRlpHash
|
||||
db.setAccount(address, account)
|
||||
|
||||
proc getStorageRoot*(db: AccountStateDB, address: EthAddress): Hash256 =
|
||||
|
@ -12,7 +12,7 @@ import
|
||||
./interpreter/[opcode_values, gas_meter, gas_costs, vm_forks],
|
||||
./code_stream, ./memory, ./message, ./stack, ../db/[state_db, db_chain],
|
||||
../utils/header, stew/[byteutils, ranges], precompiles,
|
||||
transaction_tracer, eth/trie/trie_defs
|
||||
transaction_tracer
|
||||
|
||||
logScope:
|
||||
topics = "vm computation"
|
||||
@ -50,10 +50,6 @@ template isError*(c: Computation): bool =
|
||||
func shouldBurnGas*(c: Computation): bool =
|
||||
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] =
|
||||
c.rawOutput
|
||||
|
||||
@ -148,14 +144,12 @@ proc applyMessage*(c: Computation, opCode: static[Op]) =
|
||||
defer:
|
||||
c.dispose()
|
||||
|
||||
# EIP161 nonce incrementation
|
||||
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)
|
||||
if c.fork >= FkByzantium:
|
||||
# RevertInCreateInInit.json
|
||||
db.setStorageRoot(c.msg.contractAddress, emptyRlpHash)
|
||||
|
||||
when opCode in {CallCode, Call, Create}:
|
||||
c.transferBalance(opCode)
|
||||
|
@ -6,12 +6,16 @@
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
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,
|
||||
./test_helpers, ./test_allowed_to_fail, ../nimbus/vm/interpreter,
|
||||
../nimbus/[constants, vm_state, vm_types, utils],
|
||||
../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 vmJsonMain*() =
|
||||
@ -78,7 +82,7 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
||||
fail()
|
||||
|
||||
let expectedOutput = fixture{"out"}.getStr
|
||||
check(computation.outputHex == expectedOutput)
|
||||
check(computation.output.bytesToHex == expectedOutput)
|
||||
let gasMeter = computation.gasMeter
|
||||
|
||||
let expectedGasRemaining = fixture{"gas"}.getHexadecimalInt
|
||||
|
Loading…
x
Reference in New Issue
Block a user