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

chore: uncomment asserts in oink rec verifier #8316

Merged
merged 8 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -185,6 +185,10 @@ 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a comment to explain why this is a special case please

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also a bit confused how this is related to the tampered fold proof

Copy link
Contributor Author

@lucasxia01 lucasxia01 Sep 2, 2024

Choose a reason for hiding this comment

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

the 4th circuit (idx == 3) is the kernel circuit that calls the recursive folding verifier with the folding proofs of the 2nd and 3rd instances. Since we're tampering with the first proof, this circuit now throws an error from the oink checks added in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to be more clear, on line 191, there's an if statement for idx == 2 that tampers the proof.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for explaining! would you be able to add a comment about this and then I think it's a pretty good failing test. Will approve

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);

Expand All @@ -193,8 +197,6 @@ 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
Expand All @@ -207,6 +209,10 @@ 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));
break;
}
auto circuit = circuit_producer.create_next_circuit(ivc, /*log2_num_gates=*/5);
ivc.accumulate(circuit);

Expand All @@ -215,8 +221,6 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,9 @@ 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_FALSE(prove_and_verify(ivc));
EXPECT_ANY_THROW(ivc.accumulate(circuit_2));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now that these tests don't fail at prove_and_verify, maybe could make new tests that do, but not sure if that's possible anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused why that's the case, can you clarify

Copy link
Contributor Author

Choose a reason for hiding this comment

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

they fail at accumulate now because the proof has bad data so the recursive verifier throws an error.

};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ template <typename Flavor> void OinkRecursiveVerifier_<Flavor>::verify()
CommitmentLabels labels;

FF circuit_size = transcript->template receive_from_prover<FF>(domain_separator + "circuit_size");
transcript->template receive_from_prover<FF>(domain_separator + "public_input_size");
transcript->template receive_from_prover<FF>(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<uint32_t>(circuit_size.get_value()) == key->circuit_size);
// ASSERT(static_cast<uint32_t>(public_input_size.get_value()) == key->num_public_inputs);
// ASSERT(static_cast<uint32_t>(pub_inputs_offset.get_value()) == key->pub_inputs_offset);
FF public_input_size = transcript->template receive_from_prover<FF>(domain_separator + "public_input_size");
FF pub_inputs_offset = transcript->template receive_from_prover<FF>(domain_separator + "pub_inputs_offset");

if (static_cast<uint32_t>(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<uint32_t>(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<uint32_t>(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<FF> public_inputs;
for (size_t i = 0; i < instance->verification_key->num_public_inputs; ++i) {
Expand Down
Loading