Altair consensus changes and refactors (#2279)

## Proposed Changes

Implement the consensus changes necessary for the upcoming Altair hard fork.

## Additional Info

This is quite a heavy refactor, with pivotal types like the `BeaconState` and `BeaconBlock` changing from structs to enums. This ripples through the whole codebase with field accesses changing to methods, e.g. `state.slot` => `state.slot()`.


Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
Michael Sproul
2021-07-09 06:15:32 +00:00
parent 89361573d4
commit b4689e20c6
271 changed files with 9652 additions and 8444 deletions

View File

@@ -153,7 +153,19 @@ impl PartialEq for BlstAggregatePublicKey {
}
}
impl TAggregatePublicKey for BlstAggregatePublicKey {}
impl TAggregatePublicKey<blst_core::PublicKey> for BlstAggregatePublicKey {
fn to_public_key(&self) -> GenericPublicKey<blst_core::PublicKey> {
GenericPublicKey::from_point(self.0.to_public_key())
}
fn aggregate(pubkeys: &[GenericPublicKey<blst_core::PublicKey>]) -> Result<Self, Error> {
let pubkey_refs = pubkeys.iter().map(|pk| pk.point()).collect::<Vec<_>>();
// Public keys have already been checked for subgroup and infinity
let agg_pub = blst_core::AggregatePublicKey::aggregate(&pubkey_refs, false)?;
Ok(BlstAggregatePublicKey(agg_pub))
}
}
impl TSignature<blst_core::PublicKey> for blst_core::Signature {
fn serialize(&self) -> [u8; SIGNATURE_BYTES_LEN] {

View File

@@ -6,6 +6,7 @@ use crate::{
generic_signature::{TSignature, SIGNATURE_BYTES_LEN},
Error, Hash256, ZeroizeHash, INFINITY_PUBLIC_KEY, INFINITY_SIGNATURE,
};
/// Provides the externally-facing, core BLS types.
pub mod types {
pub use super::verify_signature_sets;
@@ -63,7 +64,15 @@ impl PartialEq for PublicKey {
#[derive(Clone)]
pub struct AggregatePublicKey([u8; PUBLIC_KEY_BYTES_LEN]);
impl TAggregatePublicKey for AggregatePublicKey {}
impl TAggregatePublicKey<PublicKey> for AggregatePublicKey {
fn to_public_key(&self) -> GenericPublicKey<PublicKey> {
GenericPublicKey::from_point(PublicKey(self.0))
}
fn aggregate(_pubkeys: &[GenericPublicKey<PublicKey>]) -> Result<Self, Error> {
Ok(Self(INFINITY_PUBLIC_KEY))
}
}
impl Eq for AggregatePublicKey {}

View File

@@ -86,7 +86,18 @@ impl TPublicKey for milagro::PublicKey {
}
}
impl TAggregatePublicKey for milagro::AggregatePublicKey {}
impl TAggregatePublicKey<milagro::PublicKey> for milagro::AggregatePublicKey {
fn to_public_key(&self) -> GenericPublicKey<milagro::PublicKey> {
GenericPublicKey::from_point(milagro::PublicKey {
point: self.point.clone(),
})
}
fn aggregate(pubkeys: &[GenericPublicKey<milagro::PublicKey>]) -> Result<Self, Error> {
let pubkey_refs = pubkeys.iter().map(|pk| pk.point()).collect::<Vec<_>>();
Ok(milagro::AggregatePublicKey::aggregate(&pubkey_refs)?)
}
}
impl TSignature<milagro::PublicKey> for milagro::Signature {
fn serialize(&self) -> [u8; SIGNATURE_BYTES_LEN] {