Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not always use checked arithmetic #6623

Open
sirasistant opened this issue Nov 26, 2024 · 2 comments
Open

Do not always use checked arithmetic #6623

sirasistant opened this issue Nov 26, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@sirasistant
Copy link
Contributor

Problem

Checked arithmetic has extra cost, both in constrained and unconstrained. We could both offer the user unchecked arithmetic blocks similarly to solidity, and have compiler issued operations like loop counter arithmetic be unchecked.

Happy Case

  • SSA operations can be checked or unchecked so we can issue unchecked operations where we know no overflow is possible (loops, for example)
  • Users can write unchecked {} blocks to denote which arithmetic operations don't need overflow checks. These will issue unchecked SSA ops.

Unchecked operations in Brillig can use native arithmetic saving on bytecode size and execution cost. Unchecked operations in ACIR can be cheaper by chaining operations without truncating until we need to truncate to avoid overflowing the field.

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@Savio-Sou
Copy link
Collaborator

Unchecked<{integer}> could be a potential happy case as well

@olehmisar
Copy link

i would prefer .unchecked_{add,sub,mul,div} or .wrapping_{add,sub,mul,div}, whichever name is more appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants