-
Notifications
You must be signed in to change notification settings - Fork 381
chore: document big integers #4487
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 all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bbe5bd5
document big integers
guipublic d700f5c
adding some suggestions, thanks gui
signorecello a1d5918
Merge branch 'master' into gd/issue_4205_bigint_doc
guipublic 46b88e4
Update docs/docs/noir/standard_library/bigint.md
guipublic 4aaeae0
Merge branch 'master' into gd/issue_4205_bigint_doc
guipublic 7eb9821
Merge branch 'master' into gd/issue_4205_bigint_doc
guipublic 9477d3e
add secpk and secpr to the dictionary
guipublic de03e9c
fix example
guipublic 2e0c681
Merge branch 'master' into gd/issue_4205_bigint_doc
guipublic 4e71f91
use code snippet for bigint doc
guipublic 9746288
Merge branch 'master' into gd/issue_4205_bigint_doc
guipublic e7825b3
comment ex. which does not verify (temporarily)
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,6 +154,8 @@ | |
| "sdiv", | ||
| "secp256k1", | ||
| "secp256r1", | ||
| "Secpk", | ||
| "Secpr", | ||
| "signedness", | ||
| "signorecello", | ||
| "smol", | ||
|
|
||
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,3 @@ | ||
| { | ||
| "no-missing-space-atx": false | ||
| } |
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,102 @@ | ||
| --- | ||
| title: Big Integers | ||
| description: How to use big integers from Noir standard library | ||
| keywords: | ||
| [ | ||
| Big Integer, | ||
| Noir programming language, | ||
| Noir libraries, | ||
| ] | ||
| --- | ||
|
|
||
| The BigInt module in the standard library exposes some class of integers which do not fit (well) into a Noir native field. It implements modulo arithmetic, modulo a 'big' prime number. | ||
|
|
||
| :::note | ||
|
|
||
| The module can currently be considered as `Field`s with fixed modulo sizes used by a set of elliptic curves, in addition to just the native curve. [More work](https://github.com/noir-lang/noir/issues/510) is needed to achieve arbitrarily sized big integers. | ||
|
|
||
| ::: | ||
|
|
||
| Currently 6 classes of integers (i.e 'big' prime numbers) are available in the module, namely: | ||
|
|
||
| - BN254 Fq: Bn254Fq | ||
| - BN254 Fr: Bn254Fr | ||
| - Secp256k1 Fq: Secpk1Fq | ||
| - Secp256k1 Fr: Secpk1Fr | ||
| - Secp256r1 Fr: Secpr1Fr | ||
| - Secp256r1 Fq: Secpr1Fq | ||
guipublic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Where XXX Fq and XXX Fr denote respectively the order of the base and scalar field of the (usual) elliptic curve XXX. | ||
| For instance the big integer 'Secpk1Fq' in the standard library refers to integers modulo $2^{256}-2^{32}-977$. | ||
|
|
||
| Feel free to explore the source code for the other primes: | ||
|
|
||
| #include_code curve_order_base noir_stdlib/src/bigint.nr rust | ||
|
|
||
| ## Example usage | ||
|
|
||
| A common use-case is when constructing a big integer from its bytes representation, and performing arithmetic operations on it: | ||
|
|
||
| #include_code big_int_example test_programs/execution_success/bigint/src/main.nr rust | ||
|
|
||
| ## Methods | ||
|
|
||
| The available operations for each big integer are: | ||
|
|
||
| ### from_le_bytes | ||
|
|
||
| Construct a big integer from its little-endian bytes representation. Example: | ||
|
|
||
| ```rust | ||
| let a = Secpk1Fq::from_le_bytes([x, y, 0, 45, 2]); | ||
| ``` | ||
|
|
||
| Sure, here's the formatted version of the remaining methods: | ||
|
|
||
| ### to_le_bytes | ||
|
|
||
| Return the little-endian bytes representation of a big integer. Example: | ||
|
|
||
| ```rust | ||
| let bytes = a.to_le_bytes(); | ||
| ``` | ||
|
|
||
| ### add | ||
|
|
||
| Add two big integers. Example: | ||
|
|
||
| ```rust | ||
| let sum = a + b; | ||
| ``` | ||
|
|
||
| ### sub | ||
|
|
||
| Subtract two big integers. Example: | ||
|
|
||
| ```rust | ||
| let difference = a - b; | ||
| ``` | ||
|
|
||
| ### mul | ||
|
|
||
| Multiply two big integers. Example: | ||
|
|
||
| ```rust | ||
| let product = a * b; | ||
| ``` | ||
|
|
||
| ### div | ||
|
|
||
| Divide two big integers. Note that division is field division and not euclidean division. Example: | ||
|
|
||
| ```rust | ||
| let quotient = a / b; | ||
| ``` | ||
|
|
||
| ### eq | ||
|
|
||
| Compare two big integers. Example: | ||
|
|
||
| ```rust | ||
| let are_equal = a == b; | ||
| ``` | ||
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
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.