From 400ac83aa0b112cc0a03df13c93d3108f37985b1 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Mon, 17 Dec 2018 13:36:17 -0600 Subject: [PATCH] BLSVerify > bls_verify --- beacon_chain/spec/beaconstate.nim | 6 +++--- beacon_chain/spec/crypto.nim | 6 ++---- beacon_chain/state_transition.nim | 12 ++++++------ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/beacon_chain/spec/beaconstate.nim b/beacon_chain/spec/beaconstate.nim index ded145658..2e55a04da 100644 --- a/beacon_chain/spec/beaconstate.nim +++ b/beacon_chain/spec/beaconstate.nim @@ -18,7 +18,7 @@ func process_deposit(state: var BeaconState, randao_commitment: Eth2Digest): Uint24 = ## Process a deposit from Ethereum 1.0. let msg = hash_tree_root((pubkey, withdrawal_credentials, randao_commitment)) - assert BLSVerify( + assert bls_verify( pubkey, msg, proof_of_possession, get_domain(state.fork_data, state.slot, DOMAIN_DEPOSIT)) @@ -326,13 +326,13 @@ proc checkAttestation*(state: BeaconState, attestation: Attestation): bool = let participants = get_attestation_participants( state, attestation.data, attestation.participation_bitfield) - group_public_key = BLSAddPubkeys(mapIt( + group_public_key = bls_aggregate_pubkeys(mapIt( participants, state.validator_registry[it].pubkey)) # Verify that aggregate_signature verifies using the group pubkey. let msg = hash_tree_root(attestation.data) - if not BLSVerify( + if not bls_verify( group_public_key, @msg & @[0'u8], attestation.aggregate_signature, get_domain(state.fork_data, attestation.data.slot, DOMAIN_ATTESTATION) ): diff --git a/beacon_chain/spec/crypto.nim b/beacon_chain/spec/crypto.nim index 1420ed506..8fdf65851 100644 --- a/beacon_chain/spec/crypto.nim +++ b/beacon_chain/spec/crypto.nim @@ -23,9 +23,7 @@ template hash*(k: ValidatorPubKey|ValidatorPrivKey): Hash = func pubKey*(pk: ValidatorPrivKey): ValidatorPubKey = fromSigKey(pk) -func BLSAddPubkeys*(keys: openArray[ValidatorPubKey]): ValidatorPubKey = - # name from spec! - +func bls_aggregate_pubkeys*(keys: openArray[ValidatorPubKey]): ValidatorPubKey = var empty = false for key in keys: if empty: @@ -34,7 +32,7 @@ func BLSAddPubkeys*(keys: openArray[ValidatorPubKey]): ValidatorPubKey = else: result.combine(key) -func BLSVerify*( +func bls_verify*( pubkey: ValidatorPubKey, msg: openArray[byte], sig: ValidatorSig, domain: uint64): bool = # name from spec! diff --git a/beacon_chain/state_transition.nim b/beacon_chain/state_transition.nim index deb078ef4..b4b9051c4 100644 --- a/beacon_chain/state_transition.nim +++ b/beacon_chain/state_transition.nim @@ -59,7 +59,7 @@ func verifyProposerSignature(state: BeaconState, blck: BeaconBlock): bool = let proposer_index = get_beacon_proposer_index(state, state.slot) - BLSVerify( + bls_verify( state.validator_registry[proposer_index].pubkey, proposal_hash, blck.signature, get_domain(state.fork_data, state.slot, DOMAIN_PROPOSAL)) @@ -119,7 +119,7 @@ proc processProposerSlashings(state: var BeaconState, blck: BeaconBlock): bool = for proposer_slashing in blck.body.proposer_slashings: let proposer = addr state.validator_registry[proposer_slashing.proposer_index] - if not BLSVerify( + if not bls_verify( proposer.pubkey, hash_tree_root(proposer_slashing.proposal_data_1), proposer_slashing.proposal_signature_1, @@ -128,7 +128,7 @@ proc processProposerSlashings(state: var BeaconState, blck: BeaconBlock): bool = DOMAIN_PROPOSAL)): warn("PropSlash: invalid signature 1") return false - if not BLSVerify( + if not bls_verify( proposer.pubkey, hash_tree_root(proposer_slashing.proposal_data_2), proposer_slashing.proposal_signature_2, @@ -168,9 +168,9 @@ func verify_slashable_vote_data(state: BeaconState, vote_data: SlashableVoteData return false let pubs = [ - BLSAddPubkeys(mapIt(vote_data.aggregate_signature_poc_0_indices, + bls_aggregate_pubkeys(mapIt(vote_data.aggregate_signature_poc_0_indices, state.validator_registry[it].pubkey)), - BLSAddPubkeys(mapIt(vote_data.aggregate_signature_poc_1_indices, + bls_aggregate_pubkeys(mapIt(vote_data.aggregate_signature_poc_1_indices, state.validator_registry[it].pubkey))] # TODO @@ -262,7 +262,7 @@ proc processExits(state: var BeaconState, blck: BeaconBlock): bool = for exit in blck.body.exits: let validator = state.validator_registry[exit.validator_index] - if not BLSVerify( + if not bls_verify( validator.pubkey, ZERO_HASH.data, exit.signature, get_domain(state.fork_data, exit.slot, DOMAIN_EXIT)): warn("Exit: invalid signature")