Skip to content

Commit

Permalink
feat!: update to noir-bignum v0.4.1 (#30)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Connor <[email protected]>
  • Loading branch information
TomAFrench and iAmMichaelConnor authored Nov 8, 2024
1 parent 4b81831 commit e54d13d
Show file tree
Hide file tree
Showing 17 changed files with 383 additions and 386 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
toolchain: [nightly, 0.35.0]
toolchain: [nightly, 0.36.0]
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand All @@ -30,6 +30,10 @@ jobs:
working-directory: ./lib
run: nargo test

- name: Run example project
working-directory: ./example
run: nargo execute

format:
runs-on: ubuntu-latest
steps:
Expand All @@ -39,12 +43,16 @@ jobs:
- name: Install Nargo
uses: noir-lang/[email protected]
with:
toolchain: 0.35.0
toolchain: 0.36.0

- name: Run formatter
working-directory: ./lib
run: nargo fmt --check

- name: Run formatter on example
working-directory: ./example
run: nargo fmt --check

# This is a job which depends on all test jobs and reports the overall status.
# This allows us to add/remove test jobs without having to update the required workflows.
tests-end:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/target
target
**/.DS_Store
.vscode
4 changes: 2 additions & 2 deletions example/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
name = "example"
type = "bin"
authors = [""]
compiler_version = ">=0.35.0"
compiler_version = ">=0.36.0"

[dependencies]
rsa = { path = "../lib" }
bignum = { tag = "v0.3.6", git = "https://github.com/noir-lang/noir-bignum" }
bignum = { tag = "v0.4.1", git = "https://github.com/noir-lang/noir-bignum" }
101 changes: 4 additions & 97 deletions example/Prover.toml
Original file line number Diff line number Diff line change
@@ -1,97 +1,4 @@
bn = [
[
'0xab88f7a360f88fd0782e4c8f749bb5',
'0xc4df70a6920b9bc866e6f6b2e32c55',
'0x29d74e3996e0669887d453eaa7e722',
'0x5e46b505c0067332878ccc5ce1745b',
'0xa24be548a41edc60c2476388aa79fa',
'0x2f6b76f137bfc5a5ea6ee25378faa5',
'0xad6db5af4521b0d05fc2c462857ef6',
'0x2d2a256b3ceef4946487989942c112',
'0xff87818701decef601d143ad536e75',
'0x506c7dc017de18ebe07d40e5692be1',
'0x56d47f8f1c1fdb3e6d687a876773f9',
'0x2683a784665e910d9017b94dc74b4d',
'0x522b5736042a326f8654c32be14ffe',
'0xe0351aa5ef4567f5f02110a215def2',
'0x46324a74609f07d86e6fffe0c327da',
'0x462ab654703f35cdacbba7c9049941',
'0xfc6ee90b277b12c6946001652ae11a',
'0xf2',
],
[
'0xb80936623ea38314b69abad164724b',
'0x9b4b8b47d45823815eec4f81df519c',
'0xe2a236b6e5bd64cf4fa2c421fcef5b',
'0x283dd152b19fbf8392bd77ef112819',
'0x5a7193fa497343fc66fdecacb11673',
'0xad28a77b9a15484a0912469c065e12',
'0x24e2dc41a8e07f30000d1441168080',
'0x3a9c86d7352fcd56c36f479bc6dd0d',
'0x36f95b26a2135734a919589da7df5a',
'0x4b73efbdf065bb6e3e209933c2a81b',
'0x9ab2788e486374b5407a2915dee603',
'0xff78ebdac2927df46eb09670d99286',
'0xc6c73cf9baa421664e3035e6e03204',
'0xa07bacdb33341dcb13233cbae690c0',
'0xf3533ab7e32063aa7bfcde28a30c2c',
'0x1b304126870b2ebc20f00071899dfc',
'0xb5fffe2de7dd683141a659fb879f97',
'0x10d',
],
]
hash = [
44,
242,
77,
186,
95,
176,
163,
14,
38,
232,
59,
42,
197,
185,
226,
158,
27,
22,
30,
92,
31,
167,
66,
94,
115,
4,
51,
98,
147,
139,
152,
36,
]
[signature]
limbs = [
"0x3c1f7a6bdac9d799975076bb401622",
"0x1662d29b2f99dcc51d320c17818a16",
"0x752fb8b42585d53998776c97573b5",
"0xf06107ff8fae798a1c5cf8792274d3",
"0xcfd3b6b58942ac7b6baaf3d5740661",
"0xbdf7adc8288e78c1488e99483e74bd",
"0xd86bc4ebc1e450f6810b24f9d53e37",
"0xf2b6a14967c86bf2d9699c14d8edaa",
"0x3844199077a4324c3fdd2c0319b868",
"0xbdd8679b0d51a763a74c7575debda1",
"0x99c612a61d1466e87d4abeee4379ee",
"0xb6c445ac3aa2cc5ec36505fddfcf8c",
"0xe9d3e597c2e8a1290f5485df403bb3",
"0x3e34cc6ce3f3e266645c8725ac911",
"0x7b9f2ea85922ba5f2b9e74ce5c9dd",
"0x260652f8a7cc82376455e5882eaac0",
"0x221b8273f727efb358b3cf49f94c87",
"0x99",
]
hash = [185, 77, 39, 185, 147, 77, 62, 8, 165, 46, 82, 215, 218, 125, 171, 250, 196, 132, 239, 227, 122, 83, 128, 238, 144, 136, 247, 172, 226, 239, 205, 233]
modulus_limbs = ["0xef368ee527555429e41e399f4cf4f7", "0xa6ee7046f1d4eade05c22cc71aefa8", "0x3c49a567ec0eee765c50edb83d299a", "0x14c9c07d6266ae3402a9a0ac364b2c", "0x1bb76a8a510c341b3b21f35edd33d8", "0x2e4c11fbbf960f967a0ef4bb180dcb", "0x9d84fa8a7db7bc8ba49c1eec64e37d", "0x11fb0636ca84326cfabb360c5e17b3", "0x5c7b4a41e6d9e6b8c246b0554cde5", "0xb14b86dd4cf9383f51d04ec12129", "0x6aa8a6989019189616e02c785fc8e4", "0x4a0317a62b6a22ce68031cb4f23ce8", "0x5ea80d1dd576f56ba9a3089e4099af", "0xacb7f812249b4b278c5b03d78c0afb", "0xfb2118db289e623687ba5298e6e1e2", "0x214352a64a03c909bbd43d9940d460", "0x893bd4b92877df9b2d12bdeb2d2b74", "0xb5"]
redc_limbs = ["0x3c594da174a0effdf4abd5d24891ac", "0xd4339b1877cf5b54bcb15b4451872", "0x4ba438dd5036f8abaaad8ca7398c79", "0x571e77d0eab532e7a539f0f69d18ec", "0xc0a35ddbcf6a7a2383977c5b3eaa24", "0xf14e3e1234a3a4d0cda0023f283481", "0x893d88b750931ab81a9d027fde0c2a", "0xc6a310feacba3e886caca7adf41199", "0x6f46524cd5b7a7eb2253dc8b62c212", "0x4174f6c86d1d3e6e2ba23244ebbd0", "0xf16ecfaa7ee8a299f066df87d4f7a4", "0xab74a3710a4fde3421d187a78b9db1", "0xa3ee2e53aaded37de9abe3414ab2b9", "0x12a0a012b9c643ef0bd5c034f3a366", "0x1f31d710f11ddb44794d3200a3dea", "0x4453d51bc5c08b0063af14b74995b9", "0x215f0286eb418895604ead32ec0a4e", "0x1690"]
signature_limbs = ["0x4b25985bf5f0641557331c5d5f91d5", "0xaf0124feff62f6eb48856da0a46ae6", "0x21ef75eb686d10217a616729003038", "0x9b40883cba0a51e68a1e59fd156686", "0xf95142bdb6164d5e13809014ef55d2", "0x729cbaf6eb698d665bd4d8231d55c4", "0xea48dab6d7db49d605b5378c4c5cb8", "0xac3c80a366f2afd191a3475ea994", "0xe4b99720655b68f7ab8245bcb244c9", "0x1f61d4d35aebbbfa0fcc7d27def7b0", "0xb0024a803527dd449f9a2f91150db9", "0x9355709711a9bd1475fbea10dbede4", "0x2366e18316f9e47b3fe661a9f8b6f5", "0x917aa5e1be5c328a1251fc25d09e76", "0xd40f315491f15781f335c8190aabc", "0xdfb58b8e66e8f5cec40756f5a60a11", "0xf0946746d797bf51488f96b19280bc", "0xa"]
107 changes: 84 additions & 23 deletions example/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,33 +1,94 @@
use dep::bignum::BigNum;
use dep::bignum::runtime_bignum::BigNumInstance;
use dep::std;
use dep::bignum::{params::BigNumParams, RuntimeBigNum};
use dep::rsa::{rsa::verify_sha256_pkcs1v15, types::RBN2048};

use dep::rsa::types::{RSA, RSA2048, BN2048, BNInst2048};
// Examples of the signature limbs, modulus, and redc params can be generated via
// ../../signature_gen/main.rs.
// Note: technically, the `signature` could've been passed into `main` directly,
// for a much cleaner interface.
// The reason we chose this more verbose approach here, was to reduce the amount of
// data to generate for the Prover.toml file.
fn main(
hash: [u8; 32],
signature_limbs: [Field; 18],
modulus_limbs: [Field; 18],
redc_limbs: [Field; 18],
) {
let has_multiplicative_inverse = false;
let params: BigNumParams<18, 2048> =
BigNumParams::new(has_multiplicative_inverse, modulus_limbs, redc_limbs);

fn main(bn: [[Field; 18]; 2], hash: [u8; 32], signature: BN2048) {
let rsa: RSA2048 = RSA {};
let signature: RBN2048 = RuntimeBigNum::from_array(params, signature_limbs);

let BNInstance: BNInst2048 = BigNumInstance::new(bn[0], bn[1]);

assert(rsa.verify_sha256_pkcs1v15(BNInstance, hash, signature, 65537));
assert(verify_sha256_pkcs1v15(hash, signature, 65537));
}

#[test]
fn test_main() {
// Output of `cargo run -- --msg "hello world"` in the `signature_gen` directory
let hash: [u8; 32] = dep::std::hash::sha256("hello world".as_bytes());
let signature: BN2048 = BigNum::from_array(
[
0x33aee5bd60a8d0664fe7780b7fde43, 0xc66f8a5fc4a74d18b83b27da6d4e04, 0x501c489c1764ad72e5c5b1bb56f1c6, 0xb1a8c5029f8422efdcfd1621f70da9, 0xe9b80989d178e8852266a7631c3b99, 0xb95a3af119a4ca60350a31ad3b9d7e, 0x64a98fdbb8441abc103fe2617149d9, 0xfd5a9db30568b2b151bd243b1816a9, 0x12d2be80d5959660831cc3b7929159, 0xae6034247561d3dfa882ca20d61ff6, 0x786973219800b65edd92b0b0b05d09, 0x516fdbed6a0d7afa3516dbba1ea473, 0x2f14e2807fa6c3d9cc5b7667aec5ac, 0x9a6a1997e1f7cfdeac736073ec4ce2, 0x24c94d7ea832e1afc889e82bd42c1b, 0x4cfb977a1102edca719f9c2e3f2c2e, 0x7c7cd4f29c3da09f7fa8ddf73df0b2, 0x77
]
);
let bn = [
[
0x413f4f8b6405fdb76f85540f5663c5, 0x1dffa8aaa6192d9f031a8c1d55dc33, 0xefccc1c3eb6c189c147cd485f56771, 0xc62eaf58cfd1a6eead6ec82e44111a, 0xf693ea8b22a50265d43eb2235d910b, 0x6eb385b77042a98e1f708a5b76fa17, 0xad5ad6b87eea566a26a05f5a59713b, 0x979c5611b54a78df8fd0b5b0464de6, 0xfde57bd223c394f50249f18d5522aa, 0xc6cd804f8bac07c9e81cc06fe323e9, 0x84ec399cf67c012f58a7b81515b63d, 0x61eba631d274a78a5387d0e2929d77, 0x40e2bb193409130671ac8f3e7c1fcf, 0x2aa7d8d4aec0cf96ad8fe0d0779dbb, 0x26d56c517952712bcdf1e8f1ffafc6, 0x9786e9f338cb9e6de55c436153978a, 0xb867413d06a32724b33657bbf1e3f2, 0xe8
],
[
0xbc5184dd6dc06d396240375a5211c0, 0x6280f148f5356bbea76382819bf475, 0x93d5ca8016d2335de4fc0988e7e24b, 0xd96e4c1d3210702c33d6470e16cfa0, 0xe2dbfaf8d02d4251862905787f2561, 0x9538f84fa231c9baac81216e2d9ed5, 0xcb82246c4a83da9398570aaabd4d2a, 0x94b04ca9ae375eebbb9c87479d3bee, 0x7deacf1e79cfe70937e9eee7ed887a, 0xa0f7bae3d1a70b98538142db43a58b, 0xaac2ec033a9ab117f077e3e06ba954, 0x4f937780ab7d644c95d1a34dcf450a, 0xc17dd532df051696582c85316a2517, 0x69f59bbbfa26851603d97da9a83709, 0xc506921f809dcbb4c07aea96102050, 0xbe638141f7b4d62660d59519ebdacf, 0xbc084a1b1ca76abe6f8ae8fcff6417, 0x1199
]
// Create runtime params:
let modulus_limbs = [
0x65af46d235241cf0e8fbe8cff4abb7,
0xeead39ba3f377ddd5ccb2ef2085190,
0xe483f94c0a98e8b618d92fb926f596,
0x1fa8c1b2c62cca6db090cd74a29db2,
0xc38e22042fcb74585a7e535301f50f,
0xcbc4378e5212752743ae78a75a44a9,
0xf5acc41788d9a346a0f75630a8b2b6,
0xf7a741bb3ecf1aadd5a327f362abd8,
0x4d5f24e815db43a1b2cc2ba40f8715,
0xe501f1a01305cb198475a4bff0da2e,
0xd541b78cfbc2b314083c340840c82c,
0xa0ab069c26b2a0458f4c642bf72526,
0x2ccb676d8f22517116fee0d2340533,
0x7cf2a7cf772025c0a83747bbc18228,
0xf9475f17988a56f17b3bdf88dc72dc,
0x4ff228bee24415fae7a7c05771e830,
0x55acd96b485515c38906106cf0d189,
0xb9,
];
let redc_limbs = [
0x172c8f156f020ad88d30fa3ba47f03,
0x1740a43a67cb9a7be1ac1422d77246,
0x2d967be1edf369834317e04856e591,
0x65d9fa0de5fdab598c04d9a515156a,
0xc6791a661ea7621db7e6c4ec48f466,
0xa4a1a7c06d3e8a0bcbc540c6af6788,
0xdcaffeb149f5bf646caa00d7355715,
0xb75471630a9d0fefb5cb61e66991a1,
0x97c041a0fc30fdff3d5ed16997da02,
0xbfbe7d217694b269e1ed37819c2f17,
0x1b44ffc3180531e2ab8bdf7848a3a9,
0x9f004af11132cb68bb55998ed7616a,
0x1b15dbbb96ce80f479724bbd768a0c,
0x59ba1419093ae6ed2592ffb3065867,
0xa35b69affa3bb3f4713f315e50b584,
0xa873210f83a6de0d8cbb816af3e37,
0xbe4fe7cf98da87ec87638030797e92,
0x1619,
];

let signature_limbs = [
0x2f397c4611d4a4271453e1e50e1578,
0xe506a7f47c721a4943783e8ad459e6,
0x6cc4ae1d91cb381cba9673470999fb,
0x1e127364d07f94e58227f50fbf5687,
0xf64a2579c7189f882d68832d16faa4,
0x3b014b74c6c6f76f2f8af170fa0fe4,
0x7df41e68c86815a6fdc33968c66b67,
0x6a57ac06282527242fddb6ed08dbdc,
0xac40d37b819c4b6193f90a634e4fc7,
0x96606ed166a7f032d858cd40ac73a5,
0x8eb7d4351159a46733f92610d5c597,
0xc8e8e9faa9738e82dbe774a3f5cf07,
0x89ca84fd54ee3d5cca87c9f178375e,
0xdb7a1465fc76507ea498a351af70dd,
0x6ac6fe14f51c711f983125c776f712,
0x3254c17fef51bf4194a8a1674634e3,
0xee38c83c77c6e1ff7b70a5d9d1dd0f,
0x26,
];
main(bn, hash, signature);

let hash: [u8; 32] = dep::std::hash::sha256("hello world".as_bytes());

main(hash, signature_limbs, modulus_limbs, redc_limbs);
}
1 change: 0 additions & 1 deletion example/target/example.json

This file was deleted.

Binary file removed example/target/proof
Binary file not shown.
Binary file removed example/target/t.gz
Binary file not shown.
Binary file removed example/target/vk
Binary file not shown.
2 changes: 1 addition & 1 deletion info.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nargo compile --force && bb gates -b ./target/noir_rsa.json
(cd example && nargo compile --force --silence-warnings && bb gates -b ./target/example.json | grep "circuit")
4 changes: 2 additions & 2 deletions lib/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "noir_rsa"
type = "lib"
authors = [""]
compiler_version = ">=0.35.0"
compiler_version = ">=0.36.0"

[dependencies]
bignum = {tag = "v0.3.6", git = "https://github.com/noir-lang/noir-bignum"}
bignum = {tag = "v0.4.1", git = "https://github.com/noir-lang/noir-bignum"}
4 changes: 2 additions & 2 deletions lib/src/lib.nr
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
mod rsa;
mod types;
pub mod rsa;
pub mod types;
Loading

0 comments on commit e54d13d

Please sign in to comment.