evm: Reject contract creation if the storage is non-empty(EIP-7610)

This commit is contained in:
jangko 2024-04-16 09:26:07 +07:00
parent 5c4358a969
commit d261484dd7
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
9 changed files with 63 additions and 88 deletions

View File

@ -1,42 +0,0 @@
* engine
- Failing Cases:
- Invalid Missing Ancestor Syncing ReOrg, InvalidStateRoot, EmptyTxs=true, CanonicalReOrg=false, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidStateRoot, EmptyTxs=false, CanonicalReOrg=false, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidStateRoot, EmptyTxs=true, CanonicalReOrg=true, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidStateRoot, EmptyTxs=false, CanonicalReOrg=true, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidReceiptsRoot, EmptyTxs=false, CanonicalReOrg=false, Invalid P8
- Invalid Missing Ancestor Syncing ReOrg, InvalidReceiptsRoot, EmptyTxs=false, CanonicalReOrg=true, Invalid P8
- Invalid Missing Ancestor Syncing ReOrg, InvalidGasLimit, EmptyTxs=false, CanonicalReOrg=false, Invalid P8
- Invalid Missing Ancestor Syncing ReOrg, InvalidGasLimit, EmptyTxs=false, CanonicalReOrg=true, Invalid P8
- Invalid Missing Ancestor Syncing ReOrg, InvalidGasUsed, EmptyTxs=false, CanonicalReOrg=false, Invalid P8
- Invalid Missing Ancestor Syncing ReOrg, InvalidGasUsed, EmptyTxs=false, CanonicalReOrg=true, Invalid P8
- Invalid Missing Ancestor Syncing ReOrg, InvalidTimestamp, EmptyTxs=false, CanonicalReOrg=false, Invalid P8
- Invalid Missing Ancestor Syncing ReOrg, InvalidTimestamp, EmptyTxs=false, CanonicalReOrg=true, Invalid P8
- Invalid Missing Ancestor Syncing ReOrg, RemoveTransaction, EmptyTxs=false, CanonicalReOrg=false, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, RemoveTransaction, EmptyTxs=false, CanonicalReOrg=true, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidTransactionSignature, EmptyTxs=false, CanonicalReOrg=false, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidTransactionSignature, EmptyTxs=false, CanonicalReOrg=true, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidTransactionNonce, EmptyTxs=false, CanonicalReOrg=false, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidTransactionNonce, EmptyTxs=false, CanonicalReOrg=true, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidTransactionGas, EmptyTxs=false, CanonicalReOrg=false, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidTransactionGas, EmptyTxs=false, CanonicalReOrg=true, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidTransactionGasPrice, EmptyTxs=false, CanonicalReOrg=false, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidTransactionGasPrice, EmptyTxs=false, CanonicalReOrg=true, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidTransactionValue, EmptyTxs=false, CanonicalReOrg=false, Invalid P9
- Invalid Missing Ancestor Syncing ReOrg, InvalidTransactionValue, EmptyTxs=false, CanonicalReOrg=true, Invalid P9
- Blob Transaction Ordering, Multiple Accounts
- Blob Transaction Ordering, Multiple Clients
- Invalid InvalidParentBeaconBlockRoot NewPayload
- Invalid InvalidParentBeaconBlockRoot NewPayload - syncing
- Invalid InvalidBlobGasUsed NewPayload
- Invalid InvalidBlobGasUsed NewPayload - syncing
- Invalid InvalidBlobCountGasUsed NewPayload
- Invalid InvalidBlobCountGasUsed NewPayload - syncing
- Invalid InvalidExcessBlobGas NewPayload
- Invalid InvalidExcessBlobGas NewPayload - syncing
- Invalid InvalidVersionedHashes NewPayload - syncing
- Invalid InvalidVersionedHashesVersion NewPayload - syncing
- Invalid IncompleteVersionedHashes NewPayload - syncing
- Invalid ExtraVersionedHashes NewPayload - syncing
- ok: 220, skipped: 0, failed: 38
- Elapsed: 04:02

View File

