Skip to content

feat(math): add UintN wrapping arithmetic - #1189

Draft
0xisk wants to merge 2 commits into
mainfrom
feat/math-uintn
Draft

0xisk wants to merge 2 commits into
mainfrom
feat/math-uintn

Conversation

@0xisk

@0xisk 0xisk commented Oct 21, 2026

Copy link
Copy Markdown
Member

Types of changes

What types of changes does your code introduce to OpenZeppelin Midnight Contracts?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Refs #727. #1183 stacks on this: its delivery pads become UintN<248>.

Draft until the test suite lands.

Not visible in the diff:

  • The category wiring (compile:math, its turbo task, the live-math pair) is build(math): add the math category scaffold (1/13) #1125's hunks verbatim, so the math stack rebases onto this as a no-op.
  • wrappingAdd tests a > MAX - b, with MAX cast from the constant MODULUS() - 1. Casting MODULUS() - 1 - b costs one more 248-bit range check (1126 vs 980 rows at 248). This form matches the pinned pad in feat(token): add confidential note delivery extension #1183 instruction for instruction.
  • MODULUS folds to a constant at every width, so the generic body costs nothing over a literal.

PR Checklist

Further comments

* build, ci: compile:math, its turbo task and the live pair copy #1125
  hunk for hunk, so the math stack rebases cleanly.
* math: the wrap test subtracts from the constant 2^N - 1, which at
  248 bits compiles to the same instructions and rows as a pinned
  literal pad.

Refs: #727
@coderabbitai

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@0xisk
0xisk added this pull request to stack #1190 October 21, 2026 14:29

This branch has not been deployed

No deployments
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