13 additional GeneralStateTests working; remove commented auto-ported Py-EVM validations which are implicit in UInt256; address comments to last commit (toSeq, hoising vmState.readOnlyStateDB, deltaBalance -> increaseBalance)

This commit is contained in:
Dustin Brody 2018-09-15 13:04:58 -07:00
parent 409d875beb
commit beb1befc6e
4 changed files with 54 additions and 41 deletions

View File

@ -623,7 +623,7 @@ OK: 0/8 Fail: 8/8 Skip: 0/8
MSTORE_Bounds2.json Skip
MSTORE_Bounds2a.json Skip
POP_Bounds.json Skip
- RETURN_Bounds.json Fail
+ RETURN_Bounds.json OK
SLOAD_Bounds.json Skip
SSTORE_Bounds.json Skip
mload32bitBound.json Skip
@ -636,7 +636,7 @@ OK: 0/8 Fail: 8/8 Skip: 0/8
static_CALL_Bounds2a.json Skip
static_CALL_Bounds3.json Skip
```
OK: 4/38 Fail: 1/38 Skip: 33/38
OK: 5/38 Fail: 0/38 Skip: 33/38
## stMemoryTest
```diff
- callDataCopyOffset.json Fail
@ -1259,7 +1259,7 @@ OK: 0/16 Fail: 0/16 Skip: 16/16
+ randomStatetest66.json OK
+ randomStatetest67.json OK
+ randomStatetest69.json OK
- randomStatetest7.json Fail
+ randomStatetest7.json OK
+ randomStatetest72.json OK
+ randomStatetest73.json OK
+ randomStatetest74.json OK
@ -1284,7 +1284,7 @@ OK: 0/16 Fail: 0/16 Skip: 16/16
+ randomStatetest97.json OK
+ randomStatetest98.json OK
```
OK: 293/327 Fail: 30/327 Skip: 4/327
OK: 294/327 Fail: 29/327 Skip: 4/327
## stRandom2
```diff
+ 201503110226PYTHON_DUP6.json OK
@ -1339,7 +1339,7 @@ OK: 293/327 Fail: 30/327 Skip: 4/327
+ randomStatetest440.json OK
+ randomStatetest441.json OK
+ randomStatetest442.json OK
- randomStatetest443.json Fail
+ randomStatetest443.json OK
+ randomStatetest444.json OK
+ randomStatetest445.json OK
+ randomStatetest446.json OK
@ -1515,7 +1515,7 @@ OK: 293/327 Fail: 30/327 Skip: 4/327
- randomStatetest646.json Fail
randomStatetest647.json Skip
```
OK: 200/227 Fail: 23/227 Skip: 4/227
OK: 201/227 Fail: 22/227 Skip: 4/227
## stRecursiveCreate
```diff
- recursiveCreate.json Fail
@ -1576,7 +1576,7 @@ OK: 11/19 Fail: 8/19 Skip: 0/19
+ returndatasize_after_failing_callcode.json OK
returndatasize_after_failing_delegatecall.json Skip
+ returndatasize_after_failing_staticcall.json OK
- returndatasize_after_oog_after_deeper.json Fail
+ returndatasize_after_oog_after_deeper.json OK
+ returndatasize_after_successful_callcode.json OK
+ returndatasize_after_successful_delegatecall.json OK
+ returndatasize_after_successful_staticcall.json OK
@ -1585,7 +1585,7 @@ OK: 11/19 Fail: 8/19 Skip: 0/19
+ returndatasize_initial.json OK
+ returndatasize_initial_zero_read.json OK
```
OK: 24/37 Fail: 10/37 Skip: 3/37
OK: 25/37 Fail: 9/37 Skip: 3/37
## stRevertTest
```diff
- LoopCallsDepthThenRevert.json Fail
@ -1598,12 +1598,12 @@ OK: 24/37 Fail: 10/37 Skip: 3/37
- RevertDepth2.json Fail
- RevertDepthCreateAddressCollision.json Fail
- RevertDepthCreateOOG.json Fail
- RevertInCallCode.json Fail
+ RevertInCallCode.json OK
- RevertInCreateInInit.json Fail
- RevertInDelegateCall.json Fail
+ RevertInDelegateCall.json OK
+ RevertInStaticCall.json OK
+ RevertOnEmptyStack.json OK
- RevertOpcode.json Fail
+ RevertOpcode.json OK
- RevertOpcodeCalls.json Fail
- RevertOpcodeCreate.json Fail
- RevertOpcodeDirectCall.json Fail
@ -1618,21 +1618,21 @@ OK: 24/37 Fail: 10/37 Skip: 3/37
RevertPrecompiledTouchDC.json Skip
- RevertPrefound.json Fail
- RevertPrefoundCall.json Fail
- RevertPrefoundCallOOG.json Fail
+ RevertPrefoundCallOOG.json OK
- RevertPrefoundEmpty.json Fail
- RevertPrefoundEmptyCall.json Fail
- RevertPrefoundEmptyCallOOG.json Fail
+ RevertPrefoundEmptyCallOOG.json OK
- RevertPrefoundEmptyOOG.json Fail
- RevertPrefoundOOG.json Fail
- RevertRemoteSubCallStorageOOG.json Fail
- RevertRemoteSubCallStorageOOG2.json Fail
- RevertSubCallStorageOOG.json Fail
- RevertSubCallStorageOOG2.json Fail
+ RevertSubCallStorageOOG.json OK
+ RevertSubCallStorageOOG2.json OK
- TouchToEmptyAccountRevert.json Fail
- TouchToEmptyAccountRevert2.json Fail
- TouchToEmptyAccountRevert3.json Fail
```
OK: 3/43 Fail: 35/43 Skip: 5/43
OK: 10/43 Fail: 28/43 Skip: 5/43
## stShift
```diff
sar00.json Skip
@ -2041,8 +2041,8 @@ OK: 0/284 Fail: 0/284 Skip: 284/284
- CallToNameRegistratorTooMuchMemory2.json Fail
- CallToNameRegistratorZeorSizeMemExpansion.json Fail
- CallToReturn1.json Fail
- CallToReturn1ForDynamicJump0.json Fail
- CallToReturn1ForDynamicJump1.json Fail
+ CallToReturn1ForDynamicJump0.json OK
+ CallToReturn1ForDynamicJump1.json OK
- CalltoReturn2.json Fail
- CreateHashCollision.json Fail
- PostToReturn1.json Fail
@ -2083,7 +2083,7 @@ OK: 0/284 Fail: 0/284 Skip: 284/284
+ suicideSendEtherToMe.json OK
- testRandomTest.json Fail
```
OK: 21/67 Fail: 44/67 Skip: 2/67
OK: 23/67 Fail: 42/67 Skip: 2/67
## stTransactionTest
```diff
+ ContractStoreClearsOOG.json OK

