Skip to content

Commit

Permalink
tools: add txs root calculation (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz authored Jan 5, 2024
1 parent f71a615 commit 7306261
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Test fixtures for use by clients are available for each release on the [Github r
- ✨ Add a `--single-fixture-per-file` flag to generate one fixture JSON file per test case ([#331](https://github.com/ethereum/execution-spec-tests/pull/331)).
- 🔀 Rename test fixtures names to match the corresponding pytest node ID as generated using `fill` ([#342](https://github.com/ethereum/execution-spec-tests/pull/342)).
- 💥 Replace "=" with "_" in pytest node ids and test fixture names ([#342](https://github.com/ethereum/execution-spec-tests/pull/342)).
- 🔀 Locally calculate the transactions list's root instead of using the one returned by t8n when producing BlockchainTests ([#353](https://github.com/ethereum/execution-spec-tests/pull/353))
- ✨ Fork objects used to write tests can now be compared using the `>`, `>=`, `<`, `<=` operators, to check for a fork being newer than, newer than or equal, older than, older than or equal, respectively when compared against other fork ([#367](https://github.com/ethereum/execution-spec-tests/pull/367))
- 🐞 Storage type iterator is now fixed ([#369](https://github.com/ethereum/execution-spec-tests/pull/369))

Expand Down
2 changes: 2 additions & 0 deletions src/ethereum_test_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
to_address,
to_hash,
to_hash_bytes,
transaction_list_root,
)
from .filling.fill import fill_test
from .reference_spec import ReferenceSpec, ReferenceSpecTypes
Expand Down Expand Up @@ -111,4 +112,5 @@
"to_address",
"to_hash_bytes",
"to_hash",
"transaction_list_root",
)
2 changes: 2 additions & 0 deletions src/ethereum_test_tools/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
serialize_transactions,
str_or_none,
to_json,
transaction_list_root,
withdrawals_root,
)

Expand Down Expand Up @@ -106,5 +107,6 @@
"to_hash_bytes",
"to_hash",
"to_json",
"transaction_list_root",
"withdrawals_root",
)
10 changes: 10 additions & 0 deletions src/ethereum_test_tools/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,16 @@ def with_signature_and_sender(self) -> "Transaction":
return tx


def transaction_list_root(input_txs: List[Transaction] | None) -> Hash:
"""
Returns the transactions root of a list of transactions.
"""
t = HexaryTrie(db={})
for i, tx in enumerate(input_txs or []):
t.set(eth_rlp.encode(Uint(i)), tx.serialized_bytes())
return Hash(t.root_hash)


def transaction_list_to_serializable_list(input_txs: List[Transaction] | None) -> List[Any]:
"""
Returns the transaction list as a list of serializable objects.
Expand Down
4 changes: 4 additions & 0 deletions src/ethereum_test_tools/spec/blockchain_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
ZeroPaddedHexNumber,
alloc_to_accounts,
to_json,
transaction_list_root,
withdrawals_root,
)
from ..common.constants import EmptyOmmersRoot
Expand Down Expand Up @@ -184,6 +185,9 @@ def generate_block_data(
environment=env,
)

# Update the transactions root to the one calculated locally.
header.transactions_root = transaction_list_root(txs)

if block.header_verify is not None:
# Verify the header after transition tool processing.
header.verify(block.header_verify)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"extraData": "0x",
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": "0x29f",
"blockHash": "0x6504f75aa7b88dd9e059088d2db4d911934a5c0e3d076a48f6aeef9129df1472",
"blockHash": "0xeaa67ef33964d925aabc53e217e3f5f143615723970bfa07b80c46ef946ca293",
"transactions": [
"0x02f86901048203e88203e8830f424094cccccccccccccccccccccccccccccccccccccccc80820301c001a0720e2870881f8b0e285b7ec02c169f1165847bcb5f36ea5f33f3db6079854f63a04448266b715d7d99acd1e31dcab50d7119faa620d44c69b3f64f97d636634169",
"0x02f86a0105830186a08203e8830f424094cccccccccccccccccccccccccccccccccccccccd80820302c080a06c7fb2be7e001a210d72480522b9ebecade52d721360ce5242e34a6c05a02715a01220e3cb7418cd6294443b38d05f5ed9f2967b182d25c784e11e7863454b8f9b"
Expand Down Expand Up @@ -134,7 +134,7 @@
"extraData": "0x",
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": "0x24c",
"blockHash": "0xa8eec4a7460bdc0d813ab931562ca3a3b4e25c4482b9039003fdb293c3b05c96",
"blockHash": "0xa8b4cee5dcb437faf9d815cbe99986f9000e32cf5ea86613b944ac285cac0187",
"transactions": [
"0x02f86901078203e88203e8830f424094cccccccccccccccccccccccccccccccccccccccc80820401c001a0113c54f83e1b1e5c689ba86d288ec0ce2877f350b71821c4c7a3f7073b46602ca0548848e711b86ceeb657fd0a0bf44b792f6665ed18ec8a04f498471e811f8f97",
"0x02f86a0108830186a08203e8830f424094cccccccccccccccccccccccccccccccccccccccd80820402c001a0ebc8ad530ec3d510998aa2485763fcd1c6958c900c8d8ae6eaf86e1eddde8b23a0341e4a021f7b77da28d853c07d11253b92331ab640ad3f28f5d7b2cdbc7ceca7"
Expand Down Expand Up @@ -384,7 +384,7 @@
"extraData": "0x",
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": "0x29f",
"blockHash": "0xec8258ae1312e560e07e7d0fd208237e515c3e7d709f92fdc7a5b7316da25bdc",
"blockHash": "0x5c16738a8a828e396bc356b54716694ac63cce50e27c4cb270727af80b6a6a8a",
"transactions": [
"0x02f86901048203e88203e8830f424094cccccccccccccccccccccccccccccccccccccccc80820301c001a0720e2870881f8b0e285b7ec02c169f1165847bcb5f36ea5f33f3db6079854f63a04448266b715d7d99acd1e31dcab50d7119faa620d44c69b3f64f97d636634169",
"0x02f86a0105830186a08203e8830f424094cccccccccccccccccccccccccccccccccccccccd80820302c080a06c7fb2be7e001a210d72480522b9ebecade52d721360ce5242e34a6c05a02715a01220e3cb7418cd6294443b38d05f5ed9f2967b182d25c784e11e7863454b8f9b"
Expand Down Expand Up @@ -433,7 +433,7 @@
"extraData": "0x",
"prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": "0x24c",
"blockHash": "0x30c73027954c5b8e8d633775e6cf4f1362fb15bf7d41be2424d757d2cc9d5219",
"blockHash": "0x1498909af4d98e8ad23020f9a8055ce5ec7cc6264ca84c710a8bc2a93cffeffc",
"transactions": [
"0x02f86901078203e88203e8830f424094cccccccccccccccccccccccccccccccccccccccc80820401c001a0113c54f83e1b1e5c689ba86d288ec0ce2877f350b71821c4c7a3f7073b46602ca0548848e711b86ceeb657fd0a0bf44b792f6665ed18ec8a04f498471e811f8f97",
"0x02f86a0108830186a08203e8830f424094cccccccccccccccccccccccccccccccccccccccd80820402c001a0ebc8ad530ec3d510998aa2485763fcd1c6958c900c8d8ae6eaf86e1eddde8b23a0341e4a021f7b77da28d853c07d11253b92331ab640ad3f28f5d7b2cdbc7ceca7"
Expand Down Expand Up @@ -597,4 +597,4 @@
}
}
}
}
}
2 changes: 2 additions & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ big0
big1
blockchain
BlockchainTest
BlockchainTests
BlockchainTestFiller
blockhash
blocknum
Expand Down Expand Up @@ -229,6 +230,7 @@ squidfunk
src
stackoverflow
StateTest
StateTests
StateTestFiller
staticcalled
stExample
Expand Down

0 comments on commit 7306261

Please sign in to comment.