-
Notifications
You must be signed in to change notification settings - Fork 615
feat: implement bigint in Noir, using bigint opcodes #4198
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b64b09b
Add big int opcodes (without implementation)
guipublic 4142afb
Merge branch 'master' into gd/bigint_opcode
guipublic 5aa2cb8
Merge branch 'master' into gd/bigint_opcode
guipublic 6c4c451
Use id to identify bigints between Noir and BB
guipublic d7803df
fix build
guipublic 50939d0
chore: add unit test for BB big integer opcode implementation (#4177)
guipublic ed3c537
Merge branch 'master' into gd/bigint_opcode
kevaundray 7727b3e
using bigintegers opcodes in Noir
guipublic 780d17a
Merge branch 'gd/bigint_opcode' into gd/implement_bigint
guipublic 667d224
Merge branch 'master' into gd/bigint_opcode
guipublic 27b8863
Merge branch 'gd/bigint_opcode' into gd/implement_bigint
guipublic d03b94d
fix build issue
guipublic b091214
Merge branch 'gd/bigint_opcode' into gd/implement_bigint
guipublic 81babc1
fix the build (2)
guipublic 96185fc
Merge branch 'gd/bigint_opcode' into gd/implement_bigint
guipublic 9302cdd
Merge branch 'master' into gd/implement_bigint
guipublic d64f43c
Merge branch 'master' into gd/implement_bigint
guipublic 619b1e7
Update noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generat…
kevaundray 5b48184
code review
guipublic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| pub(crate) mod acir_variable; | ||
| pub(crate) mod big_int; | ||
| pub(crate) mod generated_acir; | ||
| pub(crate) mod sort; |
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
54 changes: 54 additions & 0 deletions
54
noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/big_int.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| use acvm::FieldElement; | ||
| use num_bigint::BigUint; | ||
|
|
||
| /// Represents a bigint value in the form (id, modulus) where | ||
| /// id is the identifier of the big integer number, and | ||
| /// modulus is the identifier of the big integer size | ||
| #[derive(Default, Clone, Copy, Debug)] | ||
| pub(crate) struct BigIntId(pub(crate) u32, pub(crate) u32); //bigint id, modulus id | ||
|
guipublic marked this conversation as resolved.
Outdated
|
||
|
|
||
| impl BigIntId { | ||
| pub(crate) fn as_field(&self) -> FieldElement { | ||
| FieldElement::from(self.0 as u128) | ||
| } | ||
|
guipublic marked this conversation as resolved.
Outdated
|
||
|
|
||
| pub(crate) fn modulus_id(&self) -> FieldElement { | ||
| FieldElement::from(self.1 as u128) | ||
| } | ||
| } | ||
|
|
||
| /// BigIntContext is used to generate identifiers for big integers and their modulus | ||
| #[derive(Default, Debug)] | ||
| pub(crate) struct BigIntContext { | ||
| modulus: Vec<BigUint>, | ||
| big_integers: Vec<BigIntId>, | ||
| } | ||
|
|
||
| impl BigIntContext { | ||
| /// Creates a new BigIntId for the given modulus and returns it. | ||
| pub(crate) fn new_big_int(&mut self, modulus: FieldElement) -> BigIntId { | ||
| let id = self.big_integers.len() as u32; | ||
| let result = BigIntId(id, modulus.to_u128() as u32); | ||
|
guipublic marked this conversation as resolved.
Outdated
|
||
| self.big_integers.push(result); | ||
| result | ||
| } | ||
|
|
||
| /// Returns the modulus corresponding to the given modulus index | ||
| pub(crate) fn modulus(&self, idx: FieldElement) -> BigUint { | ||
| self.modulus[idx.to_u128() as usize].clone() | ||
| } | ||
|
|
||
| /// Returns the BigIntId corresponding to the given identifier | ||
| pub(crate) fn get(&self, id: FieldElement) -> BigIntId { | ||
| self.big_integers[id.to_u128() as usize] | ||
| } | ||
|
|
||
| /// Adds a modulus to the context (if it is not already present) | ||
| pub(crate) fn get_or_insert_modulus(&mut self, modulus: BigUint) -> u32 { | ||
| if let Some(pos) = self.modulus.iter().position(|x| x == &modulus) { | ||
| return pos as u32; | ||
| } | ||
| self.modulus.push(modulus); | ||
| (self.modulus.len() - 1) as u32 | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.