Skip to content

Commit

Permalink
reinstate manifest test for Ultra
Browse files Browse the repository at this point in the history
  • Loading branch information
ledwards2225 committed Sep 22, 2023
1 parent e4eefa0 commit 81212df
Showing 1 changed file with 134 additions and 1 deletion.
135 changes: 134 additions & 1 deletion barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,147 @@ using namespace proof_system::honk;
class UltraTranscriptTests : public ::testing::Test {
public:
static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); }

using Flavor = proof_system::honk::flavor::Ultra;
using FF = Flavor::FF;

/**
* @brief Construct a manifest for a Ultra Honk proof
*
* @details This is where we define the "Manifest" for a Ultra Honk proof. The tests in this suite are
* intented to warn the developer if the Prover/Verifier has deviated from this manifest, however, the
* Transcript class is not otherwise contrained to follow the manifest.
*
* @note Entries in the manifest consist of a name string and a size (bytes), NOT actual data.
*
* @return TranscriptManifest
*/
TranscriptManifest construct_ultra_honk_manifest(size_t circuit_size)
{
TranscriptManifest manifest_expected;

auto log_n = numeric::get_msb(circuit_size);

size_t max_relation_length = Flavor::MAX_RANDOM_RELATION_LENGTH;
size_t size_FF = sizeof(FF);
size_t size_G = 2 * size_FF;
size_t size_uni = max_relation_length * size_FF;
size_t size_evals = (Flavor::NUM_ALL_ENTITIES)*size_FF;
size_t size_uint32 = 4;
size_t size_uint64 = 8;

size_t round = 0;
manifest_expected.add_entry(round, "circuit_size", size_uint32);
manifest_expected.add_entry(round, "public_input_size", size_uint32);
manifest_expected.add_entry(round, "pub_inputs_offset", size_uint32);
manifest_expected.add_entry(round, "public_input_0", size_FF);
manifest_expected.add_entry(round, "W_L", size_G);
manifest_expected.add_entry(round, "W_R", size_G);
manifest_expected.add_entry(round, "W_O", size_G);
manifest_expected.add_challenge(round, "eta");

round++;
manifest_expected.add_entry(round, "SORTED_ACCUM", size_G);
manifest_expected.add_entry(round, "W_4", size_G);
manifest_expected.add_challenge(round, "beta", "gamma");

round++;
manifest_expected.add_entry(round, "Z_PERM", size_G);
manifest_expected.add_entry(round, "Z_LOOKUP", size_G);
manifest_expected.add_challenge(round, "Sumcheck:alpha", "Sumcheck:zeta");

for (size_t i = 0; i < log_n; ++i) {
round++;
std::string idx = std::to_string(i);
manifest_expected.add_entry(round, "Sumcheck:univariate_" + idx, size_uni);
std::string label = "Sumcheck:u_" + idx;
manifest_expected.add_challenge(round, label);
}

round++;
manifest_expected.add_entry(round, "Sumcheck:evaluations", size_evals);
manifest_expected.add_challenge(round, "rho");

round++;
for (size_t i = 1; i < log_n; ++i) {
std::string idx = std::to_string(i);
manifest_expected.add_entry(round, "Gemini:FOLD_" + idx, size_G);
}
manifest_expected.add_challenge(round, "Gemini:r");

round++;
for (size_t i = 0; i < log_n; ++i) {
std::string idx = std::to_string(i);
manifest_expected.add_entry(round, "Gemini:a_" + idx, size_FF);
}
manifest_expected.add_challenge(round, "Shplonk:nu");

round++;
manifest_expected.add_entry(round, "Shplonk:Q", size_G);
manifest_expected.add_challenge(round, "Shplonk:z");

round++;
// TODO(Mara): Make testing more flavor agnostic so we can test this with all flavors
if constexpr (proof_system::IsGrumpkinFlavor<Flavor>) {
manifest_expected.add_entry(round, "IPA:poly_degree", size_uint64);
manifest_expected.add_challenge(round, "IPA:generator_challenge");

for (size_t i = 0; i < log_n; i++) {
round++;
std::string idx = std::to_string(i);
manifest_expected.add_entry(round, "IPA:L_" + idx, size_G);
manifest_expected.add_entry(round, "IPA:R_" + idx, size_G);
std::string label = "IPA:round_challenge_" + idx;
manifest_expected.add_challenge(round, label);
}

round++;
manifest_expected.add_entry(round, "IPA:a_0", size_FF);
} else {
manifest_expected.add_entry(round, "KZG:W", size_G);
}

manifest_expected.add_challenge(round); // no challenge

return manifest_expected;
}
};

/**
* @brief Ensure consistency between the manifest hard coded in this testing suite and the one generated by the
* standard honk prover over the course of proof construction.
*/
TEST_F(UltraTranscriptTests, ProverManifestConsistency)
{
// Construct a simple circuit of size n = 8 (i.e. the minimum circuit size)
typename Flavor::FF a = 1;
auto builder = typename Flavor::CircuitBuilder();
builder.add_variable(a);
builder.add_public_variable(a);

// Automatically generate a transcript manifest by constructing a proof
auto composer = UltraComposer();
auto instance = composer.create_instance(builder);
auto prover = composer.create_prover(instance);
auto proof = prover.construct_proof();

// Check that the prover generated manifest agrees with the manifest hard coded in this suite
auto manifest_expected = construct_ultra_honk_manifest(instance->proving_key->circuit_size);
auto prover_manifest = prover.transcript.get_manifest();
// Note: a manifest can be printed using manifest.print()
prover_manifest.print();
manifest_expected.print();
for (size_t round = 0; round < manifest_expected.size(); ++round) {
ASSERT_EQ(prover_manifest[round], manifest_expected[round]) << "Prover manifest discrepency in round " << round;
}
}

/**
* @brief Ensure consistency between the manifest generated by the ultra honk prover over the course of proof
* construction and the one generated by the verifier over the course of proof verification.
*
*/
TEST_F(UltraTranscriptTests, UltraVerifierManifestConsistency)
TEST_F(UltraTranscriptTests, VerifierManifestConsistency)
{

// Construct a simple circuit of size n = 8 (i.e. the minimum circuit size)
Expand Down

0 comments on commit 81212df

Please sign in to comment.