Skip to content

Commit 0ffff6c

Browse files
committed
Switch to ethereum rlp
1 parent 872bd2e commit 0ffff6c

File tree

136 files changed

+263
-1160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+263
-1160
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ install_requires =
116116
typing_extensions>=4
117117
py_ecc @ git+https://github.com/petertdavies/py_ecc.git@127184f4c57b1812da959586d0fe8f43bb1a2389
118118
ethereum-types>=0.2.1,<0.3
119+
ethereum-rlp>=0.1.1,<0.2
119120

120121
[options.package_data]
121122
ethereum =

src/ethereum/arrow_glacier/fork.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
from dataclasses import dataclass
1616
from typing import List, Optional, Set, Tuple, Union
1717

18+
from ethereum_rlp import rlp
1819
from ethereum_types.bytes import Bytes
1920
from ethereum_types.numeric import U64, U256, Uint
2021

2122
from ethereum.crypto.hash import Hash32, keccak256
2223
from ethereum.ethash import dataset_size, generate_cache, hashimoto_light
2324
from ethereum.exceptions import InvalidBlock, InvalidSenderError
2425

25-
from .. import rlp
2626
from . import vm
2727
from .blocks import Block, Header, Log, Receipt
2828
from .bloom import logs_bloom
@@ -351,7 +351,7 @@ def generate_header_hash_for_pow(header: Header) -> Hash32:
351351
header.base_fee_per_gas,
352352
)
353353

354-
return rlp.rlp_hash(header_data_without_pow_artefacts)
354+
return keccak256(rlp.encode(header_data_without_pow_artefacts))
355355

356356

357357
def validate_proof_of_work(header: Header) -> None:
@@ -650,8 +650,8 @@ def validate_ommers(
650650
chain :
651651
History and current state.
652652
"""
653-
block_hash = rlp.rlp_hash(block_header)
654-
if rlp.rlp_hash(ommers) != block_header.ommers_hash:
653+
block_hash = keccak256(rlp.encode(block_header))
654+
if keccak256(rlp.encode(ommers)) != block_header.ommers_hash:
655655
raise InvalidBlock
656656

657657
if len(ommers) == 0:
@@ -669,18 +669,19 @@ def validate_ommers(
669669
if len(ommers) > 2:
670670
raise InvalidBlock
671671

672-
ommers_hashes = [rlp.rlp_hash(ommer) for ommer in ommers]
672+
ommers_hashes = [keccak256(rlp.encode(ommer)) for ommer in ommers]
673673
if len(ommers_hashes) != len(set(ommers_hashes)):
674674
raise InvalidBlock
675675

676676
recent_canonical_blocks = chain.blocks[-(MAX_OMMER_DEPTH + Uint(1)) :]
677677
recent_canonical_block_hashes = {
678-
rlp.rlp_hash(block.header) for block in recent_canonical_blocks
678+
keccak256(rlp.encode(block.header))
679+
for block in recent_canonical_blocks
679680
}
680681
recent_ommers_hashes: Set[Hash32] = set()
681682
for block in recent_canonical_blocks:
682683
recent_ommers_hashes = recent_ommers_hashes.union(
683-
{rlp.rlp_hash(ommer) for ommer in block.ommers}
684+
{keccak256(rlp.encode(ommer)) for ommer in block.ommers}
684685
)
685686

686687
for ommer_index, ommer in enumerate(ommers):

src/ethereum/arrow_glacier/fork_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
from dataclasses import dataclass
1616

17+
from ethereum_rlp import rlp
1718
from ethereum_types.bytes import Bytes, Bytes20, Bytes256
1819
from ethereum_types.frozen import slotted_freezable
1920
from ethereum_types.numeric import U256, Uint
2021

21-
from .. import rlp
2222
from ..crypto.hash import Hash32, keccak256
2323

2424
Address = Bytes20

src/ethereum/arrow_glacier/transactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from dataclasses import dataclass
77
from typing import Tuple, Union
88

9+
from ethereum_rlp import rlp
910
from ethereum_types.bytes import Bytes, Bytes0, Bytes32
1011
from ethereum_types.frozen import slotted_freezable
1112
from ethereum_types.numeric import U64, U256, Uint
@@ -14,7 +15,6 @@
1415
from ethereum.crypto.hash import Hash32, keccak256
1516
from ethereum.exceptions import InvalidSignatureError
1617

17-
from .. import rlp
1818
from .exceptions import TransactionTypeError
1919
from .fork_types import Address
2020

src/ethereum/arrow_glacier/trie.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
Union,
2929
)
3030

31+
from ethereum_rlp import rlp
3132
from ethereum_types.bytes import Bytes
3233
from ethereum_types.frozen import slotted_freezable
3334
from ethereum_types.numeric import U256, Uint
@@ -36,7 +37,6 @@
3637
from ethereum.london import trie as previous_trie
3738
from ethereum.utils.hexadecimal import hex_to_bytes
3839

39-
from .. import rlp
4040
from .blocks import Receipt
4141
from .fork_types import Account, Address, Root, encode_account
4242
from .transactions import LegacyTransaction

src/ethereum/arrow_glacier/utils/address.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
"""
1515
from typing import Union
1616

17+
from ethereum_rlp import rlp
1718
from ethereum_types.bytes import Bytes32
1819
from ethereum_types.numeric import U256, Uint
1920

2021
from ethereum.crypto.hash import keccak256
2122
from ethereum.utils.byte import left_pad_zero_bytes
2223

23-
from ... import rlp
2424
from ..fork_types import Address
2525

2626

src/ethereum/berlin/fork.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
from dataclasses import dataclass
1616
from typing import List, Optional, Set, Tuple, Union
1717

18+
from ethereum_rlp import rlp
1819
from ethereum_types.bytes import Bytes
1920
from ethereum_types.numeric import U64, U256, Uint
2021

2122
from ethereum.crypto.hash import Hash32, keccak256
2223
from ethereum.ethash import dataset_size, generate_cache, hashimoto_light
2324
from ethereum.exceptions import InvalidBlock, InvalidSenderError
2425

25-
from .. import rlp
2626
from . import vm
2727
from .blocks import Block, Header, Log, Receipt
2828
from .bloom import logs_bloom
@@ -274,7 +274,7 @@ def generate_header_hash_for_pow(header: Header) -> Hash32:
274274
header.extra_data,
275275
)
276276

