Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix possible panic in sig verification #3543

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/3543-fix-verify-sig-panic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fixed a possible panic in transaction signatures verification missing expected
signature(s). ([\#3543](https://github.com/anoma/namada/pull/3543))
13 changes: 8 additions & 5 deletions crates/tx/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub enum VerifySigError {
InvalidSectionSignature(String),
#[error("The number of PKs overflows u8::MAX")]
PksOverflow,
#[error("An expected signature is missing.")]
MissingSignature,
}

#[allow(missing_docs)]
Expand Down Expand Up @@ -558,18 +560,19 @@ impl Authorization {
// Verify the signatures against the subset of this section's public
// keys that are also in the given map
Signer::PubKeys(pks) => {
let hash = self.get_raw_hash();
for (idx, pk) in pks.iter().enumerate() {
if let Some(map_idx) =
public_keys_index_map.get_index_from_public_key(pk)
{
let sig_idx = u8::try_from(idx)
.map_err(|_| VerifySigError::PksOverflow)?;
consume_verify_sig_gas()?;
common::SigScheme::verify_signature(
pk,
&self.get_raw_hash(),
&self.signatures[&sig_idx],
)?;
let sig = self
.signatures
.get(&sig_idx)
.ok_or(VerifySigError::MissingSignature)?;
common::SigScheme::verify_signature(pk, &hash, sig)?;
verified_pks.insert(map_idx);
// Cannot overflow
#[allow(clippy::arithmetic_side_effects)]
Expand Down
Loading