Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temp: revert to bls12_381 #31

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions node/actors/executor/src/config/proto/mod.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
// examples: "203.0.113.7:3456", "[2001:DB8::1]:4567"
//
// ValidatorPublicKey - public key of the validator (consensus participant) of the form "validator:public:<signature scheme>:<hex encoded key material>"
// Currently only bn254 signature scheme is supported for validators.
// example: "validator:public:bn254:4b0c4697f0a35eab30f63684ae4611f3c1d631eecfd97237e2345a9b3d0c472dbb16c49b793beceaab0cdd89cda6ff1099bd1aaf1ad6cabde9a15793cc09b407"
// Currently only bls12_381 signature scheme is supported for validators.
// example: "validator:public:bls12_381:4b0c4697f0a35eab30f63684ae4611f3c1d631eecfd97237e2345a9b3d0c472dbb16c49b793beceaab0cdd89cda6ff1099bd1aaf1ad6cabde9a15793cc09b407"
//
// NodePublicKey - public key of the node (gossip network participant) of the form "node:public:<signature scheme>:<hex encoded key material>"
// Currently only ed25519 signature scheme is supported for nodes.
Expand Down
8 changes: 4 additions & 4 deletions node/deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ skip = [
{ name = "regex-syntax", version = "=0.6.29" },

# Old versions required by hyper.
{ name = "socket2", version = "0.4.10" },
{ name = "socket2", version = "0.4.9" },

# Old versions required by ark-bn254.
{ name = "syn", version = "=1.0.109" },
{ name = "hashbrown", version = "=0.13.2" },
{ name = "itertools", version = "=0.10.5" }
{ name = "hashbrown", version = "0.13.2" },
{ name = "itertools", version = "0.10.5" },
{ name = "syn", version = "1.0.109" },
]

[sources]
Expand Down
3 changes: 1 addition & 2 deletions node/libs/crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

pub use fmt::*;

/// Currently replaced by [bn254] and unused.
pub mod bls12_381;

/// Currently replaced by [bls12_381] and unused.
pub mod bn254;
pub mod ed25519;
mod fmt;
Expand Down
6 changes: 3 additions & 3 deletions node/libs/roles/src/proto/validator.proto
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ message Signed {
}

message PublicKey {
optional bytes bn254 = 1; // required
optional bytes bls12_381 = 1; // required
}

message Signature {
optional bytes bn254 = 1; // required
optional bytes bls12_381 = 1; // required
}

message AggregateSignature {
optional bytes bn254 = 1; // required
optional bytes bls12_381 = 1; // required
}
12 changes: 6 additions & 6 deletions node/libs/roles/src/validator/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@ impl ProtoFmt for PublicKey {
type Proto = proto::PublicKey;

fn read(r: &Self::Proto) -> anyhow::Result<Self> {
Ok(Self(ByteFmt::decode(required(&r.bn254)?)?))
Ok(Self(ByteFmt::decode(required(&r.bls12_381)?)?))
}

fn build(&self) -> Self::Proto {
Self::Proto {
bn254: Some(self.0.encode()),
bls12_381: Some(self.0.encode()),
}
}
}
Expand All @@ -367,12 +367,12 @@ impl ProtoFmt for Signature {
type Proto = proto::Signature;

fn read(r: &Self::Proto) -> anyhow::Result<Self> {
Ok(Self(ByteFmt::decode(required(&r.bn254)?)?))
Ok(Self(ByteFmt::decode(required(&r.bls12_381)?)?))
}

fn build(&self) -> Self::Proto {
Self::Proto {
bn254: Some(self.0.encode()),
bls12_381: Some(self.0.encode()),
}
}
}
Expand All @@ -381,12 +381,12 @@ impl ProtoFmt for AggregateSignature {
type Proto = proto::AggregateSignature;

fn read(r: &Self::Proto) -> anyhow::Result<Self> {
Ok(Self(ByteFmt::decode(required(&r.bn254)?)?))
Ok(Self(ByteFmt::decode(required(&r.bls12_381)?)?))
}

fn build(&self) -> Self::Proto {
Self::Proto {
bn254: Some(self.0.encode()),
bls12_381: Some(self.0.encode()),
}
}
}
23 changes: 14 additions & 9 deletions node/libs/roles/src/validator/keys/aggregate_signature.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
use super::{Error, PublicKey, Signature};
use crate::validator::messages::{Msg, MsgHash};
use std::fmt;
use zksync_consensus_crypto::{bn254, ByteFmt, Text, TextFmt};

use zksync_consensus_crypto::{bls12_381, ByteFmt, Text, TextFmt};
use zksync_consensus_utils::enum_util::Variant;

use crate::validator::messages::{Msg, MsgHash};

use super::{Error, PublicKey, Signature};

Comment on lines +2 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We conventionally place uses in a single block; you can run the following command to achieve order them:

cargo fmt -- --config imports_granularity=Crate --config group_imports=One

@brunoffranca @pompon0 I think this was previously mentioned in style.md; or am I misremembering things?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it used to be there

/// An aggregate signature from a validator.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct AggregateSignature(pub(crate) bn254::AggregateSignature);
pub struct AggregateSignature(pub(crate) bls12_381::AggregateSignature);

impl AggregateSignature {
/// Generate a new aggregate signature from a list of signatures.
pub fn aggregate<'a>(sigs: impl IntoIterator<Item = &'a Signature>) -> Self {
AggregateSignature(bn254::AggregateSignature::aggregate(
sigs.into_iter().map(|sig| &sig.0).collect::<Vec<_>>(),
pub fn aggregate<'a>(sigs: impl IntoIterator<Item = &'a Signature>) -> anyhow::Result<Self> {
Ok(AggregateSignature(
bls12_381::AggregateSignature::aggregate(
sigs.into_iter().map(|sig| &sig.0).collect::<Vec<_>>(),
)?,
))
}

Expand Down Expand Up @@ -53,12 +58,12 @@ impl ByteFmt for AggregateSignature {
impl TextFmt for AggregateSignature {
fn encode(&self) -> String {
format!(
"validator:aggregate_signature:bn254:{}",
"validator:aggregate_signature:bls12_381:{}",
hex::encode(ByteFmt::encode(&self.0))
)
}
fn decode(text: Text) -> anyhow::Result<Self> {
text.strip("validator:aggregate_signature:bn254:")?
text.strip("validator:aggregate_signature:bls12_381:")?
.decode_hex()
.map(Self)
}
Expand Down
2 changes: 1 addition & 1 deletion node/libs/roles/src/validator/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ pub use secret_key::SecretKey;
pub use signature::Signature;

/// Error type returned by validator key operations.
pub type Error = zksync_consensus_crypto::bn254::Error;
pub type Error = zksync_consensus_crypto::bls12_381::Error;
8 changes: 4 additions & 4 deletions node/libs/roles/src/validator/keys/public_key.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::fmt;
use zksync_consensus_crypto::{bn254, ByteFmt, Text, TextFmt};
use zksync_consensus_crypto::{bls12_381, ByteFmt, Text, TextFmt};

/// A public key for a validator.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PublicKey(pub(crate) bn254::PublicKey);
pub struct PublicKey(pub(crate) bls12_381::PublicKey);

impl ByteFmt for PublicKey {
fn encode(&self) -> Vec<u8> {
Expand All @@ -17,12 +17,12 @@ impl ByteFmt for PublicKey {
impl TextFmt for PublicKey {
fn encode(&self) -> String {
format!(
"validator:public:bn254:{}",
"validator:public:bls12_381:{}",
hex::encode(ByteFmt::encode(&self.0))
)
}
fn decode(text: Text) -> anyhow::Result<Self> {
text.strip("validator:public:bn254:")?
text.strip("validator:public:bls12_381:")?
.decode_hex()
.map(Self)
}
Expand Down
8 changes: 4 additions & 4 deletions node/libs/roles/src/validator/keys/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use super::{PublicKey, Signature};
use crate::validator::messages::{Msg, MsgHash, Signed};
use rand::Rng;
use std::{fmt, sync::Arc};
use zksync_consensus_crypto::{bn254, ByteFmt, Text, TextFmt};
use zksync_consensus_crypto::{bls12_381, ByteFmt, Text, TextFmt};
use zksync_consensus_utils::enum_util::Variant;

/// A secret key for the validator role.
/// SecretKey is put into an Arc, so that we can clone it,
/// without copying the secret all over the RAM.
#[derive(Clone)]
pub struct SecretKey(pub(crate) Arc<bn254::SecretKey>);
pub struct SecretKey(pub(crate) Arc<bls12_381::SecretKey>);

impl SecretKey {
/// Generate a new secret key.
Expand Down Expand Up @@ -51,13 +51,13 @@ impl ByteFmt for SecretKey {
impl TextFmt for SecretKey {
fn encode(&self) -> String {
format!(
"validator:secret:bn254:{}",
"validator:secret:bls12_381:{}",
hex::encode(ByteFmt::encode(&*self.0))
)
}

fn decode(text: Text) -> anyhow::Result<Self> {
text.strip("validator:secret:bn254:")?
text.strip("validator:secret:bls12_381:")?
.decode_hex()
.map(Arc::new)
.map(Self)
Expand Down
8 changes: 4 additions & 4 deletions node/libs/roles/src/validator/keys/signature.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::{Error, PublicKey};
use crate::validator::messages::{Msg, MsgHash};
use std::fmt;
use zksync_consensus_crypto::{bn254, ByteFmt, Text, TextFmt};
use zksync_consensus_crypto::{bls12_381, ByteFmt, Text, TextFmt};

/// A signature from a validator.
#[derive(Clone, PartialEq, Eq)]
pub struct Signature(pub(crate) bn254::Signature);
pub struct Signature(pub(crate) bls12_381::Signature);

impl Signature {
/// Verify a message against a public key.
Expand All @@ -31,12 +31,12 @@ impl ByteFmt for Signature {
impl TextFmt for Signature {
fn encode(&self) -> String {
format!(
"validator:signature:bn254:{}",
"validator:signature:bls12_381:{}",
hex::encode(ByteFmt::encode(&self.0))
)
}
fn decode(text: Text) -> anyhow::Result<Self> {
text.strip("validator:signature:bn254:")?
text.strip("validator:signature:bls12_381:")?
.decode_hex()
.map(Self)
}
Expand Down
4 changes: 2 additions & 2 deletions node/libs/roles/src/validator/messages/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl PrepareQC {

// Aggregate the signatures.
let signature =
validator::AggregateSignature::aggregate(signed_messages.iter().map(|v| &v.sig));
validator::AggregateSignature::aggregate(signed_messages.iter().map(|v| &v.sig))?;

Ok(Self { map, signature })
}
Expand Down Expand Up @@ -314,7 +314,7 @@ impl CommitQC {
.collect();

// Aggregate the signatures.
let signature = validator::AggregateSignature::aggregate(msg_map.values().copied());
let signature = validator::AggregateSignature::aggregate(msg_map.values().copied())?;
Ok(Self {
message,
signers: Signers(bit_vec),
Expand Down
2 changes: 1 addition & 1 deletion node/libs/roles/src/validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn test_agg_signature_verify() {
let sig1 = key1.sign_hash(&msg1);
let sig2 = key2.sign_hash(&msg2);

let agg_sig = AggregateSignature::aggregate(vec![&sig1, &sig2]);
let agg_sig = AggregateSignature::aggregate(vec![&sig1, &sig2]).unwrap();

// Matching key and message.
assert!(agg_sig
Expand Down
Loading