277-
return rlp.rlp_hash(header_data_without_pow_artefacts)
277+
return keccak256(rlp.encode(header_data_without_pow_artefacts))
278278

279279

280280
def validate_proof_of_work(header: Header) -> None:
@@ -544,8 +544,8 @@ def validate_ommers(
544544
chain :
545545
History and current state.
546546
"""
547-
block_hash = rlp.rlp_hash(block_header)
548-
if rlp.rlp_hash(ommers) != block_header.ommers_hash:
547+
block_hash = keccak256(rlp.encode(block_header))
548+
if keccak256(rlp.encode(ommers)) != block_header.ommers_hash:
549549
raise InvalidBlock
550550

551551
if len(ommers) == 0:
@@ -563,18 +563,19 @@ def validate_ommers(
563563
if len(ommers) > 2:
564564
raise InvalidBlock
565565

566-
ommers_hashes = [rlp.rlp_hash(ommer) for ommer in ommers]
566+
ommers_hashes = [keccak256(rlp.encode(ommer)) for ommer in ommers]
567567
if len(ommers_hashes) != len(set(ommers_hashes)):
568568
raise InvalidBlock
569569

570570
recent_canonical_blocks = chain.blocks[-(MAX_OMMER_DEPTH + Uint(1)) :]
571571
recent_canonical_block_hashes = {
572-
rlp.rlp_hash(block.header) for block in recent_canonical_blocks
572+
keccak256(rlp.encode(block.header))
573+
for block in recent_canonical_blocks
573574
}
574575
recent_ommers_hashes: Set[Hash32] = set()
575576
for block in recent_canonical_blocks:
576577
recent_ommers_hashes = recent_ommers_hashes.union(
577-
{rlp.rlp_hash(ommer) for ommer in block.ommers}
578+
{keccak256(rlp.encode(ommer)) for ommer in block.ommers}
578579
)
579580

580581
for ommer_index, ommer in enumerate(ommers):

src/ethereum/berlin/fork_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
from dataclasses import dataclass
1616

17+
from ethereum_rlp import rlp
1718
from ethereum_types.bytes import Bytes, Bytes20, Bytes256
1819
from ethereum_types.frozen import slotted_freezable
1920
from ethereum_types.numeric import U256, Uint
2021

21-
from .. import rlp
2222
from ..crypto.hash import Hash32, keccak256
2323

2424
Address = Bytes20

src/ethereum/berlin/transactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from dataclasses import dataclass
77
from typing import Tuple, Union
88

9+
from ethereum_rlp import rlp
910
from ethereum_types.bytes import Bytes, Bytes0, Bytes32
1011
from ethereum_types.frozen import slotted_freezable
1112
from ethereum_types.numeric import U64, U256, Uint
@@ -14,7 +15,6 @@
1415
from ethereum.crypto.hash import Hash32, keccak256
1516
from ethereum.exceptions import InvalidSignatureError
1617

17-
from .. import rlp
1818
from .exceptions import TransactionTypeError
1919
from .fork_types import Address
2020

src/ethereum/berlin/trie.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
Union,
2929
)
3030

31+
from ethereum_rlp import rlp
3132
from ethereum_types.bytes import Bytes
3233
from ethereum_types.frozen import slotted_freezable
3334
from ethereum_types.numeric import U256, Uint
@@ -36,7 +37,6 @@
3637
from ethereum.muir_glacier import trie as previous_trie
3738
from ethereum.utils.hexadecimal import hex_to_bytes
3839

39-
from .. import rlp
4040
from .blocks import Receipt
4141
from .fork_types import Account, Address, Root, encode_account
4242
from .transactions import LegacyTransaction

0 commit comments

Comments
 (0)