-
Notifications
You must be signed in to change notification settings - Fork 199
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
fix: compute witness when println evaluated before input #891
Conversation
@jfecher If you could review once more. The place I added the println in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Confirming that this doesn't require doc updates right? |
Yes this was simply a bug with printing certain stdlib func outputs |
This makes it much easier to find the correct place to add a break point while debugging a program. For example, now one can do the following: ``` $ cd test_programs/execution_success/merkle_insert/ $ nargo debug [merkle_insert] Starting debugger At opcode 0: BRILLIG CALL func 0: PREDICATE = %EXPR [ 1 ]% inputs: [Single(Expression { mul_terms: [], linear_combina [...] > next At opcode 0.17: Const { destination: MemoryAddress(21), bi [...] At [...]/test_programs/execution_success/merkle_insert/src/main.nr:12:3 7 ... 8 new_root: pub Field, 9 leaf: Field, 10 index: Field, 11 mimc_input: [Field; 4] 12 -> ) { 13 assert(old_root == std::merkle::compute_merkle_ [...] 14 15 let calculated_root = std::merkle::compute_merk [...] 16 assert(new_root == calculated_root); 17 18 let h = mimc::mimc_bn254(mimc_input); 19 // Regression test for PR noir-lang#891 20 std::println(h); 21 assert(h == 18226366069841799622585958305961373 [...] 22 } > break 18 Added breakpoint at opcode 0.1274 > continue (Continuing execution...) Stopped at breakpoint in opcode 0.1274 At opcode 0.1274: Const { destination: MemoryAddress(36), [...] At /home/stan/code/repos/noir/test_programs/execution_succ [...] 13 ... 14 15 let calculated_root = std::merkle::compute_merk [...] 16 assert(new_root == calculated_root); 17 18 -> let h = mimc::mimc_bn254(mimc_input); 19 // Regression test for PR noir-lang#891 20 std::println(h); 21 assert(h == 18226366069841799622585958305961373 [...] 22 } > ```
This makes it much easier to find the correct place to add a break point while debugging a program. For example, now one can do the following: ``` $ cd test_programs/execution_success/merkle_insert/ $ nargo debug [merkle_insert] Starting debugger At opcode 0: BRILLIG CALL func 0: PREDICATE = %EXPR [ 1 ]% inputs: [Single(Expression { mul_terms: [], linear_combina [...] > next At opcode 0.17: Const { destination: MemoryAddress(21), bi [...] At [...]/test_programs/execution_success/merkle_insert/src/main.nr:12:3 7 ... 8 new_root: pub Field, 9 leaf: Field, 10 index: Field, 11 mimc_input: [Field; 4] 12 -> ) { 13 assert(old_root == std::merkle::compute_merkle_ [...] 14 15 let calculated_root = std::merkle::compute_merk [...] 16 assert(new_root == calculated_root); 17 18 let h = mimc::mimc_bn254(mimc_input); 19 // Regression test for PR noir-lang#891 20 std::println(h); 21 assert(h == 18226366069841799622585958305961373 [...] 22 } > break 18 Added breakpoint at opcode 0.1274 > continue (Continuing execution...) Stopped at breakpoint in opcode 0.1274 At opcode 0.1274: Const { destination: MemoryAddress(36), [...] At /home/stan/code/repos/noir/test_programs/execution_succ [...] 13 ... 14 15 let calculated_root = std::merkle::compute_merk [...] 16 assert(new_root == calculated_root); 17 18 -> let h = mimc::mimc_bn254(mimc_input); 19 // Regression test for PR noir-lang#891 20 std::println(h); 21 assert(h == 18226366069841799622585958305961373 [...] 22 } > ```
This makes it much easier to find the correct place to add a break point while debugging a program. For example, now one can do the following: ``` $ cd test_programs/execution_success/merkle_insert/ $ nargo debug [merkle_insert] Starting debugger At opcode 0: BRILLIG CALL func 0: PREDICATE = %EXPR [ 1 ]% inputs: [Single(Expression { mul_terms: [], linear_combina [...] > next At opcode 0.17: Const { destination: MemoryAddress(21), bi [...] At [...]/test_programs/execution_success/merkle_insert/src/main.nr:12:3 7 ... 8 new_root: pub Field, 9 leaf: Field, 10 index: Field, 11 mimc_input: [Field; 4] 12 -> ) { 13 assert(old_root == std::merkle::compute_merkle_ [...] 14 15 let calculated_root = std::merkle::compute_merk [...] 16 assert(new_root == calculated_root); 17 18 let h = mimc::mimc_bn254(mimc_input); 19 // Regression test for PR noir-lang#891 20 std::println(h); 21 assert(h == 18226366069841799622585958305961373 [...] 22 } > break 18 Added breakpoint at opcode 0.1274 > continue (Continuing execution...) Stopped at breakpoint in opcode 0.1274 At opcode 0.1274: Const { destination: MemoryAddress(36), [...] At /home/stan/code/repos/noir/test_programs/execution_succ [...] 13 ... 14 15 let calculated_root = std::merkle::compute_merk [...] 16 assert(new_root == calculated_root); 17 18 -> let h = mimc::mimc_bn254(mimc_input); 19 // Regression test for PR noir-lang#891 20 std::println(h); 21 assert(h == 18226366069841799622585958305961373 [...] 22 } > ```
This makes it much easier to find the correct place to add a break point while debugging a program. For example, now one can do the following: ``` $ cd test_programs/execution_success/merkle_insert/ $ nargo debug [merkle_insert] Starting debugger At opcode 0: BRILLIG CALL func 0: PREDICATE = %EXPR [ 1 ]% inputs: [Single(Expression { mul_terms: [], linear_combina [...] > next At opcode 0.17: Const { destination: MemoryAddress(21), bi [...] At [...]/test_programs/execution_success/merkle_insert/src/main.nr:12:3 7 ... 8 new_root: pub Field, 9 leaf: Field, 10 index: Field, 11 mimc_input: [Field; 4] 12 -> ) { 13 assert(old_root == std::merkle::compute_merkle_ [...] 14 15 let calculated_root = std::merkle::compute_merk [...] 16 assert(new_root == calculated_root); 17 18 let h = mimc::mimc_bn254(mimc_input); 19 // Regression test for PR noir-lang#891 20 std::println(h); 21 assert(h == 18226366069841799622585958305961373 [...] 22 } > break 18 Added breakpoint at opcode 0.1274 > continue (Continuing execution...) Stopped at breakpoint in opcode 0.1274 At opcode 0.1274: Const { destination: MemoryAddress(36), [...] At /home/stan/code/repos/noir/test_programs/execution_succ [...] 13 ... 14 15 let calculated_root = std::merkle::compute_merk [...] 16 assert(new_root == calculated_root); 17 18 -> let h = mimc::mimc_bn254(mimc_input); 19 // Regression test for PR noir-lang#891 20 std::println(h); 21 assert(h == 18226366069841799622585958305961373 [...] 22 } > ```
Related issue(s)
No issue as found issue while debugging separate project and is a quick fix
Description
I was attempting to print the hash result of
mimc_bn254
in the std lib, but was hitting an unreachable case in the recently addingevaluate_println
method in the acir_gen. It looks as though the println was being evaluated before the mimc result thus resulting in a situation where the non-constant expression had no cached witness.Summary of changes
During
evaluate_println
we instead useget_or_compute_witness
to compute the witness for InternalVar's that do not have a cached_witness rather than panicking.Dependency additions / changes
Test additions / changes
I tested this by adding a println to the
merkle_insert
test where we check that we can print the mimc hash. I also checked the output of the mimc hash inmerkle_insert
, where the printed output was correct.Checklist
cargo fmt
with default settings.Additional context