Add new bls-aggregates crates
This commit is contained in:
parent
0b661c5b11
commit
67b11a394e
@ -7,7 +7,7 @@ authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
# TODO: remove "blake2" in favor of "blake2-rfc"
|
||||
blake2 = "^0.7.1"
|
||||
blake2-rfc = "0.2.18"
|
||||
bls = { git = "https://github.com/sigp/bls" }
|
||||
bls-aggregates = { git = "https://github.com/sigp/signature-schemes" }
|
||||
boolean-bitfield = { path = "boolean-bitfield" }
|
||||
bytes = ""
|
||||
crypto-mac = "^0.6.2"
|
||||
|
9
lighthouse/bls/mod.rs
Normal file
9
lighthouse/bls/mod.rs
Normal file
@ -0,0 +1,9 @@
|
||||
extern crate bls_aggregates;
|
||||
|
||||
pub use self::bls_aggregates::AggregateSignature;
|
||||
pub use self::bls_aggregates::AggregatePublicKey;
|
||||
pub use self::bls_aggregates::Signature;
|
||||
pub use self::bls_aggregates::Keypair;
|
||||
pub use self::bls_aggregates::PublicKey;
|
||||
|
||||
pub const BLS_AGG_SIG_BYTE_SIZE: usize = 97;
|
@ -2,6 +2,7 @@
|
||||
extern crate slog;
|
||||
extern crate slog_term;
|
||||
extern crate slog_async;
|
||||
extern crate ssz;
|
||||
extern crate clap;
|
||||
extern crate network_libp2p;
|
||||
extern crate futures;
|
||||
|
@ -1,5 +1,8 @@
|
||||
use super::utils::types::{ Hash256, Bitfield };
|
||||
use super::utils::bls::{ AggregateSignature };
|
||||
use super::bls::{
|
||||
AggregateSignature,
|
||||
BLS_AGG_SIG_BYTE_SIZE,
|
||||
};
|
||||
use super::ssz::{
|
||||
Encodable,
|
||||
Decodable,
|
||||
@ -16,7 +19,7 @@ pub const MIN_SSZ_ATTESTION_RECORD_LENGTH: usize = {
|
||||
5 + // attester_bitfield (assuming 1 byte of bitfield)
|
||||
8 + // justified_slot
|
||||
32 + // justified_block_hash
|
||||
4 + (2 * 8) // aggregate sig (two 256 bit points)
|
||||
4 + BLS_AGG_SIG_BYTE_SIZE // aggregate sig (two 256 bit points)
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -28,7 +31,7 @@ pub struct AttestationRecord {
|
||||
pub attester_bitfield: Bitfield,
|
||||
pub justified_slot: u64,
|
||||
pub justified_block_hash: Hash256,
|
||||
pub aggregate_sig: Option<AggregateSignature>,
|
||||
pub aggregate_sig: AggregateSignature,
|
||||
}
|
||||
|
||||
impl Encodable for AttestationRecord {
|
||||
@ -40,8 +43,7 @@ impl Encodable for AttestationRecord {
|
||||
s.append_vec(&self.attester_bitfield.to_be_vec());
|
||||
s.append(&self.justified_slot);
|
||||
s.append(&self.justified_block_hash);
|
||||
// TODO: encode the aggregate sig correctly
|
||||
s.append_vec(&vec![0_u8; 16])
|
||||
s.append_vec(&self.aggregate_sig.as_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +59,10 @@ impl Decodable for AttestationRecord {
|
||||
let (justified_slot, i) = u64::ssz_decode(bytes, i)?;
|
||||
let (justified_block_hash, i) = Hash256::ssz_decode(bytes, i)?;
|
||||
// Do aggregate sig decoding properly.
|
||||
let aggregate_sig = None; let i = i + 20;
|
||||
let (agg_sig_bytes, i) = decode_ssz_list(bytes, i)?;
|
||||
let aggregate_sig = AggregateSignature::from_bytes(&agg_sig_bytes)
|
||||
.map_err(|_| DecodeError::OutOfBounds)?;
|
||||
|
||||
let attestation_record = Self {
|
||||
slot,
|
||||
shard_id,
|
||||
@ -82,7 +87,7 @@ impl AttestationRecord {
|
||||
attester_bitfield: Bitfield::new(),
|
||||
justified_slot: 0,
|
||||
justified_block_hash: Hash256::zero(),
|
||||
aggregate_sig: None,
|
||||
aggregate_sig: AggregateSignature::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -113,7 +118,7 @@ mod tests {
|
||||
attester_bitfield: Bitfield::from(&vec![17; 42][..]),
|
||||
justified_slot: 19,
|
||||
justified_block_hash: Hash256::from(&vec![15; 32][..]),
|
||||
aggregate_sig: None,
|
||||
aggregate_sig: AggregateSignature::new(),
|
||||
};
|
||||
|
||||
let mut ssz_stream = SszStream::new();
|
||||
|
@ -235,9 +235,9 @@ mod tests {
|
||||
// will tell us if the hash changes, not that it matches some
|
||||
// canonical reference.
|
||||
let expected_hash = [
|
||||
195, 180, 208, 144, 113, 20, 129, 108, 14, 128, 166, 170,
|
||||
137, 15, 191, 186, 34, 171, 79, 214, 74, 86, 89, 202, 255,
|
||||
9, 100, 170, 149, 160, 93, 59
|
||||
64, 176, 117, 210, 228, 229, 237, 100, 66, 66, 98,
|
||||
252, 31, 111, 218, 27, 160, 57, 164, 12, 15, 164,
|
||||
66, 102, 142, 36, 2, 196, 121, 54, 242, 3
|
||||
];
|
||||
assert_eq!(hash, expected_hash);
|
||||
|
||||
|
@ -4,9 +4,10 @@ extern crate blake2_rfc as blake2;
|
||||
extern crate bytes;
|
||||
extern crate ssz;
|
||||
|
||||
use super::bls;
|
||||
use super::db;
|
||||
use super::Logger;
|
||||
use super::utils;
|
||||
use super::db;
|
||||
|
||||
pub mod active_state;
|
||||
pub mod attestation_record;
|
||||
|
@ -6,7 +6,7 @@ use super::attestation_parent_hashes::{
|
||||
use super::db::ClientDB;
|
||||
use super::db::stores::BlockStore;
|
||||
use super::ssz::SszStream;
|
||||
use super::utils::bls::{
|
||||
use super::bls::{
|
||||
AggregateSignature,
|
||||
PublicKey,
|
||||
};
|
||||
|
@ -6,6 +6,7 @@ use super::block::Block;
|
||||
use super::chain_config::ChainConfig;
|
||||
*/
|
||||
use super::block;
|
||||
use super::bls;
|
||||
use super::Logger;
|
||||
use super::db;
|
||||
use super::attestation_record::AttestationRecord;
|
||||
|
@ -1,7 +1,7 @@
|
||||
extern crate rand;
|
||||
|
||||
use super::utils::types::{ Hash256, Address, U256 };
|
||||
use super::utils::bls::{ PublicKey, Keypair };
|
||||
use super::bls::{ PublicKey, Keypair };
|
||||
|
||||
use self::rand::thread_rng;
|
||||
|
||||
@ -21,10 +21,9 @@ impl ValidatorRecord {
|
||||
///
|
||||
/// Returns the new instance and new keypair.
|
||||
pub fn zero_with_thread_rand_keypair() -> (Self, Keypair) {
|
||||
let mut rng = thread_rng();
|
||||
let keypair = Keypair::generate(&mut rng);
|
||||
let keypair = Keypair::random();
|
||||
let s = Self {
|
||||
pubkey: keypair.public.clone(),
|
||||
pubkey: keypair.pk.clone(),
|
||||
withdrawal_shard: 0,
|
||||
withdrawal_address: Address::zero(),
|
||||
randao_commitment: Hash256::zero(),
|
||||
|
@ -1,13 +0,0 @@
|
||||
extern crate bls;
|
||||
extern crate pairing;
|
||||
|
||||
use self::bls::AggregateSignature as GenericAggregateSignature;
|
||||
use self::bls::Signature as GenericSignature;
|
||||
use self::bls::Keypair as GenericKeypair;
|
||||
use self::bls::PublicKey as GenericPublicKey;
|
||||
use self::pairing::bls12_381::Bls12;
|
||||
|
||||
pub type AggregateSignature = GenericAggregateSignature<Bls12>;
|
||||
pub type Signature = GenericSignature<Bls12>;
|
||||
pub type Keypair = GenericKeypair<Bls12>;
|
||||
pub type PublicKey = GenericPublicKey<Bls12>;
|
@ -7,9 +7,5 @@ extern crate boolean_bitfield;
|
||||
pub mod macros;
|
||||
pub mod hash;
|
||||
pub mod types;
|
||||
pub mod bls;
|
||||
pub mod test_helpers;
|
||||
pub mod logging;
|
||||
pub mod errors;
|
||||
|
||||
|
||||
|
@ -1,12 +0,0 @@
|
||||
extern crate rand;
|
||||
|
||||
use super::bls::Keypair;
|
||||
use self::rand::thread_rng;
|
||||
|
||||
// Returns a keypair for use in testing purposes.
|
||||
// It is dangerous because we provide no guarantees
|
||||
// that the private key is unique or in-fact private.
|
||||
pub fn get_dangerous_test_keypair() -> Keypair {
|
||||
let mut rng = thread_rng();
|
||||
Keypair::generate(&mut rng)
|
||||
}
|
Loading…
Reference in New Issue
Block a user