Skip to content

Commit

Permalink
Merge pull request #816 from ethereum/block-root-fix
Browse files Browse the repository at this point in the history
use signed_root for block id purposes in blocks/state
  • Loading branch information
djrtwo committed Mar 20, 2019
2 parents ab197d9 + c10384d commit bab36b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@ def get_temporary_block_header(block: BeaconBlock) -> BeaconBlockHeader:
previous_block_root=block.previous_block_root,
state_root=ZERO_HASH,
block_body_root=hash_tree_root(block.body),
signature=block.signature,
# signed_root(block) is used for block id purposes so signature is a stub
signature=EMPTY_SIGNATURE,
)
```

Expand Down Expand Up @@ -1689,7 +1690,7 @@ def cache_state(state: BeaconState) -> None:
state.latest_block_header.state_root = previous_slot_state_root

# store latest known block for previous slot
state.latest_block_roots[state.slot % SLOTS_PER_HISTORICAL_ROOT] = hash_tree_root(state.latest_block_header)
state.latest_block_roots[state.slot % SLOTS_PER_HISTORICAL_ROOT] = signed_root(state.latest_block_header)
```

### Per-epoch processing
Expand Down Expand Up @@ -2250,7 +2251,7 @@ def process_block_header(state: BeaconState, block: BeaconBlock) -> None:
# Verify that the slots match
assert block.slot == state.slot
# Verify that the parent matches
assert block.previous_block_root == hash_tree_root(state.latest_block_header)
assert block.previous_block_root == signed_root(state.latest_block_header)
# Save current block as the new latest block
state.latest_block_header = get_temporary_block_header(block)
# Verify proposer signature
Expand Down
2 changes: 1 addition & 1 deletion tests/phase0/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def build_empty_block_for_next_slot(state):
previous_block_header = deepcopy(state.latest_block_header)
if previous_block_header.state_root == spec.ZERO_HASH:
previous_block_header.state_root = state.hash_tree_root()
empty_block.previous_block_root = previous_block_header.hash_tree_root()
empty_block.previous_block_root = signed_root(previous_block_header)
return empty_block


Expand Down

0 comments on commit bab36b5

Please sign in to comment.