Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to ethereum-rlp #1034

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ install_requires =
typing_extensions>=4
py_ecc @ git+https://github.com/petertdavies/py_ecc.git@127184f4c57b1812da959586d0fe8f43bb1a2389
ethereum-types>=0.2.1,<0.3
ethereum-rlp>=0.1.1,<0.2

[options.package_data]
ethereum =
Expand Down
15 changes: 8 additions & 7 deletions src/ethereum/arrow_glacier/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
from dataclasses import dataclass
from typing import List, Optional, Set, Tuple, Union

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes
from ethereum_types.numeric import U64, U256, Uint

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

from .. import rlp
from . import vm
from .blocks import Block, Header, Log, Receipt
from .bloom import logs_bloom
Expand Down Expand Up @@ -351,7 +351,7 @@ def generate_header_hash_for_pow(header: Header) -> Hash32:
header.base_fee_per_gas,
)

return rlp.rlp_hash(header_data_without_pow_artefacts)
return keccak256(rlp.encode(header_data_without_pow_artefacts))


def validate_proof_of_work(header: Header) -> None:
Expand Down Expand Up @@ -650,8 +650,8 @@ def validate_ommers(
chain :
History and current state.
"""
block_hash = rlp.rlp_hash(block_header)
if rlp.rlp_hash(ommers) != block_header.ommers_hash:
block_hash = keccak256(rlp.encode(block_header))
if keccak256(rlp.encode(ommers)) != block_header.ommers_hash:
raise InvalidBlock

if len(ommers) == 0:
Expand All @@ -669,18 +669,19 @@ def validate_ommers(
if len(ommers) > 2:
raise InvalidBlock

ommers_hashes = [rlp.rlp_hash(ommer) for ommer in ommers]
ommers_hashes = [keccak256(rlp.encode(ommer)) for ommer in ommers]
if len(ommers_hashes) != len(set(ommers_hashes)):
raise InvalidBlock

recent_canonical_blocks = chain.blocks[-(MAX_OMMER_DEPTH + Uint(1)) :]
recent_canonical_block_hashes = {
rlp.rlp_hash(block.header) for block in recent_canonical_blocks
keccak256(rlp.encode(block.header))
for block in recent_canonical_blocks
}
recent_ommers_hashes: Set[Hash32] = set()
for block in recent_canonical_blocks:
recent_ommers_hashes = recent_ommers_hashes.union(
{rlp.rlp_hash(ommer) for ommer in block.ommers}
{keccak256(rlp.encode(ommer)) for ommer in block.ommers}
)

for ommer_index, ommer in enumerate(ommers):
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/arrow_glacier/fork_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

from dataclasses import dataclass

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes, Bytes20, Bytes256
from ethereum_types.frozen import slotted_freezable
from ethereum_types.numeric import U256, Uint

from .. import rlp
from ..crypto.hash import Hash32, keccak256

Address = Bytes20
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/arrow_glacier/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dataclasses import dataclass
from typing import Tuple, Union

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes, Bytes0, Bytes32
from ethereum_types.frozen import slotted_freezable
from ethereum_types.numeric import U64, U256, Uint
Expand All @@ -14,7 +15,6 @@
from ethereum.crypto.hash import Hash32, keccak256
from ethereum.exceptions import InvalidSignatureError

from .. import rlp
from .exceptions import TransactionTypeError
from .fork_types import Address

Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/arrow_glacier/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Union,
)

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes
from ethereum_types.frozen import slotted_freezable
from ethereum_types.numeric import U256, Uint
Expand All @@ -36,7 +37,6 @@
from ethereum.london import trie as previous_trie
from ethereum.utils.hexadecimal import hex_to_bytes

from .. import rlp
from .blocks import Receipt
from .fork_types import Account, Address, Root, encode_account
from .transactions import LegacyTransaction
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/arrow_glacier/utils/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"""
from typing import Union

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes32
from ethereum_types.numeric import U256, Uint

from ethereum.crypto.hash import keccak256
from ethereum.utils.byte import left_pad_zero_bytes

from ... import rlp
from ..fork_types import Address


Expand Down
15 changes: 8 additions & 7 deletions src/ethereum/berlin/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
from dataclasses import dataclass
from typing import List, Optional, Set, Tuple, Union

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes
from ethereum_types.numeric import U64, U256, Uint

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

from .. import rlp
from . import vm
from .blocks import Block, Header, Log, Receipt
from .bloom import logs_bloom
Expand Down Expand Up @@ -274,7 +274,7 @@ def generate_header_hash_for_pow(header: Header) -> Hash32:
header.extra_data,
)

return rlp.rlp_hash(header_data_without_pow_artefacts)
return keccak256(rlp.encode(header_data_without_pow_artefacts))


def validate_proof_of_work(header: Header) -> None:
Expand Down Expand Up @@ -544,8 +544,8 @@ def validate_ommers(
chain :
History and current state.
"""
block_hash = rlp.rlp_hash(block_header)
if rlp.rlp_hash(ommers) != block_header.ommers_hash:
block_hash = keccak256(rlp.encode(block_header))
if keccak256(rlp.encode(ommers)) != block_header.ommers_hash:
raise InvalidBlock

if len(ommers) == 0:
Expand All @@ -563,18 +563,19 @@ def validate_ommers(
if len(ommers) > 2:
raise InvalidBlock

ommers_hashes = [rlp.rlp_hash(ommer) for ommer in ommers]
ommers_hashes = [keccak256(rlp.encode(ommer)) for ommer in ommers]
if len(ommers_hashes) != len(set(ommers_hashes)):
raise InvalidBlock

recent_canonical_blocks = chain.blocks[-(MAX_OMMER_DEPTH + Uint(1)) :]
recent_canonical_block_hashes = {
rlp.rlp_hash(block.header) for block in recent_canonical_blocks
keccak256(rlp.encode(block.header))
for block in recent_canonical_blocks
}
recent_ommers_hashes: Set[Hash32] = set()
for block in recent_canonical_blocks:
recent_ommers_hashes = recent_ommers_hashes.union(
{rlp.rlp_hash(ommer) for ommer in block.ommers}
{keccak256(rlp.encode(ommer)) for ommer in block.ommers}
)

for ommer_index, ommer in enumerate(ommers):
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/berlin/fork_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

from dataclasses import dataclass

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes, Bytes20, Bytes256
from ethereum_types.frozen import slotted_freezable
from ethereum_types.numeric import U256, Uint

from .. import rlp
from ..crypto.hash import Hash32, keccak256

Address = Bytes20
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/berlin/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dataclasses import dataclass
from typing import Tuple, Union

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes, Bytes0, Bytes32
from ethereum_types.frozen import slotted_freezable
from ethereum_types.numeric import U64, U256, Uint
Expand All @@ -14,7 +15,6 @@
from ethereum.crypto.hash import Hash32, keccak256
from ethereum.exceptions import InvalidSignatureError

from .. import rlp
from .exceptions import TransactionTypeError
from .fork_types import Address

Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/berlin/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Union,
)

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes
from ethereum_types.frozen import slotted_freezable
from ethereum_types.numeric import U256, Uint
Expand All @@ -36,7 +37,6 @@
from ethereum.muir_glacier import trie as previous_trie
from ethereum.utils.hexadecimal import hex_to_bytes

from .. import rlp
from .blocks import Receipt
from .fork_types import Account, Address, Root, encode_account
from .transactions import LegacyTransaction
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/berlin/utils/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"""
from typing import Union

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes32
from ethereum_types.numeric import U256, Uint

from ethereum.crypto.hash import keccak256
from ethereum.utils.byte import left_pad_zero_bytes

from ... import rlp
from ..fork_types import Address


Expand Down
15 changes: 8 additions & 7 deletions src/ethereum/byzantium/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
from dataclasses import dataclass
from typing import List, Optional, Set, Tuple

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes
from ethereum_types.numeric import U64, U256, Uint

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

from .. import rlp
from . import vm
from .blocks import Block, Header, Log, Receipt
from .bloom import logs_bloom
Expand Down Expand Up @@ -270,7 +270,7 @@ def generate_header_hash_for_pow(header: Header) -> Hash32:
header.extra_data,
)

return rlp.rlp_hash(header_data_without_pow_artefacts)
return keccak256(rlp.encode(header_data_without_pow_artefacts))


def validate_proof_of_work(header: Header) -> None:
Expand Down Expand Up @@ -534,8 +534,8 @@ def validate_ommers(
chain :
History and current state.
"""
block_hash = rlp.rlp_hash(block_header)
if rlp.rlp_hash(ommers) != block_header.ommers_hash:
block_hash = keccak256(rlp.encode(block_header))
if keccak256(rlp.encode(ommers)) != block_header.ommers_hash:
raise InvalidBlock

if len(ommers) == 0:
Expand All @@ -553,18 +553,19 @@ def validate_ommers(
if len(ommers) > 2:
raise InvalidBlock

ommers_hashes = [rlp.rlp_hash(ommer) for ommer in ommers]
ommers_hashes = [keccak256(rlp.encode(ommer)) for ommer in ommers]
if len(ommers_hashes) != len(set(ommers_hashes)):
raise InvalidBlock

recent_canonical_blocks = chain.blocks[-(MAX_OMMER_DEPTH + Uint(1)) :]
recent_canonical_block_hashes = {
rlp.rlp_hash(block.header) for block in recent_canonical_blocks
keccak256(rlp.encode(block.header))
for block in recent_canonical_blocks
}
recent_ommers_hashes: Set[Hash32] = set()
for block in recent_canonical_blocks:
recent_ommers_hashes = recent_ommers_hashes.union(
{rlp.rlp_hash(ommer) for ommer in block.ommers}
{keccak256(rlp.encode(ommer)) for ommer in block.ommers}
)

for ommer_index, ommer in enumerate(ommers):
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/byzantium/fork_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

from dataclasses import dataclass

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes, Bytes20, Bytes256
from ethereum_types.frozen import slotted_freezable
from ethereum_types.numeric import U256, Uint

from .. import rlp
from ..crypto.hash import Hash32, keccak256

Address = Bytes20
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/byzantium/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dataclasses import dataclass
from typing import Union

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes, Bytes0
from ethereum_types.frozen import slotted_freezable
from ethereum_types.numeric import U64, U256, Uint
Expand All @@ -14,7 +15,6 @@
from ethereum.crypto.hash import Hash32, keccak256
from ethereum.exceptions import InvalidSignatureError

from .. import rlp
from .fork_types import Address

TX_BASE_COST = 21000
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/byzantium/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
Union,
)

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes
from ethereum_types.frozen import slotted_freezable
from ethereum_types.numeric import U256, Uint
Expand All @@ -36,7 +37,6 @@
from ethereum.spurious_dragon import trie as previous_trie
from ethereum.utils.hexadecimal import hex_to_bytes

from .. import rlp
from .blocks import Receipt
from .fork_types import Account, Address, Root, encode_account
from .transactions import Transaction
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/byzantium/utils/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"""
from typing import Union

from ethereum_rlp import rlp
from ethereum_types.numeric import U256, Uint

from ethereum.crypto.hash import keccak256
from ethereum.utils.byte import left_pad_zero_bytes

from ... import rlp
from ..fork_types import Address


Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/cancun/fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
from dataclasses import dataclass
from typing import List, Optional, Tuple, Union

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes, Bytes32
from ethereum_types.numeric import U64, U256, Uint

from ethereum.crypto.hash import Hash32, keccak256
from ethereum.exceptions import InvalidBlock, InvalidSenderError

from .. import rlp
from . import vm
from .blocks import Block, Header, Log, Receipt, Withdrawal
from .bloom import logs_bloom
Expand Down
2 changes: 1 addition & 1 deletion src/ethereum/cancun/fork_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

from dataclasses import dataclass

from ethereum_rlp import rlp
from ethereum_types.bytes import Bytes, Bytes20, Bytes256
from ethereum_types.frozen import slotted_freezable
from ethereum_types.numeric import U256, Uint

from .. import rlp
from ..crypto.hash import Hash32, keccak256

Address = Bytes20
Expand Down
Loading
Loading