-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ssa refactor): more comprehensive instruction simplification (#1735)
* chore(ssa refactor): more comprehensive instruction simplification * chore(ssa refactor): cp working test * chore(ssa refactor): allow HO functions; tidy * chore(ssa refactor): also now works * chore(ssa refactor): PR feedback * Update crates/noirc_evaluator/src/ssa_refactor/ir/instruction.rs --------- Co-authored-by: jfecher <[email protected]>
- Loading branch information
1 parent
c53bfc8
commit 97d6747
Showing
7 changed files
with
211 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
39 changes: 39 additions & 0 deletions
39
crates/nargo_cli/tests/test_data_ssa_refactor/6/Prover.toml
This file contains 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,39 @@ | ||
|
||
# hello as bytes | ||
# used : https://emn178.github.io/online-tools/sha256.html | ||
x = [104, 101, 108, 108, 111] | ||
|
||
result = [ | ||
0x2c, | ||
0xf2, | ||
0x4d, | ||
0xba, | ||
0x5f, | ||
0xb0, | ||
0xa3, | ||
0x0e, | ||
0x26, | ||
0xe8, | ||
0x3b, | ||
0x2a, | ||
0xc5, | ||
0xb9, | ||
0xe2, | ||
0x9e, | ||
0x1b, | ||
0x16, | ||
0x1e, | ||
0x5c, | ||
0x1f, | ||
0xa7, | ||
0x42, | ||
0x5e, | ||
0x73, | ||
0x04, | ||
0x33, | ||
0x62, | ||
0x93, | ||
0x8b, | ||
0x98, | ||
0x24, | ||
] |
20 changes: 20 additions & 0 deletions
20
crates/nargo_cli/tests/test_data_ssa_refactor/6/src/main.nr
This file contains 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,20 @@ | ||
// Sha256 circuit where the input is 5 bytes | ||
// not five field elements since sha256 operates over | ||
// bytes. | ||
// | ||
// If you do not cast, it will take all the bytes from the field element! | ||
|
||
// Mimc input is an array of field elements | ||
// The function is called mimc_bn254 to emphasize its parameters are chosen for bn254 curve, it should be used only with a proving system using the same curve (e.g Plonk from Aztec) | ||
use dep::std; | ||
|
||
fn main(x: [u8; 5], result: pub [u8; 32]) { | ||
let mut digest = std::hash::sha256(x); | ||
digest[0] = 5 as u8; | ||
digest = std::hash::sha256(x); | ||
assert(digest == result); | ||
|
||
let y = [12,45,78,41]; | ||
let h = std::hash::mimc_bn254(y); | ||
assert(h == 18226366069841799622585958305961373004333097209608110160936134895615261821931); | ||
} |
7 changes: 7 additions & 0 deletions
7
crates/nargo_cli/tests/test_data_ssa_refactor/merkle_insert/Nargo.toml
This file contains 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,7 @@ | ||
|
||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] | ||
|
11 changes: 11 additions & 0 deletions
11
crates/nargo_cli/tests/test_data_ssa_refactor/merkle_insert/Prover.toml
This file contains 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,11 @@ | ||
old_root = "0x285785b10eca49cf456b935f1c9787ff571f306c1bc62549c31a9199a633f9f8" | ||
old_leaf = "0x1cdcf02431ba623767fe389337d011df1048dcc24b98ed81cec97627bab454a0" | ||
old_hash_path = [ | ||
"0x1cdcf02431ba623767fe389337d011df1048dcc24b98ed81cec97627bab454a0", | ||
"0x0b5e9666e7323ce925c28201a97ddf4144ac9d148448ed6f49f9008719c1b85b", | ||
"0x22ec636f8ad30ef78c42b7fe2be4a4cacf5a445cfb5948224539f59a11d70775", | ||
] | ||
new_root = "0x2d05c2650e6c2ef02c6dc7fae7f517b8ac191386666c0b5a68130a8c11092f5f" | ||
leaf = "0x085ca53be9c9d95b57e6e5fc91c5d531ad9e63e85dd71af7e35562991774b435" | ||
index = "0" | ||
mimc_input = [12,45,78,41] |
21 changes: 21 additions & 0 deletions
21
crates/nargo_cli/tests/test_data_ssa_refactor/merkle_insert/src/main.nr
This file contains 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,21 @@ | ||
use dep::std; | ||
|
||
fn main( | ||
old_root: Field, | ||
old_leaf: Field, | ||
old_hash_path: [Field; 3], | ||
new_root: pub Field, | ||
leaf: Field, | ||
index: Field, | ||
mimc_input: [Field; 4], | ||
) { | ||
assert(old_root == std::merkle::compute_merkle_root(old_leaf, index, old_hash_path)); | ||
|
||
let calculated_root = std::merkle::compute_merkle_root(leaf, index, old_hash_path); | ||
assert(new_root == calculated_root); | ||
|
||
let h = std::hash::mimc_bn254(mimc_input); | ||
// Regression test for PR #891 | ||
std::println(h); | ||
assert(h == 18226366069841799622585958305961373004333097209608110160936134895615261821931); | ||
} |
This file contains 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