Skip to content

Smaller circuit terms - #151

Merged
frozenspider merged 6 commits into
mainfrom
fs/smaller-circuit-terms
Nov 17, 2026
Merged

frozenspider merged 6 commits into
mainfrom
fs/smaller-circuit-terms

Conversation

@frozenspider

@frozenspider frozenspider commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Resolves #44

Summary of changes:

  • Change coefficients in SHA-256 circuit from BigInt to i64 - this is safe to do as all coefficients are $\le 2^{35}$.
  • Relax BitzSemiring: From<u64> to From<u32>. This does not involve any kind of performance penalty, but lets i64 become BitzConstraintRing: BitzSemiring.
  • As a guardrail, check_witness and IntegerProducts::is_satisfied now perform check for arithmetics overflow.
  • As another guardrail, constraint generator now checks limb capacity of a ring at compile time.

Result:

Measured on my machine:
cargo run --release -p bitz-cli -- circuit-e2e --circuit sha256-2kb --threads 5

What Before After
Setup/Synthesize constraints ~420 ms ~300 ms
Setup/Prepare integer matrices ~290 ms ~210 ms
Peak RSS of circuit-e2e 270 MiB 186 MiB
Generator output matrices 95 MiB 54 MiB
Synthesis peak 132 MiB 89 MiB
Prepare integer matrices peak 159 MiB 89 MiB

cargo run --release -p bitz-cli -- circuit-e2e --circuit sha256-chain --num-blocks 600 --threads 5

What Before After
Setup/Synthesize constraints ~8.4 s ~6.9 s
Setup/Prepare integer matrices ~3.6 s ~1.3 s
Peak RSS of circuit-e2e 4790 MiB 3220 MiB
Generator output matrices 1781 MiB 1020 MiB
Synthesis peak 2328 MiB 1543 MiB
Prepare integer matrices peak 2889 MiB 1543 MiB

Other running time numbers are unaffected.

@frozenspider frozenspider changed the title [WIP] Smaller circuit terms Smaller circuit terms Nov 13, 2026
@frozenspider
frozenspider marked this pull request as ready for review November 13, 2026 15:14

@xrvdg xrvdg 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.

LGTM. I left one comment. Could you also review whether these tests are necessary? The project is accumulating generated unit tests that add little value. Just keep the ones that cover important behaviour and regressions.

Comment thread tooling/cli/src/lib.rs Resolved
Comment on lines +672 to +674
impl SignedLimbCapacity for BigInt {
const MAX_SIGNED_LIMBS: usize = usize::MAX;
}

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.

Do we still need BigInt or does this exist for comparison checking?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We no longer need dynamic size integer per se - BigInt constraint generators are test-only, and our circuits know their widest coefficient bound in advance.

However, replacing BigInt with fixed-size integer ring is outside of the scope. Might make sense to do as a follow-up though.

Comment thread tooling/cli/tests/circuits.rs Resolved
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.

Replace the BTreeMap and BTreeSet accumulators in LinearCombination

2 participants