From 9c11fd264451a3d2b8617ee5e47e6db3fcb148d8 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Fri, 28 Jun 2024 15:12:05 +0100 Subject: [PATCH] fix: ignore calls to `Intrinsic::AsWitness` during brillig codegen (#5350) # Description ## Problem\* Resolves ## Summary\* This PR addresses an issue where if a call is made to `std::as_witness` from a brillig runtime then the compiler will panic with the unreachable error directly below where the new match arm is added. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --- .../src/brillig/brillig_gen/brillig_block.rs | 5 +++++ test_programs/execution_success/as_witness/Nargo.toml | 6 ++++++ test_programs/execution_success/as_witness/Prover.toml | 1 + test_programs/execution_success/as_witness/src/main.nr | 5 +++++ 4 files changed, 17 insertions(+) create mode 100644 test_programs/execution_success/as_witness/Nargo.toml create mode 100644 test_programs/execution_success/as_witness/Prover.toml create mode 100644 test_programs/execution_success/as_witness/src/main.nr diff --git a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs index f10ff834f6c..c2bc1e32cd6 100644 --- a/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs +++ b/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs @@ -583,6 +583,11 @@ impl<'block> BrilligBlock<'block> { 1, ); } + + // `Intrinsic::AsWitness` is used to provide hints to acir-gen on optimal expression splitting. + // It is then useless in the brillig runtime and so we can ignore it + Value::Intrinsic(Intrinsic::AsWitness) => (), + _ => { unreachable!("unsupported function call type {:?}", dfg[*func]) } diff --git a/test_programs/execution_success/as_witness/Nargo.toml b/test_programs/execution_success/as_witness/Nargo.toml new file mode 100644 index 00000000000..18f3f99b5b5 --- /dev/null +++ b/test_programs/execution_success/as_witness/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "as_witness" +type = "bin" +authors = [""] + +[dependencies] diff --git a/test_programs/execution_success/as_witness/Prover.toml b/test_programs/execution_success/as_witness/Prover.toml new file mode 100644 index 00000000000..cd8a5b5e03c --- /dev/null +++ b/test_programs/execution_success/as_witness/Prover.toml @@ -0,0 +1 @@ +a = 42 \ No newline at end of file diff --git a/test_programs/execution_success/as_witness/src/main.nr b/test_programs/execution_success/as_witness/src/main.nr new file mode 100644 index 00000000000..a24f4af7669 --- /dev/null +++ b/test_programs/execution_success/as_witness/src/main.nr @@ -0,0 +1,5 @@ +// Simple example of checking where two arrays are different +fn main(a: Field) -> pub Field { + std::as_witness(a); + a +}