Add `process_shard_block` verification

This commit is contained in:
Hsiao-Wei Wang 2020-06-24 18:18:50 +08:00
parent 4a46fb2a8a
commit 661959c13e
No known key found for this signature in database
GPG Key ID: 95B070122902DEA4
2 changed files with 20 additions and 9 deletions

View File

@ -92,11 +92,8 @@ def process_shard_block(shard_state: ShardState,
prev_gasprice = shard_state.gasprice
shard_block_length = len(block.body)
shard_state.gasprice = compute_updated_gasprice(prev_gasprice, uint64(shard_block_length))
if shard_block_length == 0:
latest_block_root = shard_state.latest_block_root
else:
latest_block_root = hash_tree_root(block)
shard_state.latest_block_root = latest_block_root
if shard_block_length != 0:
shard_state.latest_block_root = hash_tree_root(block)
```
## Fraud proofs

View File

@ -16,7 +16,8 @@ from eth2spec.test.helpers.state import transition_to_valid_shard_slot
def run_shard_blocks(spec, shard_state, signed_shard_block,
beacon_parent_state,
validate=True, valid=True):
yield 'pre', shard_state.copy()
pre_shard_state = shard_state.copy()
yield 'pre', pre_shard_state
yield 'signed_shard_block', signed_shard_block
yield 'validate', validate
yield 'beacon_parent_state', beacon_parent_state
@ -29,10 +30,23 @@ def run_shard_blocks(spec, shard_state, signed_shard_block,
shard_state, signed_shard_block, validate=validate, beacon_parent_state=beacon_parent_state)
)
yield 'post', None
return
spec.shard_state_transition(shard_state, signed_shard_block,
validate=validate, beacon_parent_state=beacon_parent_state)
yield 'post', shard_state
# Verify `process_shard_block`
block = signed_shard_block.message
assert shard_state.slot == block.slot
shard_block_length = len(block.body)
assert shard_state.gasprice == spec.compute_updated_gasprice(pre_shard_state.gasprice, shard_block_length)
if shard_block_length != 0:
shard_state.latest_block_root == block.hash_tree_root()
else:
spec.shard_state_transition(shard_state, signed_shard_block,
validate=validate, beacon_parent_state=beacon_parent_state)
yield 'post', shard_state
shard_state.latest_block_root == pre_shard_state.latest_block_root
@with_all_phases_except([PHASE0])