You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-14Lines changed: 39 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,15 +15,29 @@ bignum can evaluate large integer arithmetic by defining a modulus() that is a p
15
15
16
16
## High level overview
17
17
18
-
This library provides modular arithmetic operations for big numbers. The Noir std library provides integers up to 128 bits and a field type up to 254 bits; this library supports arbitrary length numbers.
18
+
This library provides modular arithmetic operations for big numbers. The Noir std library provides integers up to 128 bits and a field type up to 254 bits; this library supports arbitrary length numbers.
19
+
20
+
A number of pre-defined bignum and finite field types are provided. If you need a bignum or finite field that's not on this list, this repo also provides the tools you'll need to generate your own.
21
+
22
+
See `./src/lib.nr` for the list of exported bignums.
23
+
24
+
See `./src/fields/` for files which shows how those bignums were created; you can copy this approach to generate your own bignums.
19
25
20
26
More details about this library are described in the rest of this document, this is just a quick high level overview.
21
27
22
-
To start using the library you need to do 2 things:
28
+
To start using the library:
29
+
30
+
If the bignum you need is in the pre-defined list, import it and use it:
31
+
32
+
```rust
33
+
usedep::bignum::U256;
34
+
```
35
+
36
+
If the bignum you need is not in the pre-defined list, you'll need to create it:
23
37
1. Define or import a **parameter set** with info about your modulus
24
38
2. Define the correct **type** for your big number
25
39
26
-
For step 1, the library contains parameters for predefined fields or integer types. Otherwise, you can define your own parameters; instructions on how to do this can be found below.
40
+
Instructions on how to do this can be found below.
27
41
28
42
Step 2 depends on when you know your modulus; this can be either at compile-time or runtime. Use the correct type for your situation:
29
43
*`BigNum`, if modulus is known at compile-time
@@ -48,34 +62,45 @@ In your _Nargo.toml_ file, add the version of this library you would like to ins
48
62
bignum = { tag = "v0.4.2", git = "https://github.com/noir-lang/noir-bignum" }
49
63
```
50
64
51
-
### Import
65
+
### Import a pre-defined bignum:
52
66
53
67
Add imports at the top of your Noir code, for example:
54
68
55
69
```rust
56
-
usebignum::fields::U256::U256Params;
57
-
usebignum::BigNum;
70
+
usedep::bignum::U256;
58
71
```
59
-
### Quick example: Addition in U256
60
72
61
-
A simple 1 + 2 = 3 check in 256-bit unsigned integers. Note that for performing multiple arithmetic operations up to degree 2 it is recommended to use `evaluate_quadratic_expression` (see explanation below).
73
+
### Create a custom bignum:
62
74
63
-
```rust
75
+
> We use U256 as an illustrative example, even though it's actually a pre-defined bignum.
76
+
77
+
Use the paramgen tool to generate your bignum's params (see below). Then define your custom bignum from those params:
64
78
65
-
usebignum::fields::U256::U256Params;
66
-
usebignum::BigNum;
79
+
```rust
80
+
usedep::bignum::fields::U256::U256Params;
81
+
usedep::bignum::BigNum;
67
82
68
83
// Define (compile-time) BigNum type
69
84
// number of limbs, number of bits of modulus, parameter set
70
85
typeU256=BigNum<3, 257, U256Params>;
86
+
```
87
+
88
+
### Quick example: Addition in U256
89
+
90
+
A simple 1 + 2 = 3 check in 256-bit unsigned integers. Note that for performing multiple arithmetic operations up to degree 2 it is recommended to use `evaluate_quadratic_expression` (see explanation below).
0 commit comments