mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-10 05:09:22 +00:00
Minor SignatureScheme API changes
This commit is contained in:
@@ -46,7 +46,7 @@ pub trait SignatureScheme: Send + Sync {
|
||||
fn sign(&self, msg: &[u8]) -> Self::Signature;
|
||||
/// Verify a signature from the validator in question.
|
||||
#[must_use]
|
||||
fn verify(&self, validator: Self::ValidatorId, msg: &[u8], sig: Self::Signature) -> bool;
|
||||
fn verify(&self, validator: Self::ValidatorId, msg: &[u8], sig: &Self::Signature) -> bool;
|
||||
|
||||
/// Aggregate signatures.
|
||||
fn aggregate(sigs: &[Self::Signature]) -> Self::AggregateSignature;
|
||||
@@ -54,8 +54,8 @@ pub trait SignatureScheme: Send + Sync {
|
||||
#[must_use]
|
||||
fn verify_aggregate(
|
||||
&self,
|
||||
msg: &[u8],
|
||||
signers: &[Self::ValidatorId],
|
||||
msg: &[u8],
|
||||
sig: &Self::AggregateSignature,
|
||||
) -> bool;
|
||||
}
|
||||
@@ -142,8 +142,8 @@ pub trait Network: Send + Sync {
|
||||
commit: &Commit<Self::SignatureScheme>,
|
||||
) -> bool {
|
||||
if !self.signature_scheme().verify_aggregate(
|
||||
&commit_msg(commit.round, id.as_ref()),
|
||||
&commit.validators,
|
||||
&commit_msg(commit.round, id.as_ref()),
|
||||
&commit.signature,
|
||||
) {
|
||||
return false;
|
||||
|
||||
@@ -278,7 +278,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
||||
loop {
|
||||
match msg_recv.try_recv() {
|
||||
Ok(msg) => {
|
||||
if !machine.signer.verify(msg.msg.sender, &msg.msg.encode(), msg.sig) {
|
||||
if !machine.signer.verify(msg.msg.sender, &msg.msg.encode(), &msg.sig) {
|
||||
continue;
|
||||
}
|
||||
machine.queue.push((false, msg.msg));
|
||||
@@ -345,7 +345,7 @@ impl<N: Network + 'static> TendermintMachine<N> {
|
||||
) -> Result<Option<N::Block>, TendermintError<N::ValidatorId>> {
|
||||
// Verify the signature if this is a precommit
|
||||
if let Data::Precommit(Some((id, sig))) = &msg.data {
|
||||
if !self.signer.verify(msg.sender, &commit_msg(msg.round, id.as_ref()), sig.clone()) {
|
||||
if !self.signer.verify(msg.sender, &commit_msg(msg.round, id.as_ref()), sig) {
|
||||
// Since we verified this validator actually sent the message, they're malicious
|
||||
Err(TendermintError::Malicious(msg.sender))?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user