From a327c8282068a39f131cd49eaf16bbc1581e14b3 Mon Sep 17 00:00:00 2001 From: tersec Date: Tue, 10 Mar 2020 15:56:08 +0000 Subject: [PATCH] Revert "finalizing state_transition (#792)" This reverts commit 91d75bdfdd239880bc1398547504e4d9043578f8. --- beacon_chain/block_pool.nim | 2 ++ beacon_chain/spec/helpers.nim | 2 +- beacon_chain/state_transition.nim | 25 ++----------------------- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/beacon_chain/block_pool.nim b/beacon_chain/block_pool.nim index fcb62258c..c3e5111a6 100644 --- a/beacon_chain/block_pool.nim +++ b/beacon_chain/block_pool.nim @@ -373,6 +373,7 @@ proc add*( # TODO if the block is from the future, we should not be resolving it (yet), # but maybe we should use it as a hint that our clock is wrong? updateStateData(pool, pool.tmpState, BlockSlot(blck: parent, slot: blck.slot - 1)) + if not state_transition(pool.tmpState.data, signedBlock, {}): # TODO find a better way to log all this block data notice "Invalid block", @@ -381,6 +382,7 @@ proc add*( cat = "filtering" return + # Careful, tmpState.data has been updated but not blck - we need to create # the BlockRef first! pool.tmpState.blck = pool.addResolvedBlock( diff --git a/beacon_chain/spec/helpers.nim b/beacon_chain/spec/helpers.nim index 87aa8d60a..c8d88b388 100644 --- a/beacon_chain/spec/helpers.nim +++ b/beacon_chain/spec/helpers.nim @@ -151,7 +151,7 @@ func compute_signing_root*(ssz_object: auto, domain: Domain): Eth2Digest = # object-domain tree. let domain_wrapped_object = SigningRoot( object_root: hash_tree_root(ssz_object), - domain: bytes_to_int(domain) + domain: domain ) hash_tree_root(domain_wrapped_object) diff --git a/beacon_chain/state_transition.nim b/beacon_chain/state_transition.nim index 75464a0af..1352ac08a 100644 --- a/beacon_chain/state_transition.nim +++ b/beacon_chain/state_transition.nim @@ -31,9 +31,9 @@ # now. import - collections/sets, chronicles, sets, options, + collections/sets, chronicles, sets, ./extras, ./ssz, metrics, - ./spec/[datatypes, crypto, digest, helpers, validator], + ./spec/[datatypes, digest, helpers, validator], ./spec/[state_transition_block, state_transition_epoch], ../nbench/bench_lab @@ -101,19 +101,6 @@ proc process_slots*(state: var BeaconState, slot: Slot) {.nbench.}= if is_epoch_transition: beacon_current_validators.set(get_epoch_validator_count(state)) -#https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#verify_block_signature -proc verify_block_signature*(state: var BeaconState, signedBlock: SignedBeaconBlock, stateCache: var StateCache): bool {.nbench.} = - let proposer = state.validators[get_beacon_proposer_index(state, stateCache).get] - let domain = get_domain(state, DOMAIN_BEACON_PROPOSER, compute_epoch_at_slot(signedBlock.message.slot)) - # TODO This will need to be changed for: - # ``` - # let signing_root = compute_signing_root(signedBlock.message,domain) - # return bls_verify(proposer.pubKey, signing_root.data, signedBlock.signature, domain) - # ``` - # when https://github.com/status-im/nim-beacon-chain/pull/780 is merged - return bls_verify(proposer.pubKey, hash_tree_root(signedBlock.message).data, signedBlock.signature, domain) - - # https://github.com/ethereum/eth2.0-specs/blob/v0.9.4/specs/core/0_beacon-chain.md#beacon-chain-state-transition-function proc verifyStateRoot(state: BeaconState, blck: BeaconBlock): bool = # This is inlined in state_transition(...) in spec. @@ -170,10 +157,6 @@ proc state_transition*( # https://github.com/ethereum/eth2.0-specs/issues/293 var per_epoch_cache = get_empty_per_epoch_cache() - if skipBLSValidation notin flags and not verify_block_signature(state, signedBlock, per_epoch_cache): - state = old_state - return false - if processBlock(state, signedBlock.message, flags, per_epoch_cache): # This is a bit awkward - at the end of processing we verify that the # state we arrive at is what the block producer thought it would be - @@ -241,10 +224,6 @@ proc state_transition*( process_slots(state, signedBlock.message.slot) var per_epoch_cache = get_empty_per_epoch_cache() - if skipBLSValidation notin flags and not verify_block_signature(state.data, signedBlock, per_epoch_cache): - state = old_state - return false - 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!