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 84012b3cb85d..09daa6708e17 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) @@ -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,11 @@ 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) { // 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; + } auto circuit = circuit_producer.create_next_circuit(ivc, /*log2_num_gates=*/5); ivc.accumulate(circuit); @@ -193,11 +198,9 @@ TEST_F(AztecIVCTests, BadProofFailure) tamper_with_proof(ivc.verification_queue[0].proof); // tamper with first proof } } - - EXPECT_FALSE(ivc.prove_and_verify()); } - // 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; @@ -207,6 +210,11 @@ 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) { // 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; + } auto circuit = circuit_producer.create_next_circuit(ivc, /*log2_num_gates=*/5); ivc.accumulate(circuit); @@ -215,11 +223,9 @@ TEST_F(AztecIVCTests, BadProofFailure) tamper_with_proof(ivc.verification_queue[1].proof); // tamper with second proof } } - - EXPECT_FALSE(ivc.prove_and_verify()); } - // 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 77685d2717cb..7b8587c086a7 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,13 +128,10 @@ 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); - 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(ivc.accumulate(circuit_2)); }; /** 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..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 @@ -41,14 +41,18 @@ 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"); - - // 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); + 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"); + + 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) {