View File

@ -61,7 +61,7 @@ proc setBalance*(db: var AccountStateDB, address: EthAddress, balance: UInt256)
account.balance = balance
db.setAccount(address, account)
proc deltaBalance*(db: var AccountStateDB, address: EthAddress, delta: UInt256) =
proc increaseBalance*(db: var AccountStateDB, address: EthAddress, delta: UInt256) =
db.setBalance(address, db.getBalance(address) + delta)
template createTrieKeyFromSlot(slot: UInt256): ByteRange =
@ -76,12 +76,19 @@ template createTrieKeyFromSlot(slot: UInt256): ByteRange =
template getAccountTrie(stateDb: AccountStateDB, account: Account): auto =
initSecureHexaryTrie(HexaryTrie(stateDb.trie).db, account.storageRoot)
# XXX: https://github.com/status-im/nimbus/issues/142#issuecomment-420583181
proc setStorageRoot*(db: var AccountStateDB, address: EthAddress, storageRoot: Hash256) =
var account = db.getAccount(address)
account.storageRoot = storageRoot
db.setAccount(address, account)
proc getStorageRoot*(db: var AccountStateDB, address: EthAddress): Hash256 =
var account = db.getAccount(address)
account.storageRoot
proc setStorage*(db: var AccountStateDB,
address: EthAddress,
slot: UInt256, value: UInt256) =
#validateGte(value, 0, title="Storage Value")
#validateGte(slot, 0, title="Storage Slot")
var account = db.getAccount(address)
var accountTrie = getAccountTrie(db, account)
let slotAsKey = createTrieKeyFromSlot slot

View File

