Skip to content

Commit 8fe1c23

Browse files
fix(fw,tests): Replace ethereum.base_types with ethereum-types, replace ethereum.crypto.hash (#850)
* feat(all): Use `ethereum-types` * refactor(fw): Replace `ethereum.crypto.hash` usages * refactor(tests): Replace `ethereum.crypto.hash` usages * docs: changelog * fix(uv): Update lock * chore(ci): bump uv version * chore(tox): configure tox to respect uv.lock Added in tox-uv 1.12.0: https://github.com/tox-dev/tox-uv/releases/tag/1.12.0 * fix(github): Disable 3.10 tox * fix(github): Bump to `ubuntu-latest` --------- Co-authored-by: danceratopz <[email protected]>
1 parent 6ae70a7 commit 8fe1c23

File tree

21 files changed

+109
-78
lines changed

21 files changed

+109
-78
lines changed

.github/actions/setup-uv/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ runs:
66
- name: Install UV
77
shell: bash
88
run: |
9-
UV_VERSION="0.4.2"
9+
UV_VERSION="0.4.17"
1010
echo "Installing UV version $UV_VERSION..."
1111
curl -LsSf https://astral.sh/uv/${UV_VERSION}/install.sh | sh

.github/workflows/tox_verify.yaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@ jobs:
88
strategy:
99
matrix:
1010
include:
11-
- os: ubuntu-24.04
12-
python: "3.10"
13-
evm-type: "stable"
14-
tox-cmd: "uvx --with=tox-uv tox" # run-parallel --parallel-no-spinner" # TODO: disable parallelisation for uv testing
15-
- os: ubuntu-24.04
11+
# Temporarily disable
12+
# - os: ubuntu-latest
13+
# python: "3.10"
14+
# evm-type: "stable"
15+
# tox-cmd: "uvx --with=tox-uv tox" # run-parallel --parallel-no-spinner" # TODO: disable parallelisation for uv testing
16+
- os: ubuntu-latest
1617
python: "3.12"
1718
evm-type: "stable"
1819
tox-cmd: "uvx --with=tox-uv tox" # run-parallel --parallel-no-spinner"
1920
# Disabled due to unavailable evm implementation for devnet-1
20-
# - os: ubuntu-24.04
21+
# - os: ubuntu-latest
2122
# python: '3.11'
2223
# evm-type: 'develop'
2324
# tox-cmd: 'tox -e tests-develop'
2425
# Disabled to not be gated by evmone implementation
25-
# - os: ubuntu-24.04
26+
# - os: ubuntu-latest
2627
# python: '3.11'
2728
# evm-type: 'eip7692'
2829
# tox-cmd: 'tox -e tests-eip7692'

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Test fixtures for use by clients are available for each release on the [Github r
4242
- 🐞 Fix `Conditional` code generator in EOF mode ([#821](https://github.com/ethereum/execution-spec-tests/pull/821))
4343
- 🔀 `ethereum_test_rpc` library has been created with what was previously `ethereum_test_tools.rpc` ([#822](https://github.com/ethereum/execution-spec-tests/pull/822))
4444
- ✨ Add `Wei` type to `ethereum_test_base_types` which allows parsing wei amounts from strings like "1 ether", "1000 wei", "10**2 gwei", etc ([#825](https://github.com/ethereum/execution-spec-tests/pull/825))
45+
- 🔀 Replace `ethereum.base_types` with `ethereum-types` ([#850](https://github.com/ethereum/execution-spec-tests/pull/850))
4546

4647
### 🔧 EVM Tools
4748

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dependencies = [
3939
"rich>=13.7.0,<14",
4040
"solc-select>=1.0.4,<2",
4141
"filelock>=3.15.1,<4",
42+
"ethereum-types>=0.2.1,<0.3",
4243
]
4344

4445
[project.urls]

src/ethereum_test_base_types/base_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,12 @@ def or_none(cls, input: "Bytes | BytesConvertible | None") -> "Bytes | None":
197197
return input
198198
return cls(input)
199199

200-
def keccak256(self) -> "Bytes":
200+
def keccak256(self) -> "Hash":
201201
"""
202202
Return the keccak256 hash of the opcode byte representation.
203203
"""
204204
k = keccak.new(digest_bits=256)
205-
return Bytes(k.update(bytes(self)).digest())
205+
return Hash(k.update(bytes(self)).digest())
206206

207207

208208
S = TypeVar("S", bound="FixedSizeHexNumber")

src/ethereum_test_fixtures/blockchain.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from typing import Annotated, Any, ClassVar, List, Literal, Tuple, Union, get_args, get_type_hints
77

88
from ethereum import rlp as eth_rlp
9-
from ethereum.base_types import Uint
10-
from ethereum.crypto.hash import keccak256
9+
from ethereum_types.numeric import Uint
1110
from pydantic import AliasChoices, Field, PlainSerializer, computed_field
1211

1312
from ethereum_test_base_types import (
@@ -182,7 +181,7 @@ def block_hash(self) -> Hash:
182181
"""
183182
Compute the RLP of the header
184183
"""
185-
return Hash(keccak256(self.rlp))
184+
return self.rlp.keccak256()
186185

187186

188187
class FixtureExecutionPayload(CamelModel):

src/ethereum_test_fixtures/tests/test_blockchain.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,7 @@
620620
"excessBlobGas": hex(18),
621621
"blockHash": "0xd90115b7fde329f64335763a446af150ab67e639281dccdb07a007d18bb80211",
622622
"transactions": [
623-
"0x"
624-
+ Transaction(
623+
Transaction(
625624
to=0x1234,
626625
data=b"\x01\x00",
627626
access_list=[
@@ -735,8 +734,7 @@
735734
"0x8eca4747db6a4b272018f2850e4208b863989ce9971bb1907467ae2204950695"
736735
),
737736
"transactions": [
738-
"0x"
739-
+ Transaction(
737+
Transaction(
740738
to=0x1234,
741739
data=b"\x01\x00",
742740
access_list=[
@@ -914,8 +912,7 @@
914912
"0x78a4bf2520248e0b403d343c32b6746a43da1ebcf3cc8de14b959bc9f461fe76"
915913
),
916914
"transactions": [
917-
"0x"
918-
+ Transaction(
915+
Transaction(
919916
to=0x1234,
920917
data=b"\x01\x00",
921918
access_list=[
@@ -1082,8 +1079,7 @@ def test_json_deserialization(
10821079
"blockHash": "0xd90115b7fde329f64335763a446af1"
10831080
"50ab67e639281dccdb07a007d18bb80211",
10841081
"transactions": [
1085-
"0x"
1086-
+ Transaction(
1082+
Transaction(
10871083
to=0x1234,
10881084
data=b"\x01\x00",
10891085
access_list=[
@@ -1193,8 +1189,7 @@ def test_json_deserialization(
11931189
"blockHash": "0xd90115b7fde329f64335763a446af1"
11941190
"50ab67e639281dccdb07a007d18bb80211",
11951191
"transactions": [
1196-
"0x"
1197-
+ Transaction(
1192+
Transaction(
11981193
to=0x1234,
11991194
data=b"\x01\x00",
12001195
access_list=[

src/ethereum_test_tools/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
copy_opcode_cost,
5757
cost_memory_bytes,
5858
eip_2028_transaction_data_cost,
59+
keccak256,
5960
)
6061
from ethereum_test_vm import (
6162
Bytecode,
@@ -151,5 +152,6 @@
151152
"eip_2028_transaction_data_cost",
152153
"eip_2028_transaction_data_cost",
153154
"extend_with_defaults",
155+
"keccak256",
154156
"vm",
155157
)

src/ethereum_test_types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
Transaction,
3030
Withdrawal,
3131
WithdrawalRequest,
32+
keccak256,
3233
)
3334

3435
__all__ = (
@@ -64,5 +65,6 @@
6465
"copy_opcode_cost",
6566
"cost_memory_bytes",
6667
"eip_2028_transaction_data_cost",
68+
"keccak256",
6769
"to_json",
6870
)

src/ethereum_test_types/helpers.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from dataclasses import MISSING, dataclass, fields
66
from typing import List, SupportsBytes
77

8-
from ethereum.crypto.hash import keccak256
98
from ethereum.rlp import encode
109

1110
from ethereum_test_base_types.base_types import Address, Bytes, Hash
@@ -48,7 +47,7 @@ def compute_create_address(
4847
if nonce is None:
4948
nonce = 0
5049
nonce_bytes = bytes() if nonce == 0 else nonce.to_bytes(length=1, byteorder="big")
51-
hash = keccak256(encode([address, nonce_bytes]))
50+
hash = Bytes(encode([address, nonce_bytes])).keccak256()
5251
return Address(hash[-20:])
5352
if opcode == Op.CREATE2:
5453
return compute_create2_address(address, salt, initcode)
@@ -62,7 +61,7 @@ def compute_create2_address(
6261
Compute address of the resulting contract created using the `CREATE2`
6362
opcode.
6463
"""
65-
hash = keccak256(b"\xff" + Address(address) + Hash(salt) + keccak256(Bytes(initcode)))
64+
hash = Bytes(b"\xff" + Address(address) + Hash(salt) + Bytes(initcode).keccak256()).keccak256()
6665
return Address(hash[-20:])
6766

6867

@@ -100,7 +99,9 @@ def compute_eofcreate_address(
10099
"""
101100
Compute address of the resulting contract created using the `EOFCREATE` opcode.
102101
"""
103-
hash = keccak256(b"\xff" + Address(address) + Hash(salt) + keccak256(Bytes(init_container)))
102+
hash = Bytes(
103+
b"\xff" + Address(address) + Hash(salt) + Bytes(init_container).keccak256()
104+
).keccak256()
104105
return Address(hash[-20:])
105106

106107

0 commit comments

Comments
 (0)