Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
chonk_transcript_invariants.test.cpp
Go to the documentation of this file.
1
41#include <gtest/gtest.h>
42
43using namespace bb;
44
48class ChonkTranscriptInvariantTests : public ::testing::Test {
49 protected:
51};
52
85TEST_F(ChonkTranscriptInvariantTests, AccumulationTranscriptCount)
86{
87 // Pinned expected transcript count for a MAX_APPS_PER_KERNEL + 1 app IVC (one full app group + a one-app
88 // remainder group, then the reset-tail and hiding kernels). Values below assume MAX_APPS_PER_KERNEL == 5.
89 static_assert(MAX_APPS_PER_KERNEL == 5, "Update pinned transcript counts if MAX_APPS_PER_KERNEL changes");
90 constexpr size_t EXPECTED_TOTAL_TRANSCRIPTS = 11;
91 constexpr size_t EXPECTED_NUM_CIRCUITS = 10;
92 constexpr std::array<size_t, EXPECTED_NUM_CIRCUITS> EXPECTED_CIRCUIT_TRANSCRIPTS = { 0, 0, 0, 0, 0, 3, 0, 3, 2, 3 };
93
94 // Record transcript index before IVC
95 size_t index_before_ivc = bb::unique_transcript_index.load();
96
97 // Track indices at each circuit accumulation
98 std::vector<size_t> indices_before_accumulation;
99 std::vector<size_t> indices_after_accumulation;
100
101 // Create IVC with MAX_APPS_PER_KERNEL + 1 app circuits to force a full app group plus a one-app remainder group.
102 constexpr size_t NUM_APP_CIRCUITS = MAX_APPS_PER_KERNEL + 1;
103 PrivateFunctionExecutionMockCircuitProducer circuit_producer(NUM_APP_CIRCUITS);
104 const size_t num_circuits = circuit_producer.total_num_circuits;
105 ASSERT_EQ(num_circuits, EXPECTED_NUM_CIRCUITS) << "Circuit count mismatch - test assumptions invalid";
106
107 Chonk ivc{ circuit_producer.circuit_kinds() };
108
109 for (size_t j = 0; j < num_circuits; ++j) {
110 indices_before_accumulation.push_back(bb::unique_transcript_index.load());
111 circuit_producer.construct_and_accumulate_next_circuit(ivc);
112 indices_after_accumulation.push_back(bb::unique_transcript_index.load());
113 }
114
115 size_t index_after_ivc = bb::unique_transcript_index.load();
116 size_t total_transcripts = index_after_ivc - index_before_ivc;
117
118 // Pin the total number of transcripts created during accumulation
119 EXPECT_EQ(total_transcripts, EXPECTED_TOTAL_TRANSCRIPTS)
120 << "Total transcript count during 4-app IVC accumulation changed. "
121 << "If intentional, update EXPECTED_TOTAL_TRANSCRIPTS. "
122 << "Unexpected changes may indicate security-relevant transcript isolation issues.";
123
124 // Pin per-circuit transcript counts
125 for (size_t i = 0; i < num_circuits; ++i) {
126 size_t circuit_transcripts = indices_after_accumulation[i] - indices_before_accumulation[i];
127 EXPECT_EQ(circuit_transcripts, EXPECTED_CIRCUIT_TRANSCRIPTS[i])
128 << "Circuit " << i << " transcript count changed from " << EXPECTED_CIRCUIT_TRANSCRIPTS[i] << " to "
129 << circuit_transcripts;
130 }
131
132 // Generate and verify proof
133 auto proof = ivc.prove();
134 auto vk_and_hash = ivc.get_hiding_kernel_vk_and_hash();
135 ChonkNativeVerifier verifier(vk_and_hash);
136 EXPECT_TRUE(verifier.verify(proof)) << "IVC proof should verify";
137}
138
150TEST_F(ChonkTranscriptInvariantTests, RecursiveVerificationTranscriptCount)
151{
152 using RecursiveVerifier = ChonkRecursiveVerifier;
153
154 // Create a minimal IVC and generate proof
155 constexpr size_t NUM_APP_CIRCUITS = 1;
156 PrivateFunctionExecutionMockCircuitProducer circuit_producer(NUM_APP_CIRCUITS);
157 const size_t num_circuits = circuit_producer.total_num_circuits;
158 Chonk ivc{ circuit_producer.circuit_kinds() };
159
160 for (size_t j = 0; j < num_circuits; ++j) {
161 circuit_producer.construct_and_accumulate_next_circuit(ivc);
162 }
163
164 auto proof = ivc.prove();
165 auto vk_and_hash = ivc.get_hiding_kernel_vk_and_hash();
166
167 // Perform recursive verification and track transcript creation
168 // unique_transcript_index is only incremented for in-circuit transcripts (in_circuit == true)
170 size_t index_before_verify = bb::unique_transcript_index.load();
171
172 // Create stdlib VK and hash from native VK
173 auto stdlib_vk_and_hash = std::make_shared<RecursiveVerifier::VKAndHash>(builder, vk_and_hash->vk);
174
175 RecursiveVerifier verifier(stdlib_vk_and_hash);
176 ChonkStdlibProof stdlib_proof(builder, proof);
177 [[maybe_unused]] auto output = verifier.verify(stdlib_proof);
178
179 size_t index_after_verify = bb::unique_transcript_index.load();
180 size_t transcripts_created = index_after_verify - index_before_verify;
181
182 // Pin the exact number of transcripts created during recursive verification
183 constexpr size_t EXPECTED_TRANSCRIPTS_DURING_RECURSIVE_VERIFY = 2;
184 EXPECT_EQ(transcripts_created, EXPECTED_TRANSCRIPTS_DURING_RECURSIVE_VERIFY)
185 << "ChonkRecursiveVerifier transcript count changed. "
186 << "If intentional, update EXPECTED_TRANSCRIPTS_DURING_RECURSIVE_VERIFY. "
187 << "Unexpected changes may indicate security-relevant transcript isolation issues.";
188}
TEST_F(ChonkTranscriptInvariantTests, AccumulationTranscriptCount)
Pin the exact number of transcripts created during IVC accumulation.
Test fixture for Chonk transcript invariant tests.
The IVC scheme used by the aztec client for private function execution.
Definition chonk.hpp:42
std::vector< CircuitKind > circuit_kinds
Definition chonk.hpp:159
Verifier for Chonk IVC proofs (both native and recursive).
Output verify(const Proof &proof)
Verify a Chonk proof.
AluTraceBuilder builder
Definition alu.test.cpp:124
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
std::atomic< size_t > unique_transcript_index
ChonkVerifier< true > ChonkRecursiveVerifier
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Chonk proof type.