Skip to content

Commit

Permalink
exposed proof-of-possession methods (#186)
Browse files Browse the repository at this point in the history
Needed for matter-labs/zksync-era#2684
Also upgraded logging of attestation votes.

---------

Co-authored-by: Akosh Farkash <[email protected]>
  • Loading branch information
pompon0 and aakoshh authored Sep 2, 2024
1 parent fa035ec commit 7e5068f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion node/actors/network/src/gossip/attestation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ impl State {
}
// Verify signature only after checking all the other preconditions.
vote.verify().context("verify")?;
tracing::info!("collected vote with weight {weight} from {:?}", vote.key);
tracing::info!(
"collected vote for {:?} with weight {weight} from {:?}",
vote.msg.number,
vote.key
);
self.votes.insert(vote.key.clone(), vote);
self.total_weight += weight;
Ok(())
Expand Down
1 change: 0 additions & 1 deletion node/libs/crypto/src/bls12_381/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ impl SecretKey {
/// Produces a proof of possession for the public key corresponding to this [`SecretKey`]
pub fn sign_pop(&self) -> ProofOfPossession {
let msg = self.public().encode();

ProofOfPossession(self.0.sign(&msg, DST_POP, &[]))
}

Expand Down
7 changes: 6 additions & 1 deletion node/libs/roles/src/validator/keys/secret_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{PublicKey, Signature};
use super::{ProofOfPossession, PublicKey, Signature};
use crate::validator::messages::{Msg, MsgHash, Signed};
use std::{fmt, sync::Arc};
use zksync_consensus_crypto::{bls12_381, ByteFmt, Text, TextFmt};
Expand Down Expand Up @@ -35,6 +35,11 @@ impl SecretKey {
pub fn sign_hash(&self, msg_hash: &MsgHash) -> Signature {
Signature(self.0.sign(&ByteFmt::encode(msg_hash)))
}

/// Sign a proof of possession.
pub fn sign_pop(&self) -> ProofOfPossession {
ProofOfPossession(self.0.sign_pop())
}
}

impl ByteFmt for SecretKey {
Expand Down
2 changes: 1 addition & 1 deletion node/libs/roles/src/validator/keys/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct ProofOfPossession(pub(crate) bls12_381::ProofOfPossession);

impl ProofOfPossession {
/// Verifies the proof against the public key.
pub fn verify(&self, pk: PublicKey) -> anyhow::Result<()> {
pub fn verify(&self, pk: &PublicKey) -> anyhow::Result<()> {
self.0.verify(&pk.0)
}
}
Expand Down

0 comments on commit 7e5068f

Please sign in to comment.