@ -101,9 +101,7 @@ func getAccountsForDeletion*(c: BaseComputation): seq[EthAddress] =
if c.isError:
result = @[]
else:
result = @[]
for account in c.accountsToDelete.keys:
result.add(account)
result = toSeq c.accountsToDelete.keys
proc getLogEntries*(c: BaseComputation): seq[(string, seq[UInt256], string)] =
# TODO

View File

@ -60,32 +60,36 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
# XXX: https://github.com/status-im/nimbus/issues/35#issuecomment-391726518
# TODO: put yellow paper ref here from that link justifying the limit (1 shl 34 is stand-in)
var readOnlyDB = vmState.readOnlyStateDB
if transaction.gasLimit < transaction.getFixtureIntrinsicGas or
transaction.gasPrice > (1 shl 34) or
transaction.accountNonce != vmState.readOnlyStateDB.getNonce(sender) or
vmState.readOnlyStateDB.getBalance(sender) < gas_cost:
transaction.accountNonce != readOnlyDB.getNonce(sender) or
readOnlyDB.getBalance(sender) < gas_cost:
vmState.mutateStateDb:
# pre-EIP158 (e.g., Byzantium, should ensure currentCoinbase exists)
# but in later forks, don't create at all
db.deltaBalance(currentCoinbase, 0.u256)
db.increaseBalance(currentCoinbase, 0.u256)
# FIXME: don't repeat this code
# TODO: iterate over all fixture indexes
doAssert "0x" & `$`(vmState.readOnlyStateDB.rootHash).toLowerAscii == fixture["post"]["Homestead"][0]["hash"].getStr
return
# TODO: implement other sorts of transactions
# TODO: check whether it's to an empty address
# This address might not have code. This is fine.
let code = fixture["pre"].getFixtureCode(transaction.to)
# TODO: replace with cachingDb or similar approach; necessary
# when calls/subcalls/etc come in, too.
var foo = vmState.readOnlyStateDB
let storageRoot = foo.getStorageRoot(transaction.to)
vmState.mutateStateDB:
# TODO: combine some of these
# Also, in general, map out/etc the whole vmState.mutateStateDB flow set
db.setBalance(sender, db.getBalance(sender) - gas_cost)
db.deltaBalance(currentCoinbase, gas_cost)
db.increaseBalance(currentCoinbase, gas_cost)
db.setNonce(sender, db.getNonce(sender) + 1)
db.deltaBalance(transaction.to, transaction.value)
db.increaseBalance(transaction.to, transaction.value)
db.setBalance(sender, db.getBalance(sender) - transaction.value)
# build_message (Py-EVM)
@ -101,14 +105,16 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
options = newMessageOptions(origin = sender,
createAddress = transaction.to))
var computation = newBaseComputation(vmState, header.blockNumber, message)
computation.vmState = vmState
# doAssert not message.isCreate
var computation = newBaseComputation(vmState, header.blockNumber, message)
# XXX: https://github.com/status-im/nimbus/issues/122
computation.precompiles = initTable[string, Opcode]()
doAssert computation.isOriginComputation
# TODO: delineate here during refactoring; try block not low-hanging fruit to split
# until transactional db comes in
try:
computation.executeOpcodes()
@ -128,18 +134,20 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
if not computation.isError:
vmState.mutateStateDB:
db.setBalance(currentCoinbase, db.getBalance(currentCoinbase) - gasRefundAmount)
db.deltaBalance(sender, gasRefundAmount)
db.increaseBalance(sender, gasRefundAmount)
# TODO: only here does one commit, with some nuance/caveat
else:
# TODO: replace with transactional commit/revert state (foo.revert, or just implicit)
# TODO: replace with transactional commit/revert state (foo.revert or implicit)
vmState.mutateStateDB:
db.setBalance(transaction.to, db.getBalance(transaction.to) - transaction.value)
db.deltaBalance(sender, transaction.value)
db.increaseBalance(sender, transaction.value)
db.setStorageRoot(transaction.to, storageRoot)
except ValueError:
# TODO: replace with transactional commit/revert state (here, foo.revert)
# TODO: replace with transactional commit/revert state (foo.revert or implicit)
vmState.mutateStateDB:
db.setBalance(transaction.to, db.getBalance(transaction.to) - transaction.value)
db.deltaBalance(sender, transaction.value)
db.increaseBalance(sender, transaction.value)
db.setStorageRoot(transaction.to, storageRoot)
echo "Computation error"
# TODO: do this right