@ -19,7 +19,7 @@ newBlockchainTests
+ withdrawalsValidatorIndexBounds.json OK
```
OK: 15/15 Fail: 0/15 Skip: 0/15
## bcArrowGlacierToMerge
## bcArrowGlacierToParis
```diff
+ difficultyFormula.json OK
+ powToPosBlockRejection.json OK
@ -195,6 +195,8 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
OK: 9/9 Fail: 0/9 Skip: 0/9
## bcRandomBlockhashTest
```diff
+ 201503110226PYTHON_DUP6BC.json OK
+ randomStatetest101BC.json OK
+ randomStatetest109BC.json OK
+ randomStatetest113BC.json OK
+ randomStatetest127BC.json OK
@ -230,6 +232,7 @@ OK: 9/9 Fail: 0/9 Skip: 0/9
+ randomStatetest314BC.json OK
+ randomStatetest317BC.json OK
+ randomStatetest319BC.json OK
+ randomStatetest32BC.json OK
+ randomStatetest330BC.json OK
+ randomStatetest331BC.json OK
+ randomStatetest344BC.json OK
@ -243,6 +246,7 @@ OK: 9/9 Fail: 0/9 Skip: 0/9
+ randomStatetest400BC.json OK
+ randomStatetest403BC.json OK
+ randomStatetest40BC.json OK
+ randomStatetest423BC.json OK
+ randomStatetest427BC.json OK
+ randomStatetest431BC.json OK
+ randomStatetest432BC.json OK
@ -251,14 +255,17 @@ OK: 9/9 Fail: 0/9 Skip: 0/9
+ randomStatetest453BC.json OK
+ randomStatetest459BC.json OK
+ randomStatetest463BC.json OK
+ randomStatetest468BC.json OK
+ randomStatetest479BC.json OK
+ randomStatetest486BC.json OK
+ randomStatetest490BC.json OK
+ randomStatetest492BC.json OK
+ randomStatetest50BC.json OK
+ randomStatetest515BC.json OK
+ randomStatetest522BC.json OK
+ randomStatetest529BC.json OK
+ randomStatetest530BC.json OK
+ randomStatetest538BC.json OK
+ randomStatetest540BC.json OK
+ randomStatetest551BC.json OK
+ randomStatetest557BC.json OK
@ -266,6 +273,7 @@ OK: 9/9 Fail: 0/9 Skip: 0/9
+ randomStatetest568BC.json OK
+ randomStatetest56BC.json OK
+ randomStatetest570BC.json OK
+ randomStatetest573BC.json OK
+ randomStatetest590BC.json OK
+ randomStatetest591BC.json OK
+ randomStatetest593BC.json OK
@ -286,13 +294,14 @@ OK: 9/9 Fail: 0/9 Skip: 0/9
+ randomStatetest71BC.json OK
+ randomStatetest76BC.json OK
+ randomStatetest79BC.json OK
+ randomStatetest7BC.json OK
+ randomStatetest86BC.json OK
+ randomStatetest8BC.json OK
+ randomStatetest91BC.json OK
+ randomStatetest93BC.json OK
+ randomStatetest99BC.json OK
```
OK: 96/96 Fail: 0/96 Skip: 0/96
OK: 105/105 Fail: 0/105 Skip: 0/105
## bcStateTests
```diff
+ BLOCKHASH_Bounds.json OK
@ -510,6 +519,11 @@ OK: 17/17 Fail: 0/17 Skip: 0/17
+ walletReorganizeOwners.json OK
```
OK: 5/5 Fail: 0/5 Skip: 0/5
## create2
```diff
+ recreate.json OK
```
OK: 1/1 Fail: 0/1 Skip: 0/1
## eip1153_tstore
```diff
+ contract_creation.json OK
@ -660,6 +674,7 @@ OK: 5/5 Fail: 0/5 Skip: 0/5
+ delegatecall_from_pre_existing_contract_to_new_contract.json OK
+ dynamic_create2_selfdestruct_collision.json OK
+ dynamic_create2_selfdestruct_collision_multi_tx.json OK
+ dynamic_create2_selfdestruct_collision_two_different_transactio OK
+ recreate_self_destructed_contract_different_txs.json OK
+ reentrancy_selfdestruct_revert.json OK
+ self_destructing_initcode.json OK
@ -669,7 +684,7 @@ OK: 5/5 Fail: 0/5 Skip: 0/5
+ selfdestruct_not_created_in_same_tx_with_revert.json OK
+ selfdestruct_pre_existing.json OK
```
OK: 13/13 Fail: 0/13 Skip: 0/13
OK: 14/14 Fail: 0/14 Skip: 0/14
## eip7516_blobgasfee
```diff
+ blobbasefee_before_fork.json OK
@ -680,10 +695,11 @@ OK: 13/13 Fail: 0/13 Skip: 0/13
OK: 4/4 Fail: 0/4 Skip: 0/4
## opcodes
```diff
+ double_kill.json OK
+ dup.json OK
+ value_transfer_gas_calculation.json OK
```
OK: 2/2 Fail: 0/2 Skip: 0/2
OK: 3/3 Fail: 0/3 Skip: 0/3
## security
```diff
+ tx_selfdestruct_balance_bug.json OK
@ -1941,7 +1957,6 @@ OK: 0/17 Fail: 0/17 Skip: 17/17
randomStatetest1.json Skip
+ randomStatetest10.json OK
+ randomStatetest100.json OK
+ randomStatetest101.json OK
+ randomStatetest102.json OK
+ randomStatetest103.json OK
+ randomStatetest104.json OK
@ -2141,7 +2156,6 @@ OK: 0/17 Fail: 0/17 Skip: 17/17
+ randomStatetest315.json OK
+ randomStatetest316.json OK
+ randomStatetest318.json OK
randomStatetest32.json Skip
+ randomStatetest320.json OK
+ randomStatetest321.json OK
+ randomStatetest322.json OK
@ -2211,7 +2225,6 @@ OK: 0/17 Fail: 0/17 Skip: 17/17
+ randomStatetest48.json OK
+ randomStatetest49.json OK
+ randomStatetest5.json OK
+ randomStatetest50.json OK
+ randomStatetest51.json OK
+ randomStatetest52.json OK
+ randomStatetest53.json OK
@ -2228,7 +2241,6 @@ OK: 0/17 Fail: 0/17 Skip: 17/17
+ randomStatetest66.json OK
+ randomStatetest67.json OK
+ randomStatetest69.json OK
+ randomStatetest7.json OK
+ randomStatetest72.json OK
+ randomStatetest73.json OK
+ randomStatetest74.json OK
@ -2252,10 +2264,9 @@ OK: 0/17 Fail: 0/17 Skip: 17/17
+ randomStatetest97.json OK
+ randomStatetest98.json OK
```
OK: 310/314 Fail: 0/314 Skip: 4/314
OK: 307/310 Fail: 0/310 Skip: 3/310
## stRandom2
```diff
+ 201503110226PYTHON_DUP6.json OK
+ randomStatetest.json OK
+ randomStatetest384.json OK
+ randomStatetest385.json OK
@ -2290,7 +2301,6 @@ OK: 310/314 Fail: 0/314 Skip: 4/314
+ randomStatetest420.json OK
+ randomStatetest421.json OK
+ randomStatetest422.json OK
+ randomStatetest423.json OK
+ randomStatetest424.json OK
+ randomStatetest425.json OK
+ randomStatetest426.json OK
@ -2327,7 +2337,6 @@ OK: 310/314 Fail: 0/314 Skip: 4/314
+ randomStatetest465.json OK
+ randomStatetest466.json OK
+ randomStatetest467.json OK
+ randomStatetest468.json OK
+ randomStatetest469.json OK
+ randomStatetest470.json OK
+ randomStatetest471.json OK
@ -2389,7 +2398,6 @@ OK: 310/314 Fail: 0/314 Skip: 4/314
+ randomStatetest535.json OK
+ randomStatetest536.json OK
+ randomStatetest537.json OK
+ randomStatetest538.json OK
+ randomStatetest539.json OK
+ randomStatetest541.json OK
+ randomStatetest542.json OK
@ -2417,7 +2425,6 @@ OK: 310/314 Fail: 0/314 Skip: 4/314
+ randomStatetest569.json OK
+ randomStatetest571.json OK
+ randomStatetest572.json OK
+ randomStatetest573.json OK
+ randomStatetest574.json OK
+ randomStatetest575.json OK
+ randomStatetest576.json OK
@ -2481,7 +2488,7 @@ OK: 310/314 Fail: 0/314 Skip: 4/314
+ randomStatetest649.json OK
+ randomStatetest650.json OK
```
OK: 223/225 Fail: 0/225 Skip: 2/225
OK: 218/220 Fail: 0/220 Skip: 2/220
## stRecursiveCreate
```diff
+ recursiveCreate.json OK
@ -3455,6 +3462,7 @@ OK: 36/36 Fail: 0/36 Skip: 0/36
+ ecpairing_bad_length_193.json OK
+ ecpairing_empty_data.json OK
+ ecpairing_empty_data_insufficient_gas.json OK
+ ecpairing_inputs.json OK
+ ecpairing_one_point_fail.json OK
+ ecpairing_one_point_insufficient_gas.json OK
+ ecpairing_one_point_not_in_subgroup.json OK
@ -3485,7 +3493,7 @@ OK: 36/36 Fail: 0/36 Skip: 0/36
+ pointMulAdd.json OK
+ pointMulAdd2.json OK
```
OK: 134/134 Fail: 0/134 Skip: 0/134
OK: 135/135 Fail: 0/135 Skip: 0/135
## stZeroKnowledge2
```diff
+ ecadd_0-0_0-0_21000_0.json OK
@ -3718,4 +3726,4 @@ OK: 11/11 Fail: 0/11 Skip: 0/11
OK: 1/1 Fail: 0/1 Skip: 0/1
---TOTAL---
OK: 3162/3268 Fail: 0/3268 Skip: 106/3268
OK: 3167/3272 Fail: 0/3272 Skip: 105/3272

