Skip to content

Commit

Permalink
9349: Transcript serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmon committed Oct 24, 2024
1 parent 42af344 commit 2621970
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 42 deletions.
44 changes: 27 additions & 17 deletions barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2321,53 +2321,63 @@ AvmFlavor::CommitmentLabels::CommitmentLabels()
Base::incl_mem_tag_err_counts = "INCL_MEM_TAG_ERR_COUNTS";
};

// Note: current de-/serialization routines are not including the padded zero univariates which are added as part of
// current sumcheck implementation. Namely, this algorithm is padding to reach CONST_PROOF_SIZE_LOG_N sumcheck rounds.
// Similarly, Shplemini implementation performs same padding over some commitments (zm_cq_comms).
// In code below, the loops are of size log(circuit_size) instead of CONST_PROOF_SIZE_LOG_N.
void AvmFlavor::Transcript::deserialize_full_transcript()
{
size_t num_frs_read = 0;
circuit_size = deserialize_from_buffer<uint32_t>(proof_data, num_frs_read);
size_t log_n = numeric::get_msb(circuit_size);

for (auto& commitment : commitments) {
commitment = deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
}
for (size_t i = 0; i < log_n; ++i) {

for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N; ++i) {
sumcheck_univariates.emplace_back(deserialize_from_buffer<bb::Univariate<FF, BATCHED_RELATION_PARTIAL_LENGTH>>(
Transcript::proof_data, num_frs_read));
}

sumcheck_evaluations =
deserialize_from_buffer<std::array<FF, NUM_ALL_ENTITIES>>(Transcript::proof_data, num_frs_read);
for (size_t i = 0; i < log_n; ++i) {
zm_cq_comms.push_back(deserialize_from_buffer<Commitment>(proof_data, num_frs_read));

for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N - 1; ++i) {
gemini_fold_comms.push_back(deserialize_from_buffer<Commitment>(proof_data, num_frs_read));
}
zm_cq_comm = deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
zm_pi_comm = deserialize_from_buffer<Commitment>(proof_data, num_frs_read);

for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N; ++i) {
gemini_fold_evals.push_back(deserialize_from_buffer<FF>(proof_data, num_frs_read));
}

shplonk_q_comm = deserialize_from_buffer<Commitment>(proof_data, num_frs_read);

kzg_w_comm = deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
}

// See note above AvmFlavor::Transcript::deserialize_full_transcript()
void AvmFlavor::Transcript::serialize_full_transcript()
{
size_t old_proof_length = proof_data.size();
Transcript::proof_data.clear();
size_t log_n = numeric::get_msb(circuit_size);

serialize_to_buffer(circuit_size, Transcript::proof_data);

for (const auto& commitment : commitments) {
serialize_to_buffer(commitment, Transcript::proof_data);
}
for (size_t i = 0; i < log_n; ++i) {

for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N; ++i) {
serialize_to_buffer(sumcheck_univariates[i], Transcript::proof_data);
}

serialize_to_buffer(sumcheck_evaluations, Transcript::proof_data);
for (size_t i = 0; i < log_n; ++i) {
serialize_to_buffer(zm_cq_comms[i], proof_data);

for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N - 1; ++i) {
serialize_to_buffer(gemini_fold_comms[i], proof_data);
}
serialize_to_buffer(zm_cq_comm, proof_data);
serialize_to_buffer(zm_pi_comm, proof_data);

for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N; ++i) {
serialize_to_buffer(gemini_fold_evals[i], proof_data);
}

serialize_to_buffer(shplonk_q_comm, proof_data);
serialize_to_buffer(kzg_w_comm, proof_data);

// sanity check to make sure we generate the same length of proof as before.
ASSERT(proof_data.size() == old_proof_length);
Expand Down
7 changes: 4 additions & 3 deletions barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,10 @@ class AvmFlavor {

std::vector<bb::Univariate<FF, BATCHED_RELATION_PARTIAL_LENGTH>> sumcheck_univariates;
std::array<FF, NUM_ALL_ENTITIES> sumcheck_evaluations;
std::vector<Commitment> zm_cq_comms;
Commitment zm_cq_comm;
Commitment zm_pi_comm;
std::vector<Commitment> gemini_fold_comms;
std::vector<FF> gemini_fold_evals;
Commitment shplonk_q_comm;
Commitment kzg_w_comm;

Transcript() = default;

Expand Down
48 changes: 29 additions & 19 deletions bb-pilcom/bb-pil-backend/templates/flavor.cpp.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -46,52 +46,62 @@ namespace bb {
{{/each}}
};

// Note: current de-/serialization routines are not including the padded zero univariates which are added as part of
// current sumcheck implementation. Namely, this algorithm is padding to reach CONST_PROOF_SIZE_LOG_N sumcheck rounds.
// Similarly, Shplemini implementation performs same padding over some commitments (zm_cq_comms).
// In code below, the loops are of size log(circuit_size) instead of CONST_PROOF_SIZE_LOG_N.
void {{name}}Flavor::Transcript::deserialize_full_transcript() {
size_t num_frs_read = 0;
circuit_size = deserialize_from_buffer<uint32_t>(proof_data, num_frs_read);
size_t log_n = numeric::get_msb(circuit_size);

for (auto& commitment : commitments) {
commitment = deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
}
for (size_t i = 0; i < log_n; ++i) {

for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N; ++i) {
sumcheck_univariates.emplace_back(
deserialize_from_buffer<bb::Univariate<FF, BATCHED_RELATION_PARTIAL_LENGTH>>(
Transcript::proof_data, num_frs_read));
}
sumcheck_evaluations = deserialize_from_buffer<std::array<FF, NUM_ALL_ENTITIES>>(
Transcript::proof_data, num_frs_read);
for (size_t i = 0; i < log_n; ++i) {
zm_cq_comms.push_back(deserialize_from_buffer<Commitment>(proof_data, num_frs_read));

sumcheck_evaluations =
deserialize_from_buffer<std::array<FF, NUM_ALL_ENTITIES>>(Transcript::proof_data, num_frs_read);

for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N - 1; ++i) {
gemini_fold_comms.push_back(deserialize_from_buffer<Commitment>(proof_data, num_frs_read));
}
zm_cq_comm = deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
zm_pi_comm = deserialize_from_buffer<Commitment>(proof_data, num_frs_read);

for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N; ++i) {
gemini_fold_evals.push_back(deserialize_from_buffer<FF>(proof_data, num_frs_read));
}

shplonk_q_comm = deserialize_from_buffer<Commitment>(proof_data, num_frs_read);

kzg_w_comm = deserialize_from_buffer<Commitment>(proof_data, num_frs_read);
}

// See note above AvmFlavor::Transcript::deserialize_full_transcript()
void {{name}}Flavor::Transcript::serialize_full_transcript() {
size_t old_proof_length = proof_data.size();
Transcript::proof_data.clear();
size_t log_n = numeric::get_msb(circuit_size);

serialize_to_buffer(circuit_size, Transcript::proof_data);

for (const auto& commitment : commitments) {
serialize_to_buffer(commitment, Transcript::proof_data);
}
for (size_t i = 0; i < log_n; ++i) {

for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N; ++i) {
serialize_to_buffer(sumcheck_univariates[i], Transcript::proof_data);
}

serialize_to_buffer(sumcheck_evaluations, Transcript::proof_data);
for (size_t i = 0; i < log_n; ++i) {
serialize_to_buffer(zm_cq_comms[i], proof_data);

for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N - 1; ++i) {
serialize_to_buffer(gemini_fold_comms[i], proof_data);
}
serialize_to_buffer(zm_cq_comm, proof_data);
serialize_to_buffer(zm_pi_comm, proof_data);

for (size_t i = 0; i < CONST_PROOF_SIZE_LOG_N; ++i) {
serialize_to_buffer(gemini_fold_evals[i], proof_data);
}

serialize_to_buffer(shplonk_q_comm, proof_data);
serialize_to_buffer(kzg_w_comm, proof_data);

// sanity check to make sure we generate the same length of proof as before.
ASSERT(proof_data.size() == old_proof_length);
Expand Down
7 changes: 4 additions & 3 deletions bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,10 @@ class {{name}}Flavor {

std::vector<bb::Univariate<FF, BATCHED_RELATION_PARTIAL_LENGTH>> sumcheck_univariates;
std::array<FF, NUM_ALL_ENTITIES> sumcheck_evaluations;
std::vector<Commitment> zm_cq_comms;
Commitment zm_cq_comm;
Commitment zm_pi_comm;
std::vector<Commitment> gemini_fold_comms;
std::vector<FF> gemini_fold_evals;
Commitment shplonk_q_comm;
Commitment kzg_w_comm;

Transcript() = default;

Expand Down

0 comments on commit 2621970

Please sign in to comment.