refactor: add pk_generation circuit#1268
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThis PR introduces a new PK generation circuit for threshold cryptography with full implementation support, updates import paths to conform to the new module structure, adds utility methods to polynomial types, and adjusts configuration constants for PK generation parameters. Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI/Main
participant Circuit as PkGenerationCircuit
participant Computation as Computation Layer
participant Codegen as Codegen Layer
participant Artifacts as Output Artifacts
CLI->>Circuit: generate_sample(preset, committee)
Circuit->>Computation: Witness::compute(preset, input)
Computation->>Computation: Bounds::compute(preset, committee)
Computation->>Computation: Bits::compute(bounds)
Computation->>Computation: Witness::compute(preset, input)
Computation-->>Circuit: PkGenerationComputationOutput
CLI->>Codegen: codegen(preset, sample_input)
Codegen->>Computation: Witness::compute()
Computation-->>Codegen: witness
Codegen->>Codegen: Configs::compute(preset, committee)
Codegen->>Codegen: generate_toml(witness)
Codegen->>Codegen: generate_configs(preset, configs)
Codegen-->>Artifacts: Artifacts {toml, configs}
Artifacts-->>CLI: Ready for proving
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@crates/polynomial/src/polynomial.rs`:
- Around line 307-310: The public method `Polynomial::remove` currently calls
`self.coefficients.remove(index)` which will panic on out-of-range indices;
change the API to perform a bounds-checked removal and return a safe result
(e.g., Option<Scalar> or Result<Scalar, RemoveError>) instead of panicking:
check `index < self.coefficients.len()` and if valid remove and return the
removed coefficient, otherwise return None or an appropriate Err; update the
`remove` method signature and any callers to handle the new return type and keep
the internal storage access via `self.coefficients` and the method name
`remove`.
In `@crates/zk-helpers/src/circuits/threshold/pk_generation/computation.rs`:
- Around line 260-390: The parallel map using par_bridge() produces results
out-of-order so the tuple index (i) must be used to restore limb order before
building CRTs; sort the collected results Vec by the first element (the index)
or place each tuple into a Vec sized to moduli and write by index, then iterate
in index order when calling r2.add_limb, r1.add_limb, pk_share.add_limb,
a.add_limb and e_sm.add_limb (refer to the local variable results and the loop
that currently uses (_i, r2i, r1i, pk_sharei, ai, e_smi)); this preserves the
correspondence between limbs and moduli and fixes the scrambled CRT assembly.
In `@crates/zk-helpers/src/circuits/threshold/pk_generation/sample.rs`:
- Around line 26-67: The three unwrap() calls in generate_sample
(build_pair_for_preset(...).unwrap(), CommonRandomPoly::new(...).unwrap(), and
PublicKeyShare::new_extended(...).unwrap()) must be changed to propagate errors
instead of panicking: use ? where the called function returns a compatible
Result, or use map_err/and_then to convert the external error into
CircuitsErrors and then ? it (e.g., handle build_pair_for_preset,
CommonRandomPoly::new, and PublicKeyShare::new_extended results and return
Err(CircuitsErrors::from(...)) or map_err(|e| CircuitsErrors::from(e)) as
needed) so generate_sample returns Err on failure rather than calling unwrap.
…tation - Sort par_bridge() results by index so limbs match moduli order - Prevents scrambled CRT assembly when building r2, r1, pk_share, a, e_sm Co-authored-by: Cursor <cursoragent@cursor.com>
6480427 to
793ee23
Compare
Re #1259
Summary by CodeRabbit
Release Notes
New Features
add_limb()andremove()methods for polynomial operations.Bug Fixes
Chores