Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
akildemir committed Aug 17, 2023
1 parent 70a9bf0 commit 3d672d2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
27 changes: 14 additions & 13 deletions coordinator/tributary/src/tendermint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ use ciphersuite::{
},
Ciphersuite, Ristretto,
};
use schnorr::{SchnorrSignature, aggregate::{SchnorrAggregator, SchnorrAggregate}};
use schnorr::{
SchnorrSignature,
aggregate::{SchnorrAggregator, SchnorrAggregate},
};

use serai_db::Db;

Expand Down Expand Up @@ -174,7 +177,12 @@ impl SignatureScheme for Validators {
}

// TODO: this function panics if wrong data passed in, should it?
fn aggregate(&self, validators: &[Self::ValidatorId], sigs: &[Self::Signature], msg: &[u8]) -> Self::AggregateSignature {
fn aggregate(
&self,
validators: &[Self::ValidatorId],
sigs: &[Self::Signature],
msg: &[u8],
) -> Self::AggregateSignature {
assert_eq!(validators.len(), sigs.len());

let mut aggregator = SchnorrAggregator::<Ristretto>::new(DST);
Expand All @@ -195,19 +203,17 @@ impl SignatureScheme for Validators {
msg: &[u8],
sig: &Self::AggregateSignature,
) -> bool {

let Ok(aggregate) = SchnorrAggregate::<Ristretto>::read::<&[u8]>(&mut sig.as_slice())
else {
let Ok(aggregate) = SchnorrAggregate::<Ristretto>::read::<&[u8]>(&mut sig.as_slice()) else {
return false;
};

// get Rs in aggregate
let mut pos: usize = 4;
let len: [u8; 4] = sig[..pos].try_into().unwrap();
let len: [u8; 4] = sig[.. pos].try_into().unwrap();
#[allow(non_snake_case)]
let mut Rs: Vec<[u8; 32]> = vec![];
for _ in 0 .. u32::from_le_bytes(len) {
Rs.push(sig[pos..pos+32].try_into().unwrap());
Rs.push(sig[pos .. pos + 32].try_into().unwrap());
pos += 32;
}

Expand All @@ -225,12 +231,7 @@ impl SignatureScheme for Validators {
signers
.iter()
.zip(challenges)
.map(|(s, c)| {
(
<Ristretto as Ciphersuite>::read_G(&mut s.as_slice()).unwrap(),
c,
)
})
.map(|(s, c)| (<Ristretto as Ciphersuite>::read_G(&mut s.as_slice()).unwrap(), c))
.collect::<Vec<_>>()
.as_slice(),
)
Expand Down
14 changes: 12 additions & 2 deletions coordinator/tributary/tendermint/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ pub trait SignatureScheme: Send + Sync {
fn verify(&self, validator: Self::ValidatorId, msg: &[u8], sig: &Self::Signature) -> bool;

/// Aggregate signatures.
fn aggregate(&self, validators: &[Self::ValidatorId], sigs: &[Self::Signature], msg: &[u8]) -> Self::AggregateSignature;
fn aggregate(
&self,
validators: &[Self::ValidatorId],
sigs: &[Self::Signature],
msg: &[u8],
) -> Self::AggregateSignature;
/// Verify an aggregate signature for the list of signers.
#[must_use]
fn verify_aggregate(
Expand All @@ -102,7 +107,12 @@ impl<S: SignatureScheme> SignatureScheme for Arc<S> {
self.as_ref().verify(validator, msg, sig)
}

fn aggregate(&self, validators: &[Self::ValidatorId], sigs: &[Self::Signature], msg: &[u8]) -> Self::AggregateSignature {
fn aggregate(
&self,
validators: &[Self::ValidatorId],
sigs: &[Self::Signature],
msg: &[u8],
) -> Self::AggregateSignature {
self.as_ref().aggregate(validators, sigs, msg)
}

Expand Down
5 changes: 4 additions & 1 deletion coordinator/tributary/tendermint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ impl<N: Network + 'static> TendermintMachine<N> {
}
}

let commit_msg = commit_msg(self.block.end_time[&self.block.round().number].canonical(), block.id().as_ref());
let commit_msg = commit_msg(
self.block.end_time[&self.block.round().number].canonical(),
block.id().as_ref(),
);
let commit = Commit {
end_time: self.block.end_time[&msg.round].canonical(),
validators: validators.clone(),
Expand Down
7 changes: 6 additions & 1 deletion coordinator/tributary/tendermint/tests/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ impl SignatureScheme for TestSignatureScheme {
(sig[.. 2] == validator.to_le_bytes()) && (sig[2 ..] == [msg, &[0; 30]].concat()[.. 30])
}

fn aggregate(&self, _: &[Self::ValidatorId], sigs: &[Self::Signature], _: &[u8]) -> Self::AggregateSignature {
fn aggregate(
&self,
_: &[Self::ValidatorId],
sigs: &[Self::Signature],
_: &[u8],
) -> Self::AggregateSignature {
sigs.to_vec()
}

Expand Down

0 comments on commit 3d672d2

Please sign in to comment.