View File

@ -53,17 +53,6 @@ OK: 7/7 Fail: 0/7 Skip: 0/7
+ gas_usage.json OK
```
OK: 3/3 Fail: 0/3 Skip: 0/3
## eip4788_beacon_root
```diff
+ beacon_root_contract_calls.json OK
+ beacon_root_contract_timestamps.json OK
+ beacon_root_equal_to_timestamp.json OK
+ beacon_root_selfdestruct.json OK
+ calldata_lengths.json OK
+ invalid_beacon_root_calldata_value.json OK
+ tx_to_beacon_root_contract.json OK
```
OK: 7/7 Fail: 0/7 Skip: 0/7
## eip4844_blobs
```diff
+ blob_gas_subtraction_tx.json OK
@ -1375,7 +1364,6 @@ OK: 0/17 Fail: 0/17 Skip: 17/17
randomStatetest1.json Skip
+ randomStatetest10.json OK
+ randomStatetest100.json OK
+ randomStatetest101.json OK
+ randomStatetest102.json OK
+ randomStatetest103.json OK
+ randomStatetest104.json OK
@ -1575,7 +1563,6 @@ OK: 0/17 Fail: 0/17 Skip: 17/17
+ randomStatetest315.json OK
+ randomStatetest316.json OK
+ randomStatetest318.json OK
randomStatetest32.json Skip
+ randomStatetest320.json OK
+ randomStatetest321.json OK
+ randomStatetest322.json OK
@ -1645,7 +1632,6 @@ OK: 0/17 Fail: 0/17 Skip: 17/17
+ randomStatetest48.json OK
+ randomStatetest49.json OK
+ randomStatetest5.json OK
+ randomStatetest50.json OK
+ randomStatetest51.json OK
+ randomStatetest52.json OK
+ randomStatetest53.json OK
@ -1662,7 +1648,6 @@ OK: 0/17 Fail: 0/17 Skip: 17/17
+ randomStatetest66.json OK
+ randomStatetest67.json OK
+ randomStatetest69.json OK
+ randomStatetest7.json OK
+ randomStatetest72.json OK
+ randomStatetest73.json OK
+ randomStatetest74.json OK
@ -1686,10 +1671,9 @@ OK: 0/17 Fail: 0/17 Skip: 17/17
+ randomStatetest97.json OK
+ randomStatetest98.json OK
```
OK: 310/314 Fail: 0/314 Skip: 4/314
OK: 307/310 Fail: 0/310 Skip: 3/310
## stRandom2
```diff
+ 201503110226PYTHON_DUP6.json OK
+ randomStatetest.json OK
+ randomStatetest384.json OK
+ randomStatetest385.json OK
@ -1724,7 +1708,6 @@ OK: 310/314 Fail: 0/314 Skip: 4/314
+ randomStatetest420.json OK
+ randomStatetest421.json OK
+ randomStatetest422.json OK
+ randomStatetest423.json OK
+ randomStatetest424.json OK
+ randomStatetest425.json OK
+ randomStatetest426.json OK
@ -1761,7 +1744,6 @@ OK: 310/314 Fail: 0/314 Skip: 4/314
+ randomStatetest465.json OK
+ randomStatetest466.json OK
+ randomStatetest467.json OK
+ randomStatetest468.json OK
+ randomStatetest469.json OK
+ randomStatetest470.json OK
+ randomStatetest471.json OK
@ -1823,7 +1805,6 @@ OK: 310/314 Fail: 0/314 Skip: 4/314
+ randomStatetest535.json OK
+ randomStatetest536.json OK
+ randomStatetest537.json OK
+ randomStatetest538.json OK
+ randomStatetest539.json OK
+ randomStatetest541.json OK
+ randomStatetest542.json OK
@ -1851,7 +1832,6 @@ OK: 310/314 Fail: 0/314 Skip: 4/314
+ randomStatetest569.json OK
+ randomStatetest571.json OK
+ randomStatetest572.json OK
+ randomStatetest573.json OK
+ randomStatetest574.json OK
+ randomStatetest575.json OK
+ randomStatetest576.json OK
@ -1915,7 +1895,7 @@ OK: 310/314 Fail: 0/314 Skip: 4/314
+ randomStatetest649.json OK
+ randomStatetest650.json OK
```
OK: 223/225 Fail: 0/225 Skip: 2/225
OK: 218/220 Fail: 0/220 Skip: 2/220
## stRecursiveCreate
```diff
+ recursiveCreate.json OK
@ -2889,6 +2869,7 @@ OK: 36/36 Fail: 0/36 Skip: 0/36
+ ecpairing_bad_length_193.json OK
+ ecpairing_empty_data.json OK
+ ecpairing_empty_data_insufficient_gas.json OK
+ ecpairing_inputs.json OK
+ ecpairing_one_point_fail.json OK
+ ecpairing_one_point_insufficient_gas.json OK
+ ecpairing_one_point_not_in_subgroup.json OK
@ -2919,7 +2900,7 @@ OK: 36/36 Fail: 0/36 Skip: 0/36
+ pointMulAdd.json OK
+ pointMulAdd2.json OK
```
OK: 134/134 Fail: 0/134 Skip: 0/134
OK: 135/135 Fail: 0/135 Skip: 0/135
## stZeroKnowledge2
```diff
+ ecadd_0-0_0-0_21000_0.json OK
@ -3152,4 +3133,4 @@ OK: 11/11 Fail: 0/11 Skip: 0/11
OK: 1/1 Fail: 0/1 Skip: 0/1
---TOTAL---
OK: 2719/2822 Fail: 0/2822 Skip: 103/2822
OK: 2705/2807 Fail: 0/2807 Skip: 102/2807

View File

@ -413,7 +413,9 @@ proc contractCollision*(ac: AccountsCache, address: EthAddress): bool {.inline.}
let acc = ac.getAccount(address, false)
if acc.isNil:
return
acc.account.nonce != 0 or acc.account.codeHash != EMPTY_SHA3
acc.account.nonce != 0 or
acc.account.codeHash != EMPTY_SHA3 or
acc.account.storageRoot != EMPTY_ROOT_HASH
proc accountExists*(ac: AccountsCache, address: EthAddress): bool {.inline.} =
let acc = ac.getAccount(address, false)

View File

@ -441,7 +441,9 @@ proc contractCollision*(ac: AccountsLedgerRef, address: EthAddress): bool =
let acc = ac.getAccount(address, false)
if acc.isNil:
return
acc.statement.nonce != 0 or acc.statement.codeHash != EMPTY_SHA3
acc.statement.nonce != 0 or
acc.statement.codeHash != EMPTY_SHA3 or
acc.statement.storage.stateOrVoid != EMPTY_ROOT_HASH
proc accountExists*(ac: AccountsLedgerRef, address: EthAddress): bool =
let acc = ac.getAccount(address, false)

View File

@ -225,7 +225,9 @@ proc getCode*(db: AccountStateDB, address: EthAddress): seq[byte] =
triedb.get(contractHashKey(db.getCodeHash(address)).toOpenArray)
proc contractCollision*(db: AccountStateDB, address: EthAddress): bool {.inline.} =
db.getNonce(address) != 0 or db.getCodeHash(address) != EMPTY_SHA3
db.getNonce(address) != 0 or
db.getCodeHash(address) != EMPTY_SHA3 or
db.getStorageRoot(address) != EMPTY_ROOT_HASH
proc dumpAccount*(db: AccountStateDB, addressS: string): string =
let address = addressS.parseAddress

@ -1 +1 @@
Subproject commit 5bf1fff257c0662bc526c27d7546d470025b3239
Subproject commit faf33b471465d3c6cdc3d04fbd690895f78d33f2

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2018-2023 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

View File

@ -283,5 +283,27 @@ proc stateDBMain*() =
check ac.vts(0xcc, 7, 88) == false
check ac.vts(0xdd, 2, 66) == false
test "accounts cache contractCollision":
# use previous hash
var ac = init(AccountsCache, acDB, emptyRlpHash, true)
let addr2 = initAddr(2)
check ac.contractCollision(addr2) == false
ac.setStorage(addr2, 1.u256, 1.u256)
check ac.contractCollision(addr2) == false
ac.persist()
check ac.contractCollision(addr2) == true
let addr3 = initAddr(3)
check ac.contractCollision(addr3) == false
ac.setCode(addr3, @[0xaa.byte, 0xbb])
check ac.contractCollision(addr3) == true
let addr4 = initAddr(4)
check ac.contractCollision(addr4) == false
ac.setNonce(addr4, 1)
check ac.contractCollision(addr4) == true
when isMainModule:
stateDBMain()