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

chore: add examples and readme updates from hc #15

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
441 changes: 321 additions & 120 deletions README.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
These examples will be moved to another repo so that they can be tested/updated.
`nargo` currently ascends the directory structure to the highest found Nargo.toml file.
8 changes: 8 additions & 0 deletions examples/custom_modulus_example/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "custom_modulus_example"
type = "bin"
authors = [""]
compiler_version = ">=0.34.0"

[dependencies]
bignum = { path = "../.." }
82 changes: 82 additions & 0 deletions examples/custom_modulus_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Custom (compile-time) modulus example

This example assumes you have a modulus of 2048 bits and want to use it at compile-time.

## Generate parameters

Generate parameters for BigNum library using the [paramgen tool](https://github.com/noir-lang/noir-bignum-paramgen). After cloning and building the repo, run for the desired modulus (replace value):
```
./target/release/paramgen instance 20456684803303048347530423697020751814399302502110667150078323718905269101172974800905356684386150937514420094865028635518785372677390301711491016948450207607846221304930728973797522378506999567139943652134234877561436074026268205649910255182621594085008284441316448901381890082286184776564686504132516001962221244304143672537300570792891349927421038112529453088606957312408143395552575078898208723518244571879698149587589463599543806422441264913231441141752207832659135584572831493077819920330893012366189267930979049769425009576366557305457228626690969723792844542486959558350660501921357172974372066702504546151411 RSA2048_example > out.txt
```

Result:
```rust
struct RSA2048_example_Params {}
impl RuntimeBigNumParamsTrait<18> for RSA2048_example_Params {
pub fn modulus_bits() -> u64 {
2048
}
}
impl BigNumParamsTrait<18> for RSA2048_example_Params {
pub fn get_instance() -> BigNumInstance<18, Self> {
RSA2048_example_Instance
}
pub fn modulus_bits() -> u64 {
2048
}
}
global RSA2048_example_Instance: BigNumInstance<18, RSA2048_example_Params> = BigNumInstance {
modulus: [
0xca067270cbaa2f334deca1472a2bf3, 0x6610de1958b4206e3e34a14af22618, 0xe59e76000fcfb05956e5503a499841, 0x3d429c951fdec78afafacd2381782c, 0x617806aa0cf2d15b8c2a41bfd38ed9, 0xa4a58ff8737791b2d5571ea75c92d3, 0x49f85ae321bfbc161162bc1034f586, 0xa40bf68ca724dff0cf63605975cf48, 0xd5c5fe2ab9a1adf232351085a7d591, 0x1b0d1c9077b8f0794b2cb4af4d294f, 0x9401a841ae63b1f566fd6b69e62ccd, 0xd6958bad7bcf453c6cb489538831e0, 0x51bdf4c4cd4c92887a1d178d6bc3ce, 0xd153e9c43d7aa9b0d7a2c1af84ea38, 0x9deb9b61f4e25c1bd0d53e4e0e61e1, 0xbed33da20e52d7c916d486f235202b, 0x0c541718be73e9ce00f430c086b205, 0xa2
],
double_modulus: [
0x01940ce4e197545e669bd9428e5457e6, 0x01cc21bc32b16840dc7c694295e44c30, 0x01cb3cec001f9f60b2adcaa074933081, 0x017a85392a3fbd8f15f5f59a4702f058, 0x01c2f00d5419e5a2b71854837fa71db1, 0x01494b1ff0e6ef2365aaae3d4eb925a5, 0x0193f0b5c6437f782c22c5782069eb0c, 0x014817ed194e49bfe19ec6c0b2eb9e8f, 0x01ab8bfc5573435be4646a210b4fab22, 0x01361a3920ef71e0f29659695e9a529e, 0x01280350835cc763eacdfad6d3cc5999, 0x01ad2b175af79e8a78d96912a71063c0, 0x01a37be9899a992510f43a2f1ad7879c, 0x01a2a7d3887af55361af45835f09d46f, 0x013bd736c3e9c4b837a1aa7c9c1cc3c2, 0x017da67b441ca5af922da90de46a4056, 0x0118a82e317ce7d39c01e861810d640a, 0x0143
],
modulus_u60: U60Repr { limbs: ArrayX { segments: [[
0x034deca1472a2bf3, 0x0ca067270cbaa2f3, 0x0e3e34a14af22618, 0x06610de1958b4206, 0x0956e5503a499841, 0x0e59e76000fcfb05, 0x0afafacd2381782c, 0x03d429c951fdec78, 0x0b8c2a41bfd38ed9, 0x0617806aa0cf2d15, 0x02d5571ea75c92d3, 0x0a4a58ff8737791b, 0x061162bc1034f586, 0x049f85ae321bfbc1, 0xcf63605975cf48, 0x0a40bf68ca724dff, 0x0232351085a7d591, 0x0d5c5fe2ab9a1adf], [0x094b2cb4af4d294f, 0x01b0d1c9077b8f07, 0x0566fd6b69e62ccd, 0x09401a841ae63b1f, 0x0c6cb489538831e0, 0x0d6958bad7bcf453, 0x087a1d178d6bc3ce, 0x051bdf4c4cd4c928, 0xd7a2c1af84ea38, 0x0d153e9c43d7aa9b, 0x0bd0d53e4e0e61e1, 0x09deb9b61f4e25c1, 0x0916d486f235202b, 0x0bed33da20e52d7c, 0x0e00f430c086b205, 0xc541718be73e9c, 0xa2, 0x00]] } },
modulus_u60_x4: U60Repr { limbs: ArrayX { segments: [[
0x034deca1472a2bf3, 0x0ca067270cbaa2f3, 0x0e3e34a14af22618, 0x06610de1958b4206, 0x0956e5503a499841, 0x0e59e76000fcfb05, 0x0afafacd2381782c, 0x03d429c951fdec78, 0x0b8c2a41bfd38ed9, 0x0617806aa0cf2d15, 0x02d5571ea75c92d3, 0x0a4a58ff8737791b, 0x061162bc1034f586, 0x049f85ae321bfbc1, 0xcf63605975cf48, 0x0a40bf68ca724dff, 0x0232351085a7d591, 0x0d5c5fe2ab9a1adf], [0x094b2cb4af4d294f, 0x01b0d1c9077b8f07, 0x0566fd6b69e62ccd, 0x09401a841ae63b1f, 0x0c6cb489538831e0, 0x0d6958bad7bcf453, 0x087a1d178d6bc3ce, 0x051bdf4c4cd4c928, 0xd7a2c1af84ea38, 0x0d153e9c43d7aa9b, 0x0bd0d53e4e0e61e1, 0x09deb9b61f4e25c1, 0x0916d486f235202b, 0x0bed33da20e52d7c, 0x0e00f430c086b205, 0xc541718be73e9c, 0xa2, 0x00], [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]] } },
redc_param: [
0x1fdcdafc0b4a1e7e76fea4d047f13c, 0xe9f3127f19f73583a5378c5e3fb4a4, 0x61d4721841efbeac85a785dd48b58e, 0x747ed55336a2218c1f011c5f730478, 0xf8e29e2ca49c4df7aa57cc4defb877, 0x67541ffb558ce4fea6409c61e5b96a, 0xc616b60523693e15226453d9c1a735, 0x8e609df55b7e417c40ec232ac85f2c, 0xec4a3a8702ea1a8836d5bf2d63dc4c, 0x73ee26edb819fac7c1a771ed2d2447, 0x84e660e9c009e0eadd88a0c2d957c5, 0xb9c718c32762b643b6c29606ea3766, 0x9077b6f87aa1ba000b853a4841ea29, 0x28e68f0218123e2f911bfe4f2afdb1, 0xc45f6a9c6e8f5c18e38415b847eba6, 0xfd74428019998d5f69bda9954cd6d4, 0x6c48d17d943d2d123a0cb7f1044254, 0x0194
]
};
```

## Add parameters to file

Create a file `src/custom_params.nr` and add the generated code.

Slightly adjust parameters:
- remove the `pub` keywords
- add dependencies
- change return type of `modulus_bits` to `u32`
- add to `RuntimeBigNumParamsTrait` and `BigNumParamsTrait`:
```rust
fn has_multiplicative_inverse() -> bool { false }
```
> Note: if you are generating modulus parameters for a field, this is not needed since the multiplicative inverse exists for all elements.

## Use the params in Noir program

Import the parameters like this:
```rust
use custom_params::RSA2048_example_Params;
```

and define the type of the BigNums for this modulus:
```rust
type RSA2048 = BigNum<18, RSA2048_example_Params>;
```

Now arithmetic operations can be performed:
```rust
fn main(a: RSA2048, b: RSA2048, expected: RSA2048) {
let c = a + b; // modular addition (constrained)
assert(c == expected);
}
```

Test this function
```
nargo test
```
39 changes: 39 additions & 0 deletions examples/custom_modulus_example/src/custom_params.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use dep::bignum::BigNum;
use dep::bignum::BigNumParamsTrait;
use dep::bignum::runtime_bignum::BigNumInstance;
use dep::bignum::runtime_bignum::BigNumParamsTrait as RuntimeBigNumParamsTrait;
use dep::bignum::utils::u60_representation::U60Repr;
use dep::bignum::utils::arrayX::ArrayX;

struct RSA2048_example_Params {}
impl RuntimeBigNumParamsTrait<18> for RSA2048_example_Params {
fn modulus_bits() -> u32 {
2048
}
fn has_multiplicative_inverse() -> bool { false }
}
impl BigNumParamsTrait<18> for RSA2048_example_Params {
fn get_instance() -> BigNumInstance<18, Self> {
RSA2048_example_Instance
}
fn modulus_bits() -> u32 {
2048
}
fn has_multiplicative_inverse() -> bool { false }
}
global RSA2048_example_Instance: BigNumInstance<18, RSA2048_example_Params> = BigNumInstance {
modulus: [
0xca067270cbaa2f334deca1472a2bf3, 0x6610de1958b4206e3e34a14af22618, 0xe59e76000fcfb05956e5503a499841, 0x3d429c951fdec78afafacd2381782c, 0x617806aa0cf2d15b8c2a41bfd38ed9, 0xa4a58ff8737791b2d5571ea75c92d3, 0x49f85ae321bfbc161162bc1034f586, 0xa40bf68ca724dff0cf63605975cf48, 0xd5c5fe2ab9a1adf232351085a7d591, 0x1b0d1c9077b8f0794b2cb4af4d294f, 0x9401a841ae63b1f566fd6b69e62ccd, 0xd6958bad7bcf453c6cb489538831e0, 0x51bdf4c4cd4c92887a1d178d6bc3ce, 0xd153e9c43d7aa9b0d7a2c1af84ea38, 0x9deb9b61f4e25c1bd0d53e4e0e61e1, 0xbed33da20e52d7c916d486f235202b, 0x0c541718be73e9ce00f430c086b205, 0xa2
],
double_modulus: [
0x01940ce4e197545e669bd9428e5457e6, 0x01cc21bc32b16840dc7c694295e44c30, 0x01cb3cec001f9f60b2adcaa074933081, 0x017a85392a3fbd8f15f5f59a4702f058, 0x01c2f00d5419e5a2b71854837fa71db1, 0x01494b1ff0e6ef2365aaae3d4eb925a5, 0x0193f0b5c6437f782c22c5782069eb0c, 0x014817ed194e49bfe19ec6c0b2eb9e8f, 0x01ab8bfc5573435be4646a210b4fab22, 0x01361a3920ef71e0f29659695e9a529e, 0x01280350835cc763eacdfad6d3cc5999, 0x01ad2b175af79e8a78d96912a71063c0, 0x01a37be9899a992510f43a2f1ad7879c, 0x01a2a7d3887af55361af45835f09d46f, 0x013bd736c3e9c4b837a1aa7c9c1cc3c2, 0x017da67b441ca5af922da90de46a4056, 0x0118a82e317ce7d39c01e861810d640a, 0x0143
],
modulus_u60: U60Repr { limbs: ArrayX { segments: [[
0x034deca1472a2bf3, 0x0ca067270cbaa2f3, 0x0e3e34a14af22618, 0x06610de1958b4206, 0x0956e5503a499841, 0x0e59e76000fcfb05, 0x0afafacd2381782c, 0x03d429c951fdec78, 0x0b8c2a41bfd38ed9, 0x0617806aa0cf2d15, 0x02d5571ea75c92d3, 0x0a4a58ff8737791b, 0x061162bc1034f586, 0x049f85ae321bfbc1, 0xcf63605975cf48, 0x0a40bf68ca724dff, 0x0232351085a7d591, 0x0d5c5fe2ab9a1adf], [0x094b2cb4af4d294f, 0x01b0d1c9077b8f07, 0x0566fd6b69e62ccd, 0x09401a841ae63b1f, 0x0c6cb489538831e0, 0x0d6958bad7bcf453, 0x087a1d178d6bc3ce, 0x051bdf4c4cd4c928, 0xd7a2c1af84ea38, 0x0d153e9c43d7aa9b, 0x0bd0d53e4e0e61e1, 0x09deb9b61f4e25c1, 0x0916d486f235202b, 0x0bed33da20e52d7c, 0x0e00f430c086b205, 0xc541718be73e9c, 0xa2, 0x00]] } },
modulus_u60_x4: U60Repr { limbs: ArrayX { segments: [[
0x034deca1472a2bf3, 0x0ca067270cbaa2f3, 0x0e3e34a14af22618, 0x06610de1958b4206, 0x0956e5503a499841, 0x0e59e76000fcfb05, 0x0afafacd2381782c, 0x03d429c951fdec78, 0x0b8c2a41bfd38ed9, 0x0617806aa0cf2d15, 0x02d5571ea75c92d3, 0x0a4a58ff8737791b, 0x061162bc1034f586, 0x049f85ae321bfbc1, 0xcf63605975cf48, 0x0a40bf68ca724dff, 0x0232351085a7d591, 0x0d5c5fe2ab9a1adf], [0x094b2cb4af4d294f, 0x01b0d1c9077b8f07, 0x0566fd6b69e62ccd, 0x09401a841ae63b1f, 0x0c6cb489538831e0, 0x0d6958bad7bcf453, 0x087a1d178d6bc3ce, 0x051bdf4c4cd4c928, 0xd7a2c1af84ea38, 0x0d153e9c43d7aa9b, 0x0bd0d53e4e0e61e1, 0x09deb9b61f4e25c1, 0x0916d486f235202b, 0x0bed33da20e52d7c, 0x0e00f430c086b205, 0xc541718be73e9c, 0xa2, 0x00], [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]] } },
redc_param: [
0x1fdcdafc0b4a1e7e76fea4d047f13c, 0xe9f3127f19f73583a5378c5e3fb4a4, 0x61d4721841efbeac85a785dd48b58e, 0x747ed55336a2218c1f011c5f730478, 0xf8e29e2ca49c4df7aa57cc4defb877, 0x67541ffb558ce4fea6409c61e5b96a, 0xc616b60523693e15226453d9c1a735, 0x8e609df55b7e417c40ec232ac85f2c, 0xec4a3a8702ea1a8836d5bf2d63dc4c, 0x73ee26edb819fac7c1a771ed2d2447, 0x84e660e9c009e0eadd88a0c2d957c5, 0xb9c718c32762b643b6c29606ea3766, 0x9077b6f87aa1ba000b853a4841ea29, 0x28e68f0218123e2f911bfe4f2afdb1, 0xc45f6a9c6e8f5c18e38415b847eba6, 0xfd74428019998d5f69bda9954cd6d4, 0x6c48d17d943d2d123a0cb7f1044254, 0x0194
]
};

25 changes: 25 additions & 0 deletions examples/custom_modulus_example/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
mod custom_params;

use custom_params::RSA2048_example_Params;
use dep::bignum::BigNum;

type RSA2048 = BigNum<18, RSA2048_example_Params>;

fn main(a: RSA2048, b: RSA2048, expected: RSA2048) {
let c = a + b;
assert(c == expected);
}

#[test]

fn test_main() {
let mut a: RSA2048 = BigNum::new();
a.limbs[0] = 10;
let mut b: RSA2048 = BigNum::new();
b.limbs[0] = 20;

let mut expected: RSA2048 = BigNum::new();
expected.limbs[0] = 30;

main(a, b, expected);
}
8 changes: 8 additions & 0 deletions examples/ed25519_example/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "ed25519_example"
type = "bin"
authors = [""]
compiler_version = ">=0.34.0"

[dependencies]
bignum = { path = "../.." }
20 changes: 20 additions & 0 deletions examples/ed25519_example/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[a]
limbs = ["1", "0", "0"]

[b]
limbs = ["2", "0", "0"]

[c]
limbs = ["3", "0", "0"]

[d]
limbs = ["4", "0", "0"]

[e]
limbs = ["5", "0", "0"]

[expected]
limbs = ["43", "0", "0"]

[f]
limbs = ["6", "0", "0"]
31 changes: 31 additions & 0 deletions examples/ed25519_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ed25519 Example

## Testing
Run test:
```
nargo test
```

## Execution
The testvalues are also in the `Prover.toml`. Adjust them to prove with other values.
Execute the Noir program:
```
nargo execute example1
```
The witness is written to `./target/example1.gz`.

Prove valid execution (with default Barretenberg backend):
```
bb prove -b ./target/ed25519_example.json -w ./target/example1.gz -o ./target/proof
```
The generated proof will be in `./target/proof`.

Verify proof by computing the verification key:
```
bb write_vk -b ./target/ed25519_example.json -o ./target/vk
```
.. and then verifying the proof:
```
bb verify -k ./target/vk -p ./target/proof
```
If successful, you see nothing! Otherwise an error will show.
57 changes: 57 additions & 0 deletions examples/ed25519_example/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use dep::bignum::fields::ed25519Fq::ED25519_Fq_Params;
use dep::bignum::runtime_bignum::BigNumInstance;
use dep::bignum::BigNum;

// Prime field mod 2^255-19
type Ed25519Fq = BigNum<3, ED25519_Fq_Params>;

// Check that `a * b + (c + d) * e + f` equals `expected`
// (this constrains `a * b + (c + d) * e + f - expected = 0`)
fn main(
a: Ed25519Fq,
b: Ed25519Fq,
c: Ed25519Fq,
d: Ed25519Fq,
e: Ed25519Fq,
f: Ed25519Fq,
expected: Ed25519Fq
) {
// Step 1: calculate g = a * b + (c + d) * e + f in unconstrained functions
// First product term a * b
let t0 = a.__mul(b);
// Second product term (c + d) * e
let t1 = (c.__add(d)).__mul(e);
let g = t0.__add(t1).__add(f);

// Step 2:
// product term 1 a * b. Rewrite to (a + 0) * b
// product term 2 (c + d) * e
// linear terms f, g
BigNum::evaluate_quadratic_expression(
[[a, BigNum::new()], [c, d]],
[[false, false], [false, false]],
[[b], [e]],
[[false], [false]],
[f, g],
[false, true]
);

// Step 3: check res equals `expected`
assert(g == expected);
}

// Simple test
#[test]
fn test_main() {
// a=1, b=2, c=3, d=4, e=5, f=6
let a: Ed25519Fq = BigNum::from_array([1, 0, 0]);
let b: Ed25519Fq = BigNum::from_array([2, 0, 0]);
let c: Ed25519Fq = BigNum::from_array([3, 0, 0]);
let d: Ed25519Fq = BigNum::from_array([4, 0, 0]);
let e: Ed25519Fq = BigNum::from_array([5, 0, 0]);
let f: Ed25519Fq = BigNum::from_array([6, 0, 0]);
// 1*2 + (3+4) * 5 + 6 = 43
let expected: Ed25519Fq = BigNum::from_array([43, 0, 0]);

main(a, b, c, d, e, f, expected);
}
8 changes: 8 additions & 0 deletions examples/runtime_modulus_example/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "runtime_modulus_example"
type = "bin"
authors = [""]
compiler_version = ">=0.34.0"

[dependencies]
bignum = { path = "../.." }
12 changes: 12 additions & 0 deletions examples/runtime_modulus_example/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
modulus = ["0xca067270cbaa2f334deca1472a3e31", "0x6610de1958b4206e3e34a14af22618", "0xe59e76000fcfb05956e5503a499841", "0x3d429c951fdec78afafacd2381782c", "0x617806aa0cf2d15b8c2a41bfd38ed9", "0xa5bd5539ec839696d39cf8dfdd92d3", "0xe9bed0c391a2d4050d6d2367c6a943", "0x2d2150ff6bb93bf3a7d1163587d488", "0x852ed0ee51bf01f3"]
redc_param = ["0xb6b68cb415434ea6273830091e7ba4", "0x9da115c204677051818a8c033cbc85", "0x8cb24ce7044f7c1fe2cd6d5425e397", "0x478c0c53482aacf0b50d3649c1b096", "0xc7b7c730e69ec6b458f1ea2faf1c28", "0x6b733155f8756e0d0cc2bce80185da", "0xf34103a45581aa68206e1aac5ecdca", "0x59c9f258f9e3905b9629a277b6752f", "0x01ec13452bee67c5dc"]

[a]
limbs = ["10", "0", "0", "0", "0", "0", "0", "0", "0"]

[b]
limbs = ["20", "0", "0", "0", "0", "0", "0", "0", "0"]

[expected]
limbs = ["30", "0", "0", "0", "0", "0", "0", "0", "0"]

64 changes: 64 additions & 0 deletions examples/runtime_modulus_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Runtime modulus example

## Create program

As explained in the general BigNum README, for a runtime modulus a `BigNumInstance` either has to be passed into the program or generated using the `modulus` and `redc_param`. In this example we'll do the latter.

This is an example assuming RSA for a modulus of 1024 bits.

At compile-time we know the number of bits of the modulus and can define the types:
```rust
struct RSA1024Params {}
impl RuntimeBigNumParamsTrait<9> for RSA1024Params {
fn modulus_bits() -> u32 {
1024
}
fn has_multiplicative_inverse() -> bool { false }
}

type RSA1024 = BigNum<9, RSA1024Params>;
type RSA1024Instance = BigNumInstance<9, RSA1024Params>;
```

The `main` function expects the `modulus` and `redc_param` in order to generate the `BigNumInstance` and consequently use it to perform arithmetic operations.

```rust
fn main(modulus: [Field; 9], redc_param: [Field; 9], a: RSA1024, b: RSA1024, expected: RSA1024) {
let BNInstance: RSA1024Instance = BigNumInstance::new(modulus, redc_param);

let c = BNInstance.add(a, b);
assert(BNInstance.eq(expected, c));
}
```

## Test program

The test defines `modulus` and `redc_param`, which have been obtained using [this tool](https://github.com/noir-lang/noir-bignum-paramgen). To run the test:
```
nargo test
```

## Execute, prove & verify program

The testvalues are also in the `Prover.toml`. Adjust them to prove with other values.
Execute the Noir program:
```
nargo execute example2
```
The witness is written to `./target/example2.gz`.

Prove valid execution (with default Barretenberg backend):
```
bb prove -b ./target/custom_modulus_example.json -w ./target/example2.gz -o ./target/proof
```
The generated proof will be in `./target/proof`.

Verify proof by computing the verification key:
```
bb write_vk -b ./target/custom_modulus_example.json -o ./target/vk
```
.. and then verifying the proof:
```
bb verify -k ./target/vk -p ./target/proof
```
If successful, you see nothing! Otherwise an error will show.
Loading
Loading