diff --git a/ledger/narwhal/batch-certificate/src/lib.rs b/ledger/narwhal/batch-certificate/src/lib.rs index 1aff6f278c..7f5c7d262c 100644 --- a/ledger/narwhal/batch-certificate/src/lib.rs +++ b/ledger/narwhal/batch-certificate/src/lib.rs @@ -53,17 +53,7 @@ impl BatchCertificate { impl BatchCertificate { /// Initializes a new batch certificate. pub fn from(batch_header: BatchHeader, signatures: IndexSet>) -> Result { - // Ensure that the number of signatures is within bounds. - ensure!(signatures.len() <= Self::max_signatures()? as usize, "Invalid number of signatures"); - - // Ensure that the signature is from a unique signer and not from the author. - let signature_authors = signatures.iter().map(|signature| signature.to_address()).collect::>(); - ensure!( - !signature_authors.contains(&batch_header.author()), - "The author's signature was included in the signers" - ); - ensure!(signature_authors.len() == signatures.len(), "A duplicate author was found in the set of signatures"); - + Self::check_signature_basic(&batch_header, &signatures)?; // Verify the signatures are valid. cfg_iter!(signatures).try_for_each(|signature| { if !signature.verify(&signature.to_address(), &[batch_header.batch_id()]) { @@ -82,6 +72,20 @@ impl BatchCertificate { // Return the batch certificate. Ok(Self { batch_header, signatures }) } + + pub fn check_signature_basic(batch_header: &BatchHeader, signatures: &IndexSet>) -> Result<()> { + // Ensure that the number of signatures is within bounds. + ensure!(signatures.len() <= Self::max_signatures()? as usize, "Invalid number of signatures"); + + // Ensure that the signature is from a unique signer and not from the author. + let signature_authors = signatures.iter().map(|signature| signature.to_address()).collect::>(); + ensure!( + !signature_authors.contains(&batch_header.author()), + "The author's signature was included in the signers" + ); + ensure!(signature_authors.len() == signatures.len(), "A duplicate author was found in the set of signatures"); + Ok(()) + } } impl PartialEq for BatchCertificate {