Repository navigation
Conversation
Port the Pack, Bytes8 and Uint64 modules from midnight-apps contracts/src/math (7de45ab, identical to the audited commit 7e09763). The circuit code is unchanged. Only the header, the pragma (>= 0.26.0) and the module imports (relative paths) change. Add the test material in the compact-contracts layout: - mocks MockPack, MockBytes8 and MockUint64 with the source circuit names and disclose() calls, a test-only header, and a Counter write that keeps every circuit impure; - async simulators on @openzeppelin/compact-simulator; - test-only witnesses (PackWitnesses, Uint64Witnesses, sqrtBigint); - the source tests (139), converted to await every circuit call and to assert failures with expectRejection. Tests that replace a witness run on the dry backend only, because a live node binds the witnesses at deploy. The live backend deploys each mock once per file. The sqrt range test matches the compact-runtime 0.19.0 type error text.
Uint64._div checked the witness with (quotient * b + remainder) as Uint<64> == a. A witness with quotient * b + remainder above 2^64 - 1 failed in the implicit cast with a compiler cast error, not with the module message. Compare the sum as a Uint<128> without the cast, so every bad division witness fails with a "Uint64:" message. The check stays sound: quotient * b + remainder is at most 2^128 - 2^64, so the Uint<128> sum cannot wrap. Test: div(10, 4) with a witness that returns quotient 2^63 and remainder 2 fails with "Uint64: division invalid".
The doc comment of the internal circuit _toUint64 used the old name _vector8ToUint64. Use the real name. This is the Bytes8 part of audit finding N-01 (midnight-apps #312).
The sqrt doc comment described special cases for common inputs and a sqrtLocally function. Neither exists. The circuit takes the root from the wit_sqrtUint64 witness and verifies it. Describe that.
…int64 Convert the doc comments of the three modules to the repository style: @module and @description instead of @title, @dev for implementation notes, a Requirements list for every assert (with its failure message) instead of @throws, and @Constraints for the circuit size. The @Constraints values replace the old @circuitInfo values. They are the rows of the matching mock circuit, measured with compiler 0.34.0 for ZKIR v2 and v3 at this commit. The Pack values are per instance size. Doc comments only. The code is unchanged, and every mock circuit compiles to the same ZKIR as before this commit.
The base tsconfig.json includes only the witness files, so a type error in a math simulator, spec or test helper reached CI unreported. The new tsconfig.math-test.json includes every TypeScript file under src/math and emits nothing. The package build keeps its own include in tsconfig.build.json. yarn types runs both checks.
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Comment |
This was referenced Oct 14, 2026
The rows of _toUint64 were the rows of its exported wrapper, which documents them.
This was referenced Oct 15, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 2 of 13 of the math library migration from midnight-apps
contracts/src/math. Closes #214.Stack: #1125 → #1126 → #1127 → #1128 → #1140 → #1141 → #1142 → #1143 → #1144 → #1145 → #1146 → #1147 → #1148. Merge in order.
Summary
Adds the
Pack,Bytes8andUint64modules. The code is a copy of the audited source, with the repository conventions and two fixes. Names, signatures and failure messages do not change.Changes
Uint64division witness now fails withUint64: division invalid. Before this fix, it failed with a compiler cast error (82a1c291). This changes only the error message. The checks that reject the witness do not change.Bytes8circuit title. This is theBytes8part of audit finding N-01 in the May 2026 audit. The audit marks it resolved, but midnight-apps#312 is not merged (3693d805).Uint64.sqrtdescription (b727a7c2).tsconfig.math-test.json, a type check of all math TypeScript.yarn typesruns it, so CI runs it too (5530cce4). Open PR chore(contracts): type-check specs and simulators #897 also changes type checking, so the two PRs need a merge check.Bytes8._toUint64(fd2952d7).Tests that replace a witness run only on the simulator backend, because the live backend fixes witnesses at deploy.
Validation
Types of changes
PR Checklist