From 8a2baa7b260628d7a2fa841e877253ba6d303a96 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 22 Oct 2018 05:58:12 +1100 Subject: [PATCH] Move proof_of_possession into bls crate --- .../types/src/validator_registration.rs | 4 ---- beacon_chain/utils/bls/Cargo.toml | 1 + beacon_chain/utils/bls/src/lib.rs | 19 ++++++++++++++++ .../validator_induction/src/inductor.rs | 5 +++-- beacon_chain/validator_induction/src/lib.rs | 5 ----- .../src/proof_of_possession.rs | 22 ------------------- 6 files changed, 23 insertions(+), 33 deletions(-) delete mode 100644 beacon_chain/validator_induction/src/proof_of_possession.rs diff --git a/beacon_chain/types/src/validator_registration.rs b/beacon_chain/types/src/validator_registration.rs index 1ebb90eec..384f2dc72 100644 --- a/beacon_chain/types/src/validator_registration.rs +++ b/beacon_chain/types/src/validator_registration.rs @@ -18,7 +18,3 @@ pub struct ValidatorRegistration { pub randao_commitment: Hash256, pub proof_of_possession: Signature, } - -impl ValidatorRegistration { - pub fn random() -} diff --git a/beacon_chain/utils/bls/Cargo.toml b/beacon_chain/utils/bls/Cargo.toml index eef0ec0aa..1199efc15 100644 --- a/beacon_chain/utils/bls/Cargo.toml +++ b/beacon_chain/utils/bls/Cargo.toml @@ -5,3 +5,4 @@ authors = ["Paul Hauner "] [dependencies] bls-aggregates = { git = "https://github.com/sigp/signature-schemes" } +hashing = { path = "../hashing" } diff --git a/beacon_chain/utils/bls/src/lib.rs b/beacon_chain/utils/bls/src/lib.rs index ff9a0919a..0578eb095 100644 --- a/beacon_chain/utils/bls/src/lib.rs +++ b/beacon_chain/utils/bls/src/lib.rs @@ -1,4 +1,5 @@ extern crate bls_aggregates; +extern crate hashing; pub use self::bls_aggregates::AggregateSignature; pub use self::bls_aggregates::AggregatePublicKey; @@ -8,3 +9,21 @@ pub use self::bls_aggregates::PublicKey; pub use self::bls_aggregates::SecretKey; pub const BLS_AGG_SIG_BYTE_SIZE: usize = 97; + +use hashing::proof_of_possession_hash; + +/// For some signature and public key, ensure that the signature message was the public key and it +/// was signed by the secret key that corresponds to that public key. +pub fn verify_proof_of_possession(sig: &Signature, pubkey: &PublicKey) + -> bool +{ + let hash = proof_of_possession_hash(&pubkey.as_bytes()); + sig.verify_hashed(&hash, &pubkey) +} + +pub fn create_proof_of_possession(keypair: &Keypair) + -> Signature +{ + let hash = proof_of_possession_hash(&keypair.pk.as_bytes()); + Signature::new_hashed(&hash, &keypair.sk) +} diff --git a/beacon_chain/validator_induction/src/inductor.rs b/beacon_chain/validator_induction/src/inductor.rs index 75a32c2b5..e025d0d43 100644 --- a/beacon_chain/validator_induction/src/inductor.rs +++ b/beacon_chain/validator_induction/src/inductor.rs @@ -1,11 +1,12 @@ +use bls::{ + verify_proof_of_possession, +}; use types::{ ValidatorRecord, ValidatorStatus, ValidatorRegistration, }; -use super::proof_of_possession::verify_proof_of_possession; - /// The size of a validators deposit in GWei. pub const DEPOSIT_GWEI: u64 = 32_000_000_000; diff --git a/beacon_chain/validator_induction/src/lib.rs b/beacon_chain/validator_induction/src/lib.rs index f35548480..e1f5ef09d 100644 --- a/beacon_chain/validator_induction/src/lib.rs +++ b/beacon_chain/validator_induction/src/lib.rs @@ -3,13 +3,8 @@ extern crate hashing; extern crate types; mod inductor; -mod proof_of_possession; pub use inductor::{ ValidatorInductor, ValidatorInductionError, }; - -pub use proof_of_possession::{ - create_proof_of_possession, -}; diff --git a/beacon_chain/validator_induction/src/proof_of_possession.rs b/beacon_chain/validator_induction/src/proof_of_possession.rs deleted file mode 100644 index 391625e85..000000000 --- a/beacon_chain/validator_induction/src/proof_of_possession.rs +++ /dev/null @@ -1,22 +0,0 @@ -use bls::{ - Keypair, - PublicKey, - Signature, -}; -use hashing::proof_of_possession_hash; - -/// For some signature and public key, ensure that the signature message was the public key and it -/// was signed by the secret key that corresponds to that public key. -pub fn verify_proof_of_possession(sig: &Signature, pubkey: &PublicKey) - -> bool -{ - let hash = proof_of_possession_hash(&pubkey.as_bytes()); - sig.verify_hashed(&hash, &pubkey) -} - -pub fn create_proof_of_possession(keypair: &Keypair) - -> Signature -{ - let hash = proof_of_possession_hash(&keypair.pk.as_bytes()); - Signature::new_hashed(&hash, &keypair.sk) -}