Skip to content

circomlib_binarynumber: add circuits/binnums, a BinaryNumber version of the library - #161

Open
miguelis wants to merge 1 commit into
iden3:circomlib_busesfrom
miguelis:circomlib_binarynumber
Open

miguelis wants to merge 1 commit into
iden3:circomlib_busesfrom
miguelis:circomlib_binarynumber

Conversation

@miguelis

Copy link
Copy Markdown

Adds circuits/binnums/, a second version of the library in which every port that carries a number as n bits is a BinaryNumber(n) bus instead of an array signal {binary} x[n]. Nothing in circuits/ changes: the array-based API stays as it is.

This replaces #160, which converted the existing templates in place.

What is in circuits/binnums/

  • Ports that become BinaryNumber(n) (bit i is x.bits[i], still tagged binary):
    • gates and arithmetic: MultiAND, BinSum, BinSub
    • multiplexers: Mux2..Mux4, MultiMux2..MultiMux4 (selector s)
    • bits: AliasCheck, CompConstant, Sign, BinaryCheckArray (output)
    • scalar multiplication: EscalarMul, EscalarMulWindow, EscalarMulAny, SegmentMulAny, EscalarMulFix, SegmentMulFix, WindowMulFix
    • Pedersen and EdDSA: Pedersen, Segment, Window4 (also pedersen_old), EdDSAPedersenVerifier (msg)
    • SHA-256: Sha256, Sha256compression, Ch_t, Maj_t, Xor3, RotR, ShR, SmallSigma, BigSigma, SigmaPlus, T1, T2, H, K
    • SMT: SMTLevIns (levIns), SMTProcessor and SMTProcessorSM (fnc)
  • Internal uses of Num2Bits/Bits2Num become Num2Bin/Bin2Num. Num2Bits, Bits2Num and their _strict variants keep their arrays.
  • A file is in binnums/ when its interface changes or when it includes one that does: 39 files, same layout as circuits/. Files that are not affected (buses, montgomery, mux1, switcher, poseidon*, escalarmulw4table, smt/smtbuses, smt/smthash_poseidon, the SMT level and verifier state machine files) are included from circuits/.
  • Template names are unchanged, so a circuit includes from circuits/ or from circuits/binnums/, never from both.

Tests

  • test/circuits/binnums/: the 42 test circuits that depend on a converted file, pointing to circuits/binnums/.
  • test/binnums/: the 22 JS tests that drive them; their describe names are suffixed (binnums).
  • npm test now runs test/*.js and test/binnums/*.js.
  • All test circuits compile with circom 2.2.3, and each binnums test circuit has the same constraint counts as its original.
  • npm test: 227 passing (118 existing + 109 binnums).

Documentation

  • circuits/README.md: new section describing binnums/, the converted templates and the rule about includes.
  • CHANGES.txt: one entry under Added.

🤖 Generated with Claude Code

…of the library

circuits/binnums/ holds a second version of the library in which every
port that carries a number as n bits is a BinaryNumber(n) bus instead of
`signal {binary} x[n]`, and the internal uses of Num2Bits/Bits2Num are
Num2Bin/Bin2Num. Nothing in circuits/ changes.

- Converted: MultiAND, BinSum, BinSub, Mux2..4, MultiMux2..4,
  AliasCheck, CompConstant, Sign, BinaryCheckArray (output), the
  scalar multiplication templates, Pedersen/Segment/Window4 (also
  pedersen_old), EdDSAPedersenVerifier (msg), the sha256 templates,
  SMTLevIns, SMTProcessor and SMTProcessorSM (fnc).
- A file is copied into binnums/ when its interface changes or when it
  includes one that does (39 files, same layout as circuits/). Files not
  affected (buses, montgomery, mux1, switcher, poseidon*, ...) are
  included from circuits/.
- Template names are unchanged, so a circuit includes from circuits/ or
  from circuits/binnums/, never both.
- Tests: test/circuits/binnums/ (42 circuits) and test/binnums/ (22 JS
  files, describe names suffixed "(binnums)"). npm test runs both sets.
- circuits/README.md and CHANGES.txt describe the new directory.

All test circuits compile with circom 2.2.3; each binnums test circuit has
the same constraint counts as its original. npm test: 227 passing
(118 existing + 109 binnums).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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