Skip to content

Commit

Permalink
Address comments I made on PR ethereum#2080
Browse files Browse the repository at this point in the history
  • Loading branch information
fselmo committed Oct 20, 2022
1 parent 079881d commit 68be1f5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
3 changes: 2 additions & 1 deletion eth/vm/base.py
Expand Up @@ -581,9 +581,10 @@ def validate_block(self, block: BlockAPI) -> None:
)

if not self.chaindb.exists(block.header.state_root):
# If not in the db, check if the current state root matches.
if not self.state.make_state_root() == block.header.state_root:
raise ValidationError(
"`state_root` was not found in the db.\n"
"`state_root` does not match or was not found in the db.\n"
f"- state_root: {block.header.state_root!r}"
)

Expand Down
39 changes: 13 additions & 26 deletions eth/vm/forks/paris/headers.py
Expand Up @@ -24,7 +24,9 @@ def _validate_and_return_paris_header_param(
actual: Any,
constant_value: Any,
) -> Any:
if actual and actual != constant_value:
# if a value is passed into `header_params`, validate it's correct; else, set to
# the defined EIP-3675 constant value for the `header_param`.
if actual is not None and actual != constant_value:
raise ValidationError(
f"Header param '{header_param}' must always be "
f"{constant_value}, got: {actual}"
Expand All @@ -38,33 +40,18 @@ def create_paris_header_from_parent(
parent_header: Optional[BlockHeaderAPI],
**header_params: Any,
) -> BlockHeaderAPI:
if parent_header is None:
if "mix_hash" not in header_params:
header_params["mix_hash"] = POST_MERGE_MIX_HASH
if "nonce" not in header_params:
header_params["nonce"] = POST_MERGE_NONCE
if "difficulty" not in header_params:
header_params["difficulty"] = POST_MERGE_DIFFICULTY
# `mix_hash` is not strictly validated; take the value from the `header_params`,
# if present; else, set to the EIP-3675-defined constant value.
header_params["mix_hash"] = header_params.get("mix_hash", POST_MERGE_MIX_HASH)

header_params["mix_hash"] = (
header_params["mix_hash"] if "mix_hash" in header_params
else parent_header.mix_hash
# for `difficulty` and `nonce`, if present in `header_params`, validate the value
# is the expected EIP-3675 value; else, set to the EIP-3675-defined constant value.
header_params["difficulty"] = _validate_and_return_paris_header_param(
"difficulty", header_params.get("difficulty"), POST_MERGE_DIFFICULTY
)
header_params["nonce"] = _validate_and_return_paris_header_param(
"nonce", header_params.get("nonce"), POST_MERGE_NONCE
)

if parent_header is not None:
if "difficulty" in header_params:
header_params["difficulty"] = _validate_and_return_paris_header_param(
"difficulty", header_params["difficulty"], POST_MERGE_DIFFICULTY
)
else:
header_params["difficulty"] = POST_MERGE_DIFFICULTY

if "nonce" in header_params:
header_params["nonce"] = _validate_and_return_paris_header_param(
"nonce", header_params["nonce"], POST_MERGE_NONCE
)
else:
header_params["nonce"] = POST_MERGE_NONCE

gray_glacier_validated_header = create_gray_glacier_header_from_parent(
compute_gray_glacier_difficulty, parent_header, **header_params
Expand Down
3 changes: 2 additions & 1 deletion tests/core/builder-tools/test_chain_construction.py
Expand Up @@ -31,7 +31,7 @@
from eth.vm.forks import (
FrontierVM,
HomesteadVM,
ParisVM, TangerineWhistleVM,
TangerineWhistleVM,
SpuriousDragonVM,
ByzantiumVM,
ConstantinopleVM,
Expand All @@ -42,6 +42,7 @@
LondonVM,
ArrowGlacierVM,
GrayGlacierVM,
ParisVM,
)


Expand Down
2 changes: 2 additions & 0 deletions tests/json-fixtures/blockchain/test_blockchain.py
Expand Up @@ -63,6 +63,7 @@
('GeneralStateTests/stCreate2/Create2Recursive.json', 'Create2Recursive_d0g0v0_Merge'), # noqa: E501
('GeneralStateTests/stCreate2/Create2Recursive.json', 'Create2Recursive_d0g1v0_Istanbul'), # noqa: E501
('GeneralStateTests/stCreate2/Create2Recursive.json', 'Create2Recursive_d0g1v0_Berlin'), # noqa: E501
('GeneralStateTests/stCreate2/Create2Recursive.json', 'Create2Recursive_d0g1v0_London'), # noqa: E501
('GeneralStateTests/stCreate2/Create2Recursive.json', 'Create2Recursive_d0g1v0_Merge'), # noqa: E501
('GeneralStateTests/stDelegatecallTestHomestead/Call1024BalanceTooLow.json', 'Call1024BalanceTooLow_d0g0v0_Istanbul'), # noqa: E501
('GeneralStateTests/stDelegatecallTestHomestead/Call1024PreCalls.json', 'Call1024PreCalls_d0g0v0_Istanbul'), # noqa: E501
Expand Down Expand Up @@ -272,6 +273,7 @@
('ValidBlocks/VMTests/vmPerformance/loop-exp-32b-100k.json', 'loop-exp-32b-100k_Merge'),
('ValidBlocks/VMTests/vmPerformance/loop-exp-nop-1M.json', 'loop-exp-nop-1M_Istanbul'),
('ValidBlocks/VMTests/vmPerformance/loop-exp-nop-1M.json', 'loop-exp-nop-1M_Berlin'),
('ValidBlocks/VMTests/vmPerformance/loop-exp-nop-1M.json', 'loop-exp-nop-1M_London'),
('ValidBlocks/VMTests/vmPerformance/loop-exp-nop-1M.json', 'loop-exp-nop-1M_Merge'),
('ValidBlocks/VMTests/vmPerformance/loop-mul.json', 'loop-mul_Istanbul'),
('ValidBlocks/VMTests/vmPerformance/loop-mul.json', 'loop-mul_Berlin'),
Expand Down

0 comments on commit 68be1f5

Please sign in to comment.