Files
lighthouse/eth2/utils/bls/src/signature_set.rs
Michael Sproul 338cb2fba7 Fix parallelism bug in exit processing (#1110)
* Fix parallelism bug in exit processing

Also:

* Remove parallelism for all other operations except deposit merkle proofs
* Improve exit tests
* Fix broken attestation test

Closes #1090

* Allow for generating block/pre/post states from some unit tests (#1123)

* Add post-state checks, comments

* Add state_transition_vectors crate

* Integrate new testing crate with CI

* Add readme

* Add additional valid tests

* Remove ExitTests (they were moved to new crate)

* Small test fixes

* Delete incorrect saturating_sub in slash_validator

And clean-up the balance increase/decrease functions to look more like the spec.

Co-authored-by: Paul Hauner <paul@paulhauner.com>
2020-05-09 09:37:21 +10:00

76 lines
2.2 KiB
Rust

use crate::{AggregateSignature, PublicKey, Signature};
use std::borrow::Cow;
#[cfg(not(feature = "fake_crypto"))]
use milagro_bls::{
AggregatePublicKey as RawAggregatePublicKey, AggregateSignature as RawAggregateSignature,
PublicKey as RawPublicKey,
};
#[cfg(feature = "fake_crypto")]
use crate::fakes::{
AggregatePublicKey as RawAggregatePublicKey, AggregateSignature as RawAggregateSignature,
PublicKey as RawPublicKey,
};
type Message = Vec<u8>;
#[derive(Clone, Debug)]
pub struct SignatureSet {
pub signature: RawAggregateSignature,
signing_keys: RawAggregatePublicKey,
message: Message,
}
impl SignatureSet {
pub fn single(signature: &Signature, signing_key: Cow<PublicKey>, message: Message) -> Self {
Self {
signature: RawAggregateSignature::from_signature(signature.as_raw()),
signing_keys: RawAggregatePublicKey::from_public_key(signing_key.as_raw()),
message,
}
}
pub fn new(
signature: &AggregateSignature,
signing_keys: Vec<Cow<PublicKey>>,
message: Message,
) -> Self
where {
let signing_keys_refs: Vec<&RawPublicKey> =
signing_keys.iter().map(|pk| pk.as_raw()).collect();
Self {
signature: signature.as_raw().clone(),
signing_keys: RawAggregatePublicKey::aggregate(&signing_keys_refs),
message,
}
}
pub fn is_valid(&self) -> bool {
self.signature
.fast_aggregate_verify_pre_aggregated(&self.message, &self.signing_keys)
}
}
#[cfg(not(feature = "fake_crypto"))]
type VerifySet<'a> = (
&'a RawAggregateSignature,
&'a RawAggregatePublicKey,
&'a [u8],
);
#[cfg(not(feature = "fake_crypto"))]
pub fn verify_signature_sets<'a>(sets: Vec<SignatureSet>) -> bool {
let rng = &mut rand::thread_rng();
let verify_set: Vec<VerifySet> = sets
.iter()
.map(|ss| (&ss.signature, &ss.signing_keys, ss.message.as_slice()))
.collect();
RawAggregateSignature::verify_multiple_aggregate_signatures(rng, verify_set.into_iter())
}
#[cfg(feature = "fake_crypto")]
pub fn verify_signature_sets<'a>(_: Vec<SignatureSet>) -> bool {
true
}