Skip to content

feat: optimize pipeline for nodes_fold and reuse of vk [skip-line-limit]#1581

Merged
0xjei merged 1 commit into
mainfrom
optimize/fold
Jun 5, 2026
Merged

feat: optimize pipeline for nodes_fold and reuse of vk [skip-line-limit]#1581
0xjei merged 1 commit into
mainfrom
optimize/fold

Conversation

@0xjei

@0xjei 0xjei commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Streaming nodes-fold proof aggregation pipeline enabling sequential DKG fold proof processing, eliminating the requirement to have all proofs available upfront before starting aggregation.
    • Extended DKG aggregation requests to support optional precomputed nodes-fold proofs for improved efficiency.
  • Refactor

    • Optimized verification key artifact loading to eliminate redundant disk I/O operations during fold accumulation.

@0xjei 0xjei self-assigned this Jun 5, 2026
@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
crisp Ready Ready Preview, Comment Jun 5, 2026 3:50pm
enclave-docs Ready Ready Preview, Comment Jun 5, 2026 3:50pm
enclave-enclave-dashboard Ready Ready Preview, Comment Jun 5, 2026 3:50pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fadd80a6-934e-42dc-a8ce-6c32c7e7bb3a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch optimize/fold

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
crates/aggregator/src/actors/publickey_aggregator.rs (1)

586-697: 💤 Low value

BTreeSet::iter().nth() has O(n) complexity per call.

Line 619 uses honest_party_ids.iter().nth(next_slot as usize) which is O(H) for each fold step. Across H steps, this results in O(H²) total iteration overhead. For typical committee sizes this is likely acceptable, but if H grows large, consider caching the sorted party IDs as a Vec<u64> once when entering GeneratingC5Proof to enable O(1) indexed access.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/aggregator/src/actors/publickey_aggregator.rs` around lines 586 - 697,
The code uses BTreeSet::iter().nth(next_slot) in try_dispatch_nodes_fold_step
(within PublicKeyAggregatorState::GeneratingC5Proof) which yields O(H) per
lookup causing O(H²) behavior; change the state to cache a Vec of sorted honest
IDs (e.g., add honest_party_ids_vec: Vec<u64> to
PublicKeyAggregatorState::GeneratingC5Proof or populate an existing vector when
entering that state) and replace honest_party_ids.iter().nth(next_slot as usize)
with direct indexed access honest_party_ids_vec[next_slot as usize]; ensure the
Vec is created once (when transitioning into GeneratingC5Proof) and used
everywhere that currently reads honest_party_ids by index.
crates/events/src/enclave_event/compute_request/zk.rs (1)

76-91: 💤 Low value

Type consistency: slot_index: u32 vs total_slots: usize.

The mixed integer types (slot_index: u32 and total_slots: usize) could cause subtle issues on platforms where usize differs from 32 bits, and requires explicit casts at comparison sites. Consider aligning both to the same type (either u32 or usize) for consistency.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/events/src/enclave_event/compute_request/zk.rs` around lines 76 - 91,
The struct NodesFoldStepRequest mixes slot_index: u32 and total_slots: usize
which can cause casts and platform differences; pick a single integer type
(recommend usize for counts/indexing or u32 if protocol guarantees 32-bit) and
make both fields the same type (change slot_index to usize or total_slots to
u32), then update all constructors, builders, serde/Serialize/Deserialize usage,
and any comparisons or arithmetic in functions that reference
NodesFoldStepRequest::{slot_index,total_slots} to use the unified type to avoid
repeated casts and platform-dependent bugs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/aggregator/src/domain/publickey_aggregation.rs`:
- Around line 209-214: The new required field nodes_fold_completed_slots (u32)
breaks deserialization of old snapshots; fix by making deserialization
backward-compatible: either add #[serde(default)] to nodes_fold_completed_slots
so missing values default to 0, or change its type to Option<u32> and treat None
as 0 at runtime. Update the GeneratingC5Proof variant (and any constructors/uses
of nodes_fold_completed_slots) to handle the default/Option (e.g., unwrap_or(0))
so existing logic continues to work.

---

Nitpick comments:
In `@crates/aggregator/src/actors/publickey_aggregator.rs`:
- Around line 586-697: The code uses BTreeSet::iter().nth(next_slot) in
try_dispatch_nodes_fold_step (within
PublicKeyAggregatorState::GeneratingC5Proof) which yields O(H) per lookup
causing O(H²) behavior; change the state to cache a Vec of sorted honest IDs
(e.g., add honest_party_ids_vec: Vec<u64> to
PublicKeyAggregatorState::GeneratingC5Proof or populate an existing vector when
entering that state) and replace honest_party_ids.iter().nth(next_slot as usize)
with direct indexed access honest_party_ids_vec[next_slot as usize]; ensure the
Vec is created once (when transitioning into GeneratingC5Proof) and used
everywhere that currently reads honest_party_ids by index.

In `@crates/events/src/enclave_event/compute_request/zk.rs`:
- Around line 76-91: The struct NodesFoldStepRequest mixes slot_index: u32 and
total_slots: usize which can cause casts and platform differences; pick a single
integer type (recommend usize for counts/indexing or u32 if protocol guarantees
32-bit) and make both fields the same type (change slot_index to usize or
total_slots to u32), then update all constructors, builders,
serde/Serialize/Deserialize usage, and any comparisons or arithmetic in
functions that reference NodesFoldStepRequest::{slot_index,total_slots} to use
the unified type to avoid repeated casts and platform-dependent bugs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c63a049b-3064-4935-8d7a-5120ecc3cb91

📥 Commits

Reviewing files that changed from the base of the PR and between 0997166 and 1151981.

📒 Files selected for processing (11)
  • crates/aggregator/src/actors/publickey_aggregator.rs
  • crates/aggregator/src/domain/publickey_aggregation.rs
  • crates/events/src/enclave_event/compute_request/mod.rs
  • crates/events/src/enclave_event/compute_request/zk.rs
  • crates/multithread/src/multithread.rs
  • crates/zk-prover/src/circuits/aggregation/c3_accumulator.rs
  • crates/zk-prover/src/circuits/aggregation/c6_accumulator.rs
  • crates/zk-prover/src/circuits/aggregation/node_dkg_fold.rs
  • crates/zk-prover/src/circuits/aggregation/nodes_fold_accumulator.rs
  • crates/zk-prover/src/lib.rs
  • crates/zk-prover/tests/fold_accumulators_e2e_tests.rs

Comment thread crates/aggregator/src/domain/publickey_aggregation.rs
@0xjei 0xjei marked this pull request as ready for review June 5, 2026 16:02
@0xjei 0xjei requested a review from ctrlc03 June 5, 2026 16:02
@0xjei 0xjei enabled auto-merge (squash) June 5, 2026 16:02

@ctrlc03 ctrlc03 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@0xjei 0xjei merged commit edb1477 into main Jun 5, 2026
34 checks passed
@ctrlc03 ctrlc03 deleted the optimize/fold branch June 5, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants