BLSVerify > bls_verify

This commit is contained in:
Jacek Sieka 2018-12-17 13:36:17 -06:00
parent 142aa8ca8e
commit 400ac83aa0
No known key found for this signature in database
GPG Key ID: 6299FEB3EB6FA465
3 changed files with 11 additions and 13 deletions

View File

@ -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)
):

View File

@ -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!

View File

@ -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")