Skip to content

Commit

Permalink
fix #944
Browse files Browse the repository at this point in the history
  • Loading branch information
tersec committed Apr 30, 2020
1 parent 784c5e3 commit c78f87e
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions beacon_chain/state_transition.nim
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ proc state_transition*(
# the changes in case of failure (look out for `var BeaconState` and
# bool return values...)
doAssert not rollback.isNil, "use noRollback if it's ok to mess up state"

if skipBLSValidation notin flags and
not verify_block_signature(state.data, signedBlock):
# No need to roll back because no change occurred.
return false

# These should never fail.
process_slots(state, signedBlock.message.slot)

Expand All @@ -211,22 +217,19 @@ proc state_transition*(
# that the block is sane.
# TODO what should happen if block processing fails?
# https://github.com/ethereum/eth2.0-specs/issues/293
if skipBLSValidation in flags or
verify_block_signature(state.data, signedBlock):

var per_epoch_cache = get_empty_per_epoch_cache()
if processBlock(state.data, signedBlock.message, flags, per_epoch_cache):
if skipStateRootValidation in flags or verifyStateRoot(state.data, signedBlock.message):
# State root is what it should be - we're done!

# TODO when creating a new block, state_root is not yet set.. comparing
# with zero hash here is a bit fragile however, but this whole thing
# should go away with proper hash caching
state.root =
if signedBlock.message.state_root == Eth2Digest(): hash_tree_root(state.data)
else: signedBlock.message.state_root

return true
var per_epoch_cache = get_empty_per_epoch_cache()
if processBlock(state.data, signedBlock.message, flags, per_epoch_cache):
if skipStateRootValidation in flags or verifyStateRoot(state.data, signedBlock.message):
# State root is what it should be - we're done!

# TODO when creating a new block, state_root is not yet set.. comparing
# with zero hash here is a bit fragile however, but this whole thing
# should go away with proper hash caching
state.root =
if signedBlock.message.state_root == Eth2Digest(): hash_tree_root(state.data)
else: signedBlock.message.state_root

return true

# Block processing failed, roll back changes
rollback(state)
Expand Down

0 comments on commit c78f87e

Please sign in to comment.