feat(circuits): add UTXOSettlement circom circuit#96
Conversation
Proves ownership of a UTXO note for a settlement intent using Poseidon hashing. Private inputs: secret, nonce, recipient, chainId, settlementModule Public inputs: nullifierHash, commitmentHash, amount, isMint Constraints: - nullifierHash == Poseidon(secret, nonce) - commitmentHash == Poseidon(secret, amount, isMint, recipient, chainId, settlementModule) - amount > 0 - isMint is binary 602 non-linear constraints. 6 witness tests passing. Next step: trusted setup (Powers of Tau) + snarkjs export Solidity verifier.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR introduces a new Circom circuit named ChangesUTXOSettlement Circuit and Test Infrastructure
Sequence DiagramsequenceDiagram
participant Test as Test Harness
participant Poseidon
participant WitnessCalc as Witness Calculator
participant Assert as Assertion
Test->>Poseidon: Initialize field and hash function
Test->>WitnessCalc: Load compiled circuit WASM
Test->>WitnessCalc: Create witness calculator instance
Test->>Poseidon: Hash (secret, nonce) → nullifierHash
Test->>Poseidon: Hash (secret, amount, isMint, recipient, chainId, settlementModule) → commitmentHash
Test->>WitnessCalc: Provide input with computed hashes
Test->>WitnessCalc: Calculate witness from private inputs
WitnessCalc-->>Test: Witness generated (valid) or throw (invalid)
Test->>Assert: Log PASS/FAIL based on constraint satisfaction
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Dependency ReviewThe following issues were found:
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@circuits/package.json`:
- Line 8: The current "test" npm script runs node test/UTXOSettlement.test.mjs
directly and assumes WASM/witness artifacts exist; update the package.json
"test" script (the scripts.test entry) to first invoke the project build (e.g.,
run the existing "build" script) and only then execute the test command so tests
are self-contained on clean checkouts/CI (e.g., change scripts.test to run the
build step then node test/UTXOSettlement.test.mjs).
In `@circuits/test/UTXOSettlement.test.mjs`:
- Line 3: The header comment at the top of UTXOSettlement.test.mjs contains a
stale run command referencing UTXOSettlement.test.js; update that comment so the
run command matches the actual file extension (change .js to .mjs) to avoid
confusion when running "node" or documentation readers trying to run the test.
- Around line 42-49: The test helper expectFail is treating any thrown exception
as a passing constraint failure; modify it so only known circuit constraint
failures are accepted and all other errors are rethrown (so unrelated issues
don't get masked). In practice, wrap the calcWitness call in try/catch, and in
the catch inspect the caught error from calcWitness (refer to expectFail and
calcWitness) — if the error message or type matches the expected circuit failure
pattern (e.g. contains "constraint", "assert", "witness", or the specific
runtime error your circuit library emits) log PASS, otherwise rethrow the error
so the test runner surfaces it.
🪄 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: ASSERTIVE
Plan: Pro Plus
Run ID: cebfe747-d17f-487d-8f63-94c45940778f
⛔ Files ignored due to path filters (1)
circuits/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (4)
circuits/.gitignorecircuits/package.jsoncircuits/test/UTXOSettlement.test.mjscircuits/utxo/UTXOSettlement.circom
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4bc698888a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Adds the UTXO settlement circuit for Groth16 proof generation.
Proves ownership of a UTXO note: nullifierHash = Poseidon(secret, nonce), commitmentHash = Poseidon(secret, amount, isMint, recipient, chainId, settlementModule). Amount > 0 and isMint binary are enforced as constraints.
602 non-linear constraints. 6 witness tests passing (valid inputs, wrong nullifier, wrong commitment, non-binary isMint, zero amount, burn direction).
Scope: circuits
Verification: circom 2.2.3 compiles clean. node test/UTXOSettlement.test.mjs passes.
Risk: Low. New directory only — no changes to contracts or existing code.
Summary by CodeRabbit
New Features
Tests
Chores