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

fix: to-bits and to-radix for > 128 bits #1312

Merged
merged 2 commits into from
May 11, 2023

Conversation

shuklaayush
Copy link
Contributor

@shuklaayush shuklaayush commented May 7, 2023

Related issue(s)

Resolves #1311
See #1109 (comment)

Description

Summary of changes

  • Avoid casting of opcode arguments to u128 before converting to bits or bytes
  • Allow to_radix_base to work for elements close to the modulus

Dependency additions / changes

Test additions / changes

Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt with default settings.
  • I have linked this PR to the issue(s) that it resolves.
  • I have reviewed the changes on GitHub, line by line.
  • I have ensured all changes are covered in the description.

Documentation needs

  • This PR requires documentation updates when merged.

Additional context

BEGIN_COMMIT_OVERRIDE
fix(stdlib): support use of to_bits and to_radix for values >128 bits (#1312)
END_COMMIT_OVERRIDE

Copy link
Contributor

@guipublic guipublic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am OK with replacing u128 with field elements for intrinsic arguments, but I am not sure your changes in the overflow check is correct. Could you provide a proof of correctness?

crates/noirc_evaluator/src/ssa/acir_gen/constraints.rs Outdated Show resolved Hide resolved
@shuklaayush
Copy link
Contributor Author

I reverted to the old overflow check based on the comments.

There are also a couple of other issues in the ToBits implementation:

  • It ignores the input endianness
  • It returns something even if the element wouldn't fit in the input bit_count. This is inconsistent with ToRadix which panics with ArrayOutOfBounds

I guess I can fix these in a follow-up PR once I know what the right behaviour should be.

@guipublic guipublic added this pull request to the merge queue May 11, 2023
Merged via the queue into noir-lang:master with commit 12f3e7e May 11, 2023
@shuklaayush shuklaayush deleted the fix/to-bits branch May 11, 2023 16:01
guipublic pushed a commit that referenced this pull request May 12, 2023
* fix: to-bits and to-radix for > 128 bits

* revert: use earlier overflow check that ensures unicity
TomAFrench added a commit that referenced this pull request May 17, 2023
* master: (66 commits)
  feat(nargo)!: retire print-acir in favour of flag (#1328)
  chore(ssa): enable cse for assert (#1350)
  chore(ssa refactor): Add basic instruction simplification (#1329)
  chore(noir): Release 0.6.0 (#1279)
  feat: enable to_radix for any field element (#1343)
  chore(ssa refactor): Simplify inlining pass and fix inlining failure (#1337)
  chore!: Update to acvm 0.11.0 (#1322)
  feat: Add ECDSA secp256k1 builtin test (#1294)
  chore: add support for encoding/decoding inputs from JSON (#1325)
  feat: Issue an error when attempting to use a `return` expression (#1330)
  chore(ssa refactor): Fix inlining bug (#1335)
  fix: to-bits and to-radix for > 128 bits (#1312)
  chore(parser): Parser error optimisation (#1292)
  chore(ssa refactor): Implement function inlining (#1293)
  chore: fix installation link in readme (#1326)
  chore: fix installation link in readme (#1326)
  feat(stdlib): Add keccak (#1249)
  fix: Parsing nested generics (#1319)
  chore(ssa refactor): Document some SSA-gen functions (#1321)
  fix: Assigning to tuple fields (#1318)
  ...
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.

Builtins to_bits and to_bytes only work for u128
3 participants