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

fix: compute witness when println evaluated before input #891

Merged
merged 3 commits into from
Feb 21, 2023

Conversation

vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Feb 21, 2023

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 adding evaluate_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 use get_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 in merkle_insert, where the printed output was correct.

Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt with default settings.
  • I have linked this PR to the issue(s) that it resolves.
  • I have reviewed the changes on GitHub, line by line.
  • I have ensured all changes are covered in the description.
  • This PR requires documentation updates when merged.

Additional context

@vezenovm vezenovm changed the title Fix println when fix: compute witness when println evaluated before input Feb 21, 2023
jfecher
jfecher previously approved these changes Feb 21, 2023
@vezenovm vezenovm marked this pull request as ready for review February 21, 2023 19:11
@vezenovm
Copy link
Contributor Author

vezenovm commented Feb 21, 2023

@jfecher If you could review once more. The place I added the println in the strings test was not the actual cause of the bug. I moved it to merkle_insert where the bug occurs without this PR.

Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@vezenovm vezenovm added this pull request to the merge queue Feb 21, 2023
Merged via the queue into master with commit 2727b34 Feb 21, 2023
@vezenovm vezenovm deleted the mv/fix-mimc-println branch February 21, 2023 20:12
@Savio-Sou
Copy link
Collaborator

Confirming that this doesn't require doc updates right?

@vezenovm
Copy link
Contributor Author

vezenovm commented Mar 6, 2023

Confirming that this doesn't require doc updates right?

Yes this was simply a bug with printing certain stdlib func outputs

smanilov added a commit to blocksense-network/noir that referenced this pull request May 13, 2024
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    }
>
```
smanilov added a commit to blocksense-network/noir that referenced this pull request May 13, 2024
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    }
>
```
smanilov added a commit to blocksense-network/noir that referenced this pull request Jun 6, 2024
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    }
>
```
smanilov added a commit to blocksense-network/noir that referenced this pull request Jun 6, 2024
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    }
>
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants