From 1f470e52c6fb32cafbf10a19838af6b77d87cc97 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:11:07 +0100 Subject: [PATCH 1/2] chore: remove unnecessary `AcirValue`s (#2823) --- .../src/ssa/acir_gen/acir_ir/acir_variable.rs | 16 +++------- .../noirc_evaluator/src/ssa/acir_gen/mod.rs | 32 +++++-------------- 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index 61ad747421a..0567118b419 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -285,13 +285,12 @@ impl AcirContext { // Compute the inverse with brillig code let inverse_code = brillig_directive::directive_invert(); - let field_type = AcirType::NumericType(NumericType::NativeField); let results = self.brillig( predicate, inverse_code, - vec![AcirValue::Var(var, field_type.clone())], - vec![field_type], + vec![AcirValue::Var(var, AcirType::field())], + vec![AcirType::field()], )?; let inverted_var = Self::expect_one_var(results); @@ -917,17 +916,10 @@ impl AcirContext { AcirValue::DynamicArray(AcirDynamicArray { block_id, len }) => { for i in 0..len { // We generate witnesses corresponding to the array values - let index = AcirValue::Var( - self.add_constant(FieldElement::from(i as u128)), - AcirType::NumericType(NumericType::NativeField), - ); - let index_var = index.into_var()?; + let index_var = self.add_constant(FieldElement::from(i as u128)); let value_read_var = self.read_from_memory(block_id, &index_var)?; - let value_read = AcirValue::Var( - value_read_var, - AcirType::NumericType(NumericType::NativeField), - ); + let value_read = AcirValue::Var(value_read_var, AcirType::field()); self.brillig_array_input(var_expressions, value_read)?; } diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs index 0f238bd2858..d16985eb31c 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs @@ -400,11 +400,8 @@ impl Context { let mut read_dynamic_array_index = |block_id: BlockId, array_index: usize| -> Result { - let index = AcirValue::Var( - self.acir_context.add_constant(FieldElement::from(array_index as u128)), - AcirType::NumericType(NumericType::NativeField), - ); - let index_var = index.into_var()?; + let index_var = + self.acir_context.add_constant(FieldElement::from(array_index as u128)); self.acir_context.read_from_memory(block_id, &index_var) }; @@ -896,16 +893,10 @@ impl Context { // Initialize the new array with the values from the old array result_block_id = self.block_id(result_id); let init_values = try_vecmap(0..array_len, |i| { - let index = AcirValue::Var( - self.acir_context.add_constant(FieldElement::from(i as u128)), - AcirType::NumericType(NumericType::NativeField), - ); - let var = index.into_var()?; - let read = self.acir_context.read_from_memory(block_id, &var)?; - Ok::(AcirValue::Var( - read, - AcirType::NumericType(NumericType::NativeField), - )) + let index_var = self.acir_context.add_constant(FieldElement::from(i as u128)); + + let read = self.acir_context.read_from_memory(block_id, &index_var)?; + Ok::(AcirValue::Var(read, AcirType::field())) })?; self.initialize_array( result_block_id, @@ -1609,18 +1600,11 @@ impl Context { AcirValue::DynamicArray(AcirDynamicArray { block_id, len }) => { for i in 0..len { // We generate witnesses corresponding to the array values - let index = AcirValue::Var( - self.acir_context.add_constant(FieldElement::from(i as u128)), - AcirType::NumericType(NumericType::NativeField), - ); + let index_var = self.acir_context.add_constant(FieldElement::from(i as u128)); - let index_var = index.into_var()?; let value_read_var = self.acir_context.read_from_memory(block_id, &index_var)?; - let value_read = AcirValue::Var( - value_read_var, - AcirType::NumericType(NumericType::NativeField), - ); + let value_read = AcirValue::Var(value_read_var, AcirType::field()); old_slice.push_back(value_read); } From 71dbbb863a6f262da4804c17965ace627bf3a278 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 26 Sep 2023 15:38:30 +0100 Subject: [PATCH 2/2] chore(noir_js)!: Rename inner and outer proof methods (#2845) --- tooling/noir_js/test/backend/barretenberg.ts | 10 +++++----- tooling/noir_js/test/node/e2e.test.ts | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tooling/noir_js/test/backend/barretenberg.ts b/tooling/noir_js/test/backend/barretenberg.ts index 6a770cde2f2..cc812084f87 100644 --- a/tooling/noir_js/test/backend/barretenberg.ts +++ b/tooling/noir_js/test/backend/barretenberg.ts @@ -42,7 +42,7 @@ export class Backend { // // The settings for this proof are the same as the settings for a "normal" proof // ie one that is not in the recursive setting. - async generateOuterProof(decompressedWitness: Uint8Array) { + async generateFinalProof(decompressedWitness: Uint8Array) { const makeEasyToVerifyInCircuit = false; return this.generateProof(decompressedWitness, makeEasyToVerifyInCircuit); } @@ -58,7 +58,7 @@ export class Backend { // We set `makeEasyToVerifyInCircuit` to true, which will tell the backend to // generate the proof using components that will make the proof // easier to verify in a circuit. - async generateInnerProof(witness: Uint8Array) { + async generateIntermediateProof(witness: Uint8Array) { const makeEasyToVerifyInCircuit = true; return this.generateProof(witness, makeEasyToVerifyInCircuit); } @@ -83,7 +83,7 @@ export class Backend { // method. // // The number of public inputs denotes how many public inputs are in the inner proof. - async generateInnerProofArtifacts(proof: Uint8Array, numOfPublicInputs = 0) { + async generateIntermediateProofArtifacts(proof: Uint8Array, numOfPublicInputs = 0) { const proofAsFields = await this.api.acirSerializeProofIntoFields(this.acirComposer, proof, numOfPublicInputs); // TODO: perhaps we should put this in the init function. Need to benchmark @@ -100,13 +100,13 @@ export class Backend { }; } - async verifyOuterProof(proof: Uint8Array) { + async verifyFinalProof(proof: Uint8Array) { const makeEasyToVerifyInCircuit = false; const verified = await this.verifyProof(proof, makeEasyToVerifyInCircuit); return verified; } - async verifyInnerProof(proof: Uint8Array) { + async verifyIntermediateProof(proof: Uint8Array) { const makeEasyToVerifyInCircuit = true; return this.verifyProof(proof, makeEasyToVerifyInCircuit); } diff --git a/tooling/noir_js/test/node/e2e.test.ts b/tooling/noir_js/test/node/e2e.test.ts index 18413074871..bbb936ea6e5 100644 --- a/tooling/noir_js/test/node/e2e.test.ts +++ b/tooling/noir_js/test/node/e2e.test.ts @@ -16,10 +16,10 @@ it('end-to-end proof creation and verification (outer)', async () => { // Proof creation const prover = new Backend(assert_lt_json.bytecode); await prover.init(); - const proof = await prover.generateOuterProof(serializedWitness); + const proof = await prover.generateFinalProof(serializedWitness); // Proof verification - const isValid = await prover.verifyOuterProof(proof); + const isValid = await prover.verifyFinalProof(proof); expect(isValid).to.be.true; }); @@ -36,10 +36,10 @@ it('end-to-end proof creation and verification (inner)', async () => { // Proof creation const prover = new Backend(assert_lt_json.bytecode); await prover.init(); - const proof = await prover.generateInnerProof(serializedWitness); + const proof = await prover.generateIntermediateProof(serializedWitness); // Proof verification - const isValid = await prover.verifyInnerProof(proof); + const isValid = await prover.verifyIntermediateProof(proof); expect(isValid).to.be.true; }); @@ -67,12 +67,12 @@ it('[BUG] -- bb.js null function or function signature mismatch (different insta const prover = new Backend(assert_lt_json.bytecode); await prover.init(); - const proof = await prover.generateOuterProof(serializedWitness); + const proof = await prover.generateFinalProof(serializedWitness); try { const verifier = new Backend(assert_lt_json.bytecode); await verifier.init(); - await verifier.verifyOuterProof(proof); + await verifier.verifyFinalProof(proof); expect.fail( 'bb.js currently returns a bug when we try to verify a proof with a different Barretenberg instance that created it.', ); @@ -105,13 +105,13 @@ it('[BUG] -- bb.js null function or function signature mismatch (outer-inner) ', await prover.init(); // Create a proof using both proving systems, the majority of the time // one would only use outer proofs. - const proofOuter = await prover.generateOuterProof(serializedWitness); - const _proofInner = await prover.generateInnerProof(serializedWitness); + const proofOuter = await prover.generateFinalProof(serializedWitness); + const _proofInner = await prover.generateIntermediateProof(serializedWitness); // Proof verification // try { - const isValidOuter = await prover.verifyOuterProof(proofOuter); + const isValidOuter = await prover.verifyFinalProof(proofOuter); expect(isValidOuter).to.be.true; // We can also try verifying an inner proof and it will fail. // const isValidInner = await prover.verifyInnerProof(_proofInner);