Skip to content

circomlib_binarynumber: use BinaryNumber buses for binary ports - #160

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

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

Conversation

@miguelis

Copy link
Copy Markdown

Converts the ports that carry a number in binary from arrays of {binary} signals to the BinaryNumber(n) bus, and replaces internal uses of Num2Bits/Bits2Num with Num2Bin/Bin2Num.

Changes

  • Ports now BinaryNumber(n) (previously signal {binary} x[n]):
    • gates: MultiAND
    • multiplexers: Mux2..Mux4, MultiMux2..MultiMux4 (selector s). Mux1/MultiMux1 keep their single-bit selector.
    • binary arithmetic: BinSum, BinSub
    • comparators: CompConstant, Sign; and AliasCheck
    • BinaryCheckArray (output)
    • scalar multiplication: EscalarMul, EscalarMulWindow, EscalarMulAny, SegmentMulAny, EscalarMulFix, SegmentMulFix, WindowMulFix
    • Pedersen: Pedersen, Segment, Window4 (also pedersen_old)
    • EdDSA: EdDSAPedersenVerifier (msg)
    • SHA-256: Sha256, Sha256compression, Ch_t, Maj_t, Xor3, RotR, ShR, SmallSigma, BigSigma, SigmaPlus, T1, T2, H, K. Sha256_2 keeps its ports.
    • SMT: SMTLevIns (levIns), SMTProcessor and SMTProcessorSM (fnc)
  • Num2Bits → Num2Bin in babyjub, comparators, eddsaposeidon, pointbits, sha256_2 and MinValueCheck/MinMaxValueCheck. In pointbits the AliasCheck calls that followed Num2Bits(254) are removed, because Num2Bin(254) already performs the alias check.
  • AliasCheck keeps its CompConstant implementation; only its input becomes BinaryNumber(maxbits()).
  • Num2Bits, Bits2Num and their _strict variants keep their array interface.

Ports that carried n bits as `signal {binary} x[n]` are now
`BinaryNumber(n)` buses, and internal uses of Num2Bits/Bits2Num are
replaced by Num2Bin/Bin2Num.

- Converted templates: MultiAND, Mux2..4, MultiMux2..4, BinSum, BinSub,
  CompConstant, Sign, AliasCheck, BinaryCheckArray (output),
  EscalarMul*, SegmentMul*, WindowMulFix, Pedersen, Segment, Window4,
  EdDSAPedersenVerifier (msg), the sha256 templates, SMTLevIns,
  SMTProcessor and SMTProcessorSM (fnc).
- Num2Bits -> Num2Bin in babyjub, comparators, eddsaposeidon, pointbits,
  sha256_2 and MinValueCheck/MinMaxValueCheck. In pointbits the explicit
  AliasCheck is dropped, since Num2Bin(254) already performs it.
- AliasCheck keeps the CompConstant implementation; only its input
  becomes BinaryNumber(maxbits()).
- Test circuits updated to the new interfaces; the JS tests are
  unchanged apart from one comment.
- CHANGES.txt: template counts, the reshaped-ports list and a new
  migration note 7. Docstrings and circuits/README.md updated.

All 52 test circuits compile with circom 2.2.3 with the same constraint
counts as before; npm test: 118 passing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@miguelis

Copy link
Copy Markdown
Author

Closing this: I'll resubmit the BinaryNumber versions as a separate set under circuits/binnums/ instead of replacing the existing templates, so the array-based API stays as it is.

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