From 124ec4b7376a6174a4211bd34691b418a78ee11a Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Tue, 1 Sep 2020 09:49:55 +0200 Subject: [PATCH] perform slashing check before mutation (#1594) avoid copy of validator as well --- beacon_chain/spec/state_transition_block.nim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index bedf2a2bb..cee63e98c 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -62,6 +62,10 @@ func process_block_header*( if not (blck.parent_root == hash_tree_root(state.latest_block_header)): return err("process_block_header: previous block root mismatch") + # Verify proposer is not slashed + if state.validators[proposer_index.get].slashed: + return err("process_block_header: proposer slashed") + # Cache current block as the new latest block state.latest_block_header = BeaconBlockHeader( slot: blck.slot, @@ -71,11 +75,6 @@ func process_block_header*( body_root: hash_tree_root(blck.body), ) - # Verify proposer is not slashed - let proposer = state.validators[proposer_index.get] - if proposer.slashed: - return err("process_block_header: proposer slashed") - ok() func `xor`[T: array](a, b: T): T =