Skip to content

Commit

Permalink
Simplify auth sign info verify function (MystenLabs#3235)
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind authored Jul 19, 2022
1 parent 83e9845 commit c6ef208
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
19 changes: 8 additions & 11 deletions crates/sui-core/src/safe_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ impl<C> SafeClient<C> {

if let Some(signed_effects) = &response.signed_effects {
// Check signature
signed_effects
.auth_signature
.signature
.verify(&signed_effects.effects, self.address)?;
signed_effects.verify(&self.committee)?;
// Check it has the right signer
fp_ensure!(
signed_effects.auth_signature.authority == self.address,
SuiError::ByzantineAuthoritySuspicion {
authority: self.address
}
);
// Checks it concerns the right tx
fp_ensure!(
signed_effects.effects.transaction_digest == digest,
Expand All @@ -102,13 +106,6 @@ impl<C> SafeClient<C> {
}
);
}
// Check it has the right signer
fp_ensure!(
signed_effects.auth_signature.authority == self.address,
SuiError::ByzantineAuthoritySuspicion {
authority: self.address
}
);
}

Ok(())
Expand Down
25 changes: 22 additions & 3 deletions crates/sui-types/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,19 +505,38 @@ impl PartialEq for AuthoritySignInfo {
}

impl AuthoritySignInfo {
pub fn add_to_verification_obligation(
pub fn add_to_verification_obligation<T>(
&self,
data: &T,
committee: &Committee,
obligation: &mut VerificationObligation,
message_index: usize,
) -> SuiResult<()> {
) -> SuiResult<()>
where
T: Signable<Vec<u8>>,
{
let weight = committee.weight(&self.authority);
fp_ensure!(weight > 0, SuiError::UnknownSigner);

obligation
.public_keys
.push(committee.public_key(&self.authority)?);
obligation.signatures.push(self.signature.0);
let mut message = Vec::new();
data.write(&mut message);
let message_index = obligation.add_message(message);
obligation.message_index.push(message_index);
Ok(())
}

pub fn verify<T>(&self, data: &T, committee: &Committee) -> SuiResult<()>
where
T: Signable<Vec<u8>>,
{
let mut obligation = VerificationObligation::default();
self.add_to_verification_obligation(data, committee, &mut obligation)?;
obligation.verify_all()?;
Ok(())
}
}

/// Represents at least a quorum (could be more) of authority signatures.
Expand Down
20 changes: 11 additions & 9 deletions crates/sui-types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,19 +734,17 @@ impl SignedTransaction {
}

/// Verify the signature and return the non-zero voting right of the authority.
pub fn verify(&self, committee: &Committee) -> Result<u64, SuiError> {
pub fn verify(&self, committee: &Committee) -> SuiResult {
let mut obligation = VerificationObligation::default();
self.add_sender_sig_to_verification_obligation(&mut obligation)?;
let weight = committee.weight(&self.auth_sign_info.authority);
fp_ensure!(weight > 0, SuiError::UnknownSigner);
let mut message = Vec::new();
self.data.write(&mut message);
let idx = obligation.add_message(message);
self.auth_sign_info
.add_to_verification_obligation(committee, &mut obligation, idx)?;
self.auth_sign_info.add_to_verification_obligation(
&self.data,
committee,
&mut obligation,
)?;

obligation.verify_all()?;
Ok(weight)
Ok(())
}

// Turn a SignedTransaction into a Transaction. This is needed when we are
Expand Down Expand Up @@ -1433,6 +1431,10 @@ impl SignedTransactionEffects {
pub fn digest(&self) -> [u8; 32] {
sha3_hash(&self.effects)
}

pub fn verify(&self, committee: &Committee) -> SuiResult {
self.auth_signature.verify(&self.effects, committee)
}
}

impl PartialEq for SignedTransactionEffects {
Expand Down
9 changes: 2 additions & 7 deletions crates/sui-types/src/messages_checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,8 @@ impl SignedCheckpointSummary {
self.summary.epoch == self.auth_signature.epoch,
SuiError::from("Epoch in the summary doesn't match with the signature")
);
fp_ensure!(
committee.weight(&self.auth_signature.authority) > 0,
SuiError::UnknownSigner
);
self.auth_signature
.signature
.verify(&self.summary, self.auth_signature.authority)?;

self.auth_signature.verify(&self.summary, committee)?;

if let Some(contents) = contents {
let recomputed = CheckpointSummary::new(
Expand Down

0 comments on commit c6ef208

Please sign in to comment.