Skip to content

feat(circuits): add UTXOSettlement circom circuit#96

Merged
iap merged 2 commits into
devfrom
feat/utxo-circuit
May 11, 2026
Merged

feat(circuits): add UTXOSettlement circom circuit#96
iap merged 2 commits into
devfrom
feat/utxo-circuit

Conversation

@iap
Copy link
Copy Markdown
Contributor

@iap iap commented May 11, 2026

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

    • Added a UTXO Settlement circuit to validate UTXO ownership and settlement intent.
  • Tests

    • Added a node-based witness test suite covering valid and failing scenarios (amount, nullifier/commitment, isMint).
  • Chores

    • Added package configuration and scripts for building/testing circuits.
    • Added ignore rules for circuit build output, dependencies, and common artifact files.

Review Change Stack

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.
@iap iap requested a review from a team as a code owner May 11, 2026 07:34
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 33fbc6c4-7a76-400f-96c2-70e8f50ccdeb

📥 Commits

Reviewing files that changed from the base of the PR and between 4bc6988 and 61cd180.

📒 Files selected for processing (1)
  • contracts/foundry.toml

Walkthrough

This PR introduces a new Circom circuit named UTXOSettlement that proves UTXO note ownership and validity bound to settlement intents. The circuit is accompanied by build configuration, a comprehensive witness test suite validating constraint enforcement, and project setup files.

Changes

UTXOSettlement Circuit and Test Infrastructure

Layer / File(s) Summary
Circuit Constraints
circuits/utxo/UTXOSettlement.circom
UTXOSettlement template enforces binary isMint, non-zero amount, Poseidon-based nullifierHash from (secret, nonce), and commitmentHash from (secret, amount, isMint, recipient, chainId, settlementModule). Main component exposes [nullifierHash, commitmentHash, amount, isMint] as public inputs.
Package and Build Setup
circuits/package.json
Declares @mark/circuits package with build script targeting utxo/UTXOSettlement.circom and test script running witness validation. Runtime dependency on circomlib@2.0.5; dev dependencies on circomlibjs and snarkjs for hashing and proof handling.
Witness Test Suite
circuits/test/UTXOSettlement.test.mjs
Node.js harness initializes Poseidon, loads compiled WASM and witness calculator, defines assertion helpers (expectPass, expectFail), constructs test vectors, derives expected hashes via Poseidon, and executes test cases validating hash correctness, binary isMint enforcement, non-zero amount enforcement, and burn case (isMint=0). Logs per-test results and terminates on unexpected outcomes.
Project Configuration
circuits/.gitignore, contracts/foundry.toml
Excludes build artifacts (build/), dependencies (node_modules/), and circuit outputs (*.zkey, *.ptau, witness.wtns); adds trailing newline to contracts/foundry.toml.

Sequence Diagram

sequenceDiagram
  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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • trade/mark#92: Adds Groth16SettlementVerifier that decodes and validates proofs generated by the UTXOSettlement circuit's public output signals [nullifierHash, commitmentHash, amount, isMint].

Poem

🐰 A rabbit hops through circuits new,
With Poseidon hashes clear and true,
Witnesses whisper, constraints align,
Nullifiers, commitments — proofs that shine,
Settlement hums; the circuit's through.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provides technical details about the circuit but omits several required template sections including Scope checkboxes, Verification checklists, Risk Review items, Governance checks, and explicit Linked Context. Complete the PR description using the required template: add checked/unchecked Scope items, verification steps, risk review acknowledgments, governance confirmations, and linked issue/PR references.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a UTXOSettlement circom circuit, which matches the primary objective of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/utxo-circuit

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 11, 2026

Dependency Review

The following issues were found:

  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ✅ 0 package(s) with unknown licenses.
  • ⚠️ 19 packages with OpenSSF Scorecard issues.

View full job summary

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6c02586 and 4bc6988.

⛔ Files ignored due to path filters (1)
  • circuits/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • circuits/.gitignore
  • circuits/package.json
  • circuits/test/UTXOSettlement.test.mjs
  • circuits/utxo/UTXOSettlement.circom

Comment thread circuits/package.json
Comment thread circuits/test/UTXOSettlement.test.mjs
Comment thread circuits/test/UTXOSettlement.test.mjs
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 11, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment thread circuits/utxo/UTXOSettlement.circom
Comment thread circuits/package.json
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.

1 participant