refactor: proof integration cleanup#1429
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThis PR renames ProofType enum variants from T-prefixed notation (T2, T5, T6) to C-prefixed notation (C4, C6, C7) and fixes a field name typo from Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
aff7d9e to
687b910
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/zk-prover/src/actors/share_verification.rs (1)
198-253: Cachesigned_proofs()once per passed party to avoid repeated allocations.The current implementation rebuilds cloned proof vectors multiple times per party across validation/address/hash steps. Consider caching once and reusing.
♻️ Suggested refactor
- let mut ecdsa_passed_parties = Vec::new(); + let mut ecdsa_passed_parties = Vec::new(); + let mut proofs_by_party: HashMap<u64, Vec<SignedProofPayload>> = HashMap::new(); @@ - for party in &party_proofs { - let proofs = party.signed_proofs(); - let result = - self.ecdsa_validate_signed_proofs(party.party_id(), &proofs, &e3_id_str, label); + for party in &party_proofs { + let party_id = party.party_id(); + let proofs = party.signed_proofs(); + let result = self.ecdsa_validate_signed_proofs(party_id, &proofs, &e3_id_str, label); if result.passed { ecdsa_passed_parties.push(party.clone()); + proofs_by_party.insert(party_id, proofs); } else { - ecdsa_dishonest.insert(party.party_id()); + ecdsa_dishonest.insert(party_id); if let Some((ref signed, addr)) = result.failed_payload { - self.emit_signed_proof_failed(&e3_id, signed, addr, party.party_id(), &ec); + self.emit_signed_proof_failed(&e3_id, signed, addr, party_id, &ec); } } } @@ - for party in &party_proofs { - if !ecdsa_dishonest.contains(&party.party_id()) { - let proofs = party.signed_proofs(); - if let Some(first_signed) = proofs.first() { + for party in &ecdsa_passed_parties { + let party_id = party.party_id(); + if let Some(proofs) = proofs_by_party.get(&party_id) { + if let Some(first_signed) = proofs.first() { if let Ok(addr) = first_signed.recover_address() { - party_addresses.insert(party.party_id(), addr); + party_addresses.insert(party_id, addr); } } } } @@ let mut party_proof_hashes: HashMap<u64, Vec<(ProofType, [u8; 32])>> = HashMap::new(); for party in &ecdsa_passed_parties { - let hashes: Vec<(ProofType, [u8; 32])> = party - .signed_proofs() - .iter() + let party_id = party.party_id(); + let Some(proofs) = proofs_by_party.get(&party_id) else { + continue; + }; + let hashes: Vec<(ProofType, [u8; 32])> = proofs + .iter() .map(|signed| { let msg = ( Bytes::copy_from_slice(&signed.payload.proof.data), Bytes::copy_from_slice(&signed.payload.proof.public_signals), ) .abi_encode(); (signed.payload.proof_type, keccak256(&msg).into()) }) .collect(); - party_proof_hashes.insert(party.party_id(), hashes); + party_proof_hashes.insert(party_id, hashes); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/zk-prover/src/actors/share_verification.rs` around lines 198 - 253, The code repeatedly calls party.signed_proofs() and clones the proof vectors multiple times; cache each passed party's signed_proofs once and reuse it for address recovery and proof-hash computation. After you build ecdsa_passed_parties, create a HashMap<u64, Vec<_>> (keyed by party.party_id()) populated with party.signed_proofs() for each party in ecdsa_passed_parties, then use that cached map instead of calling party.signed_proofs() again in the address-recovery loop and the party_proof_hashes construction; leave the existing failed-path that calls emit_signed_proof_failed / result.failed_payload unchanged. Ensure you reference ecdsa_passed_parties, party_addresses, party_proof_hashes, and ecdsa_validate_signed_proofs when applying the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/events/src/enclave_event/decryption_key_shared.rs`:
- Line 33: The serialized field was renamed to signed_e_sm_decryption_proofs
which will break deserialization of older payloads using
signed_esm_decryption_proofs; add a serde alias on the struct field declaration
(the field named signed_e_sm_decryption_proofs in the
DecryptionKeyShared/enclave_event struct in decryption_key_shared.rs) using
#[serde(alias = "signed_esm_decryption_proofs")] so both old and new names
deserialize correctly while keeping the Rust field name unchanged.
---
Nitpick comments:
In `@crates/zk-prover/src/actors/share_verification.rs`:
- Around line 198-253: The code repeatedly calls party.signed_proofs() and
clones the proof vectors multiple times; cache each passed party's signed_proofs
once and reuse it for address recovery and proof-hash computation. After you
build ecdsa_passed_parties, create a HashMap<u64, Vec<_>> (keyed by
party.party_id()) populated with party.signed_proofs() for each party in
ecdsa_passed_parties, then use that cached map instead of calling
party.signed_proofs() again in the address-recovery loop and the
party_proof_hashes construction; leave the existing failed-path that calls
emit_signed_proof_failed / result.failed_payload unchanged. Ensure you reference
ecdsa_passed_parties, party_addresses, party_proof_hashes, and
ecdsa_validate_signed_proofs when applying the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: cc496e8c-71c3-4fab-bc77-ad4f29e3d391
📒 Files selected for processing (9)
crates/events/src/enclave_event/compute_request/zk.rscrates/events/src/enclave_event/decryption_key_shared.rscrates/events/src/enclave_event/signed_proof.rscrates/keyshare/src/threshold_keyshare.rscrates/multithread/src/multithread.rscrates/trbfv/src/gen_pk_share_and_sk_sss.rscrates/zk-prover/src/actors/proof_request.rscrates/zk-prover/src/actors/share_verification.rspackages/enclave-contracts/test/Slashing/CommitteeExpulsion.spec.ts
fix #1380
Summary by CodeRabbit
Bug Fixes
Refactor
Chores