Skip to content

Commit f07f0b5

Browse files
CopilotSteake
andcommitted
Address code review feedback
- Fix serialization error handling in proposal ID generation - Add logging for guardian signature verification failures - Improve error handling for invalid keys/signatures Co-authored-by: Steake <[email protected]>
1 parent a434be7 commit f07f0b5

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

crates/bitcell-governance/src/guardian.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,42 @@ impl GuardianSet {
106106
// Create PublicKey and Signature from bytes
107107
let pubkey = match PublicKey::from_bytes(&guardian.pubkey) {
108108
Ok(pk) => pk,
109-
Err(_) => continue,
109+
Err(e) => {
110+
tracing::warn!(
111+
guardian = %hex::encode(&guardian.pubkey),
112+
error = %e,
113+
"Invalid guardian public key"
114+
);
115+
continue;
116+
}
110117
};
111118

112119
let signature = match Signature::from_bytes(sig_bytes) {
113120
Ok(sig) => sig,
114-
Err(_) => continue,
121+
Err(e) => {
122+
tracing::debug!(
123+
error = %e,
124+
"Invalid signature format"
125+
);
126+
continue;
127+
}
115128
};
116129

117130
// Verify signature
118131
if pubkey.verify(message, &signature).is_ok() {
119132
signed_guardians.insert(guardian.pubkey);
120133
valid_count += 1;
134+
135+
tracing::debug!(
136+
guardian = %guardian.name,
137+
"Valid guardian signature verified"
138+
);
121139
break;
140+
} else {
141+
tracing::debug!(
142+
guardian = %guardian.name,
143+
"Signature verification failed for guardian"
144+
);
122145
}
123146
}
124147
}

crates/bitcell-governance/src/proposal.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ impl ProposalId {
1717
) -> Self {
1818
let mut hasher = Sha256::new();
1919
hasher.update(proposer);
20-
hasher.update(&bincode::serialize(proposal_type).unwrap_or_default());
20+
21+
// Serialize proposal type - use expect since this should never fail
22+
let type_bytes = bincode::serialize(proposal_type)
23+
.expect("Failed to serialize proposal type - this is a bug");
24+
hasher.update(&type_bytes);
25+
2126
hasher.update(description.as_bytes());
2227
hasher.update(&created_at.to_le_bytes());
2328

0 commit comments

Comments
 (0)