From ab3fe756484bf462a0682788f8acdcb6f573707f Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 2 Sep 2024 09:08:30 +0000 Subject: [PATCH 1/7] try uncommenting asserts --- .../stdlib/honk_verifier/oink_recursive_verifier.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp index 2a8401d577ea..5f53223f559c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp @@ -41,14 +41,14 @@ template void OinkRecursiveVerifier_::verify() CommitmentLabels labels; FF circuit_size = transcript->template receive_from_prover(domain_separator + "circuit_size"); - transcript->template receive_from_prover(domain_separator + "public_input_size"); - transcript->template receive_from_prover(domain_separator + "pub_inputs_offset"); + FF public_input_size = transcript->template receive_from_prover(domain_separator + "public_input_size"); + FF pub_inputs_offset = transcript->template receive_from_prover(domain_separator + "pub_inputs_offset"); // TODO(https://github.com/AztecProtocol/barretenberg/issues/1032): Uncomment these once it doesn't cause issues // with the flows - // ASSERT(static_cast(circuit_size.get_value()) == key->circuit_size); - // ASSERT(static_cast(public_input_size.get_value()) == key->num_public_inputs); - // ASSERT(static_cast(pub_inputs_offset.get_value()) == key->pub_inputs_offset); + ASSERT(static_cast(circuit_size.get_value()) == instance->verification_key->circuit_size); + ASSERT(static_cast(public_input_size.get_value()) == instance->verification_key->num_public_inputs); + ASSERT(static_cast(pub_inputs_offset.get_value()) == instance->verification_key->pub_inputs_offset); std::vector public_inputs; for (size_t i = 0; i < instance->verification_key->num_public_inputs; ++i) { From c931abc45d6bcb497e8416910acf02a511c0fb9f Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 2 Sep 2024 10:37:29 +0000 Subject: [PATCH 2/7] change to throw_or_abort instead of assert --- .../src/barretenberg/aztec_ivc/aztec_ivc.test.cpp | 12 +++++++++--- .../barretenberg/client_ivc/client_ivc.test.cpp | 2 +- .../honk_verifier/oink_recursive_verifier.cpp | 14 +++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp index 237d8b6b7e77..7a78a609daff 100644 --- a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp @@ -175,7 +175,7 @@ TEST_F(AztecIVCTests, BadProofFailure) EXPECT_TRUE(ivc.prove_and_verify()); } - // The IVC fails to verify if the FIRST fold proof is tampered with + // The IVC throws an exception if the FIRST fold proof is tampered with { AztecIVC ivc; ivc.trace_structure = TraceStructure::SMALL_TEST; @@ -185,6 +185,9 @@ TEST_F(AztecIVCTests, BadProofFailure) // Construct and accumulate a set of mocked private function execution circuits size_t NUM_CIRCUITS = 4; for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { + if (idx == 3) { + EXPECT_ANY_THROW(circuit_producer.create_next_circuit(ivc, /*log2_num_gates=*/5)); + } auto circuit = circuit_producer.create_next_circuit(ivc, /*log2_num_gates=*/5); ivc.accumulate(circuit); @@ -194,7 +197,7 @@ TEST_F(AztecIVCTests, BadProofFailure) } } - EXPECT_FALSE(ivc.prove_and_verify()); + EXPECT_ANY_THROW(ivc.prove_and_verify()); } // The IVC fails to verify if the SECOND fold proof is tampered with @@ -207,6 +210,9 @@ TEST_F(AztecIVCTests, BadProofFailure) // Construct and accumulate a set of mocked private function execution circuits size_t NUM_CIRCUITS = 4; for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { + if (idx == 3) { + EXPECT_ANY_THROW(circuit_producer.create_next_circuit(ivc, /*log2_num_gates=*/5)); + } auto circuit = circuit_producer.create_next_circuit(ivc, /*log2_num_gates=*/5); ivc.accumulate(circuit); @@ -216,7 +222,7 @@ TEST_F(AztecIVCTests, BadProofFailure) } } - EXPECT_FALSE(ivc.prove_and_verify()); + EXPECT_ANY_THROW(ivc.prove_and_verify()); } // The IVC fails to verify if the 3rd/FINAL fold proof is tampered with diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp index 57cf69978372..822ee4d0fc67 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -134,7 +134,7 @@ TEST_F(ClientIVCTests, BasicFailure) ivc.accumulate(circuit_2); // The bad fold proof should result in an invalid witness in the final circuit and the IVC should fail to verify - EXPECT_FALSE(prove_and_verify(ivc)); + EXPECT_ANY_THROW(prove_and_verify(ivc)); }; /** diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp index 5f53223f559c..c058770bc2d3 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp @@ -44,11 +44,15 @@ template void OinkRecursiveVerifier_::verify() FF public_input_size = transcript->template receive_from_prover(domain_separator + "public_input_size"); FF pub_inputs_offset = transcript->template receive_from_prover(domain_separator + "pub_inputs_offset"); - // TODO(https://github.com/AztecProtocol/barretenberg/issues/1032): Uncomment these once it doesn't cause issues - // with the flows - ASSERT(static_cast(circuit_size.get_value()) == instance->verification_key->circuit_size); - ASSERT(static_cast(public_input_size.get_value()) == instance->verification_key->num_public_inputs); - ASSERT(static_cast(pub_inputs_offset.get_value()) == instance->verification_key->pub_inputs_offset); + if (static_cast(circuit_size.get_value()) != instance->verification_key->circuit_size) { + throw_or_abort("OinkRecursiveVerifier::verify: proof circuit size does not match verification key"); + } + if (static_cast(public_input_size.get_value()) != instance->verification_key->num_public_inputs) { + throw_or_abort("OinkRecursiveVerifier::verify: proof public input size does not match verification key"); + } + if (static_cast(pub_inputs_offset.get_value()) != instance->verification_key->pub_inputs_offset) { + throw_or_abort("OinkRecursiveVerifier::verify: proof public input offset does not match verification key"); + } std::vector public_inputs; for (size_t i = 0; i < instance->verification_key->num_public_inputs; ++i) { From d5bb84f426cfd04d9fe53bd647432782a286016b Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 2 Sep 2024 11:15:52 +0000 Subject: [PATCH 3/7] break out of loop after bad circuit --- barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp index 7a78a609daff..2db614f43468 100644 --- a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp @@ -187,6 +187,7 @@ TEST_F(AztecIVCTests, BadProofFailure) for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { if (idx == 3) { EXPECT_ANY_THROW(circuit_producer.create_next_circuit(ivc, /*log2_num_gates=*/5)); + break; } auto circuit = circuit_producer.create_next_circuit(ivc, /*log2_num_gates=*/5); ivc.accumulate(circuit); @@ -212,6 +213,7 @@ TEST_F(AztecIVCTests, BadProofFailure) for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { if (idx == 3) { EXPECT_ANY_THROW(circuit_producer.create_next_circuit(ivc, /*log2_num_gates=*/5)); + break; } auto circuit = circuit_producer.create_next_circuit(ivc, /*log2_num_gates=*/5); ivc.accumulate(circuit); From 6b7ff6a654b10e8f6eb4a64c4d059046fd6cdc1a Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 2 Sep 2024 11:17:35 +0000 Subject: [PATCH 4/7] don't run prove and verify after break --- .../cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp index 2db614f43468..a578373c6688 100644 --- a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp @@ -197,8 +197,6 @@ TEST_F(AztecIVCTests, BadProofFailure) tamper_with_proof(ivc.verification_queue[0].proof); // tamper with first proof } } - - EXPECT_ANY_THROW(ivc.prove_and_verify()); } // The IVC fails to verify if the SECOND fold proof is tampered with @@ -223,8 +221,6 @@ TEST_F(AztecIVCTests, BadProofFailure) tamper_with_proof(ivc.verification_queue[1].proof); // tamper with second proof } } - - EXPECT_ANY_THROW(ivc.prove_and_verify()); } // The IVC fails to verify if the 3rd/FINAL fold proof is tampered with From d0cbf9e45d50a5a440ffd7c55c1a07e71d20ebf9 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 2 Sep 2024 11:34:57 +0000 Subject: [PATCH 5/7] fix client ivc proof failure --- .../cpp/src/barretenberg/client_ivc/client_ivc.test.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp index 822ee4d0fc67..0e9abd4d26e7 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -128,13 +128,7 @@ TEST_F(ClientIVCTests, BasicFailure) break; } } - - // Accumulate another circuit; this involves recursive folding verification of the bad proof - Builder circuit_2 = create_mock_circuit(ivc); - ivc.accumulate(circuit_2); - - // The bad fold proof should result in an invalid witness in the final circuit and the IVC should fail to verify - EXPECT_ANY_THROW(prove_and_verify(ivc)); + EXPECT_ANY_THROW(create_mock_circuit(ivc)); }; /** From 41e544197e0c437d60cb64bd8c0a040bd5d8f372 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 2 Sep 2024 11:42:03 +0000 Subject: [PATCH 6/7] attempt #2 --- .../cpp/src/barretenberg/client_ivc/client_ivc.test.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp index 0e9abd4d26e7..af7610a356d3 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -128,7 +128,9 @@ TEST_F(ClientIVCTests, BasicFailure) break; } } - EXPECT_ANY_THROW(create_mock_circuit(ivc)); + // Accumulate another circuit; this involves recursive folding verification of the bad proof + Builder circuit_2 = create_mock_circuit(ivc); + EXPECT_ANY_THROW(ivc.accumulate(circuit_2)); }; /** From 6862c416fe48ddb7bf9a72dfad3453c0662e5565 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 2 Sep 2024 13:08:14 +0000 Subject: [PATCH 7/7] added comments [skip ci] --- .../barretenberg/aztec_ivc/aztec_ivc.test.cpp | 16 +++++++++------- .../barretenberg/client_ivc/client_ivc.test.cpp | 5 +++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp index a578373c6688..ee903d76be93 100644 --- a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp @@ -151,10 +151,10 @@ TEST_F(AztecIVCTests, BasicFour) }; /** - * @brief Check that the IVC fails to verify if an intermediate fold proof is invalid + * @brief Check that the IVC fails if an intermediate fold proof is invalid * @details When accumulating 4 circuits, there are 3 fold proofs to verify (the first two are recursively verfied and - * the 3rd is verified as part of the IVC proof). Check that if any of one of these proofs is invalid, the IVC will fail - * to verify. + * the 3rd is verified as part of the IVC proof). Check that if any of one of these proofs is invalid, the IVC will + * fail. * */ TEST_F(AztecIVCTests, BadProofFailure) @@ -185,7 +185,8 @@ TEST_F(AztecIVCTests, BadProofFailure) // Construct and accumulate a set of mocked private function execution circuits size_t NUM_CIRCUITS = 4; for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { - if (idx == 3) { + if (idx == 3) { // At idx = 3, we've tampered with the one of the folding proofs so create the recursive + // folding verifier will throw an error. EXPECT_ANY_THROW(circuit_producer.create_next_circuit(ivc, /*log2_num_gates=*/5)); break; } @@ -199,7 +200,7 @@ TEST_F(AztecIVCTests, BadProofFailure) } } - // The IVC fails to verify if the SECOND fold proof is tampered with + // The IVC fails if the SECOND fold proof is tampered with { AztecIVC ivc; ivc.trace_structure = TraceStructure::SMALL_TEST; @@ -209,7 +210,8 @@ TEST_F(AztecIVCTests, BadProofFailure) // Construct and accumulate a set of mocked private function execution circuits size_t NUM_CIRCUITS = 4; for (size_t idx = 0; idx < NUM_CIRCUITS; ++idx) { - if (idx == 3) { + if (idx == 3) { // At idx = 3, we've tampered with the one of the folding proofs so create the recursive + // folding verifier will throw an error. EXPECT_ANY_THROW(circuit_producer.create_next_circuit(ivc, /*log2_num_gates=*/5)); break; } @@ -223,7 +225,7 @@ TEST_F(AztecIVCTests, BadProofFailure) } } - // The IVC fails to verify if the 3rd/FINAL fold proof is tampered with + // The IVC fails if the 3rd/FINAL fold proof is tampered with { AztecIVC ivc; ivc.trace_structure = TraceStructure::SMALL_TEST; diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp index af7610a356d3..26299b20395b 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -106,7 +106,7 @@ TEST_F(ClientIVCTests, BasicThree) }; /** - * @brief Check that the IVC fails to verify if an intermediate fold proof is invalid + * @brief Check that the IVC fails if an intermediate fold proof is invalid * */ TEST_F(ClientIVCTests, BasicFailure) @@ -128,7 +128,8 @@ TEST_F(ClientIVCTests, BasicFailure) break; } } - // Accumulate another circuit; this involves recursive folding verification of the bad proof + // Accumulate another circuit; this involves recursive folding verification of the bad proof which throws an error + // because of circuit sizes don't match. Builder circuit_2 = create_mock_circuit(ivc); EXPECT_ANY_THROW(ivc.accumulate(circuit_2)); };