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

feat: adding structure to Transcript #2937

Merged
merged 23 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cea5c1b
combined transcripts to be all in base transcript
lucasxia01 Oct 19, 2023
b7fc57e
minor update
lucasxia01 Oct 19, 2023
4bd910a
initialize serialization function
lucasxia01 Oct 19, 2023
f37e650
added serialization,
lucasxia01 Oct 20, 2023
15526d5
small fix
lucasxia01 Oct 20, 2023
029ae02
initial integration of flavored transcripts, might be incomplete
lucasxia01 Oct 20, 2023
296724f
initial test of using structure
lucasxia01 Oct 20, 2023
8cca406
updated test, fixed bug
lucasxia01 Oct 23, 2023
750239a
updated eccvm flavors transcript, minor changes
lucasxia01 Oct 23, 2023
33bb44c
added function header comments
lucasxia01 Oct 24, 2023
9563963
added transcript class to recursive flavors, added more comments
lucasxia01 Oct 24, 2023
6130155
Merge branch 'master' into lx/transcript-add-structure
lucasxia01 Oct 25, 2023
8ade65d
small fix
lucasxia01 Oct 25, 2023
27be1f6
small edits to ultra transcript tests
lucasxia01 Oct 25, 2023
a3fd40d
updated ultra transcrip tests,
lucasxia01 Oct 26, 2023
35f67e2
made eccvm tests, fixed bugs and typos in eccvm flavor
lucasxia01 Oct 26, 2023
b41dec5
renamed transcript tests to be ultra,
lucasxia01 Oct 26, 2023
bdcf377
updated Luke's proof tampering recursive tests
lucasxia01 Oct 26, 2023
e1f4b74
small changes, renamed functions
lucasxia01 Oct 30, 2023
8142b97
Merge branch 'master' into lx/transcript-add-structure
lucasxia01 Oct 31, 2023
0e4e07c
merge conflict fix
lucasxia01 Oct 31, 2023
1bb7cbf
Merge branch 'master' into lx/transcript-add-structure
lucasxia01 Oct 31, 2023
22e78b2
update to relation_length variable names
lucasxia01 Oct 31, 2023
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
417 changes: 416 additions & 1 deletion barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ template <size_t mini_circuit_size> class GoblinTranslator_ {

class VerifierCommitments : public AllEntities<Commitment, CommitmentHandle> {
public:
VerifierCommitments(std::shared_ptr<VerificationKey> verification_key, VerifierTranscript<FF> transcript)
VerifierCommitments(std::shared_ptr<VerificationKey> verification_key, BaseTranscript<FF>& transcript)
lucasxia01 marked this conversation as resolved.
Show resolved Hide resolved
{
static_cast<void>(transcript);
static_cast<void>(verification_key);
Expand Down
106 changes: 105 additions & 1 deletion barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ class GoblinUltra {

class VerifierCommitments : public AllEntities<Commitment, CommitmentHandle> {
public:
VerifierCommitments(std::shared_ptr<VerificationKey> verification_key, VerifierTranscript<FF> transcript)
VerifierCommitments(std::shared_ptr<VerificationKey> verification_key, const BaseTranscript<FF>& transcript)
{
static_cast<void>(transcript);
q_m = verification_key->q_m;
Expand Down Expand Up @@ -451,6 +451,110 @@ class GoblinUltra {
std::vector<FF> gate_separation_challenges;
FF target_sum;
};

/**
* @brief Derived class that defines proof structure for GoblinUltra proofs, as well as supporting functions.
*
*/
class Transcript : public BaseTranscript<FF> {
public:
uint32_t circuit_size;
uint32_t public_input_size;
uint32_t pub_inputs_offset;
std::vector<FF> public_inputs;
Commitment w_l_comm;
Commitment w_r_comm;
Commitment w_o_comm;
Commitment ecc_op_wire_1_comm;
Commitment ecc_op_wire_2_comm;
Commitment ecc_op_wire_3_comm;
Commitment ecc_op_wire_4_comm;
Commitment sorted_accum_comm;
Commitment w_4_comm;
Commitment z_perm_comm;
Commitment z_lookup_comm;
std::vector<barretenberg::Univariate<FF, MAX_RANDOM_RELATION_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;

Transcript() = default;

Transcript(const std::vector<uint8_t>& proof)
: BaseTranscript<FF>(proof)
{}
void deserialize_full_transcript() override
{
// take current proof and put them into the struct
size_t num_bytes_read = 0;
circuit_size = deserialize_object<uint32_t>(proof_data, num_bytes_read);
size_t log_n = numeric::get_msb(circuit_size);

public_input_size = deserialize_object<uint32_t>(proof_data, num_bytes_read);
pub_inputs_offset = deserialize_object<uint32_t>(proof_data, num_bytes_read);
for (size_t i = 0; i < public_input_size; ++i) {
public_inputs.push_back(deserialize_object<FF>(proof_data, num_bytes_read));
}
w_l_comm = deserialize_object<Commitment>(proof_data, num_bytes_read);
w_r_comm = deserialize_object<Commitment>(proof_data, num_bytes_read);
w_o_comm = deserialize_object<Commitment>(proof_data, num_bytes_read);
ecc_op_wire_1_comm = deserialize_object<Commitment>(proof_data, num_bytes_read);
ecc_op_wire_2_comm = deserialize_object<Commitment>(proof_data, num_bytes_read);
ecc_op_wire_3_comm = deserialize_object<Commitment>(proof_data, num_bytes_read);
ecc_op_wire_4_comm = deserialize_object<Commitment>(proof_data, num_bytes_read);
sorted_accum_comm = deserialize_object<Commitment>(proof_data, num_bytes_read);
w_4_comm = deserialize_object<Commitment>(proof_data, num_bytes_read);
z_perm_comm = deserialize_object<Commitment>(proof_data, num_bytes_read);
z_lookup_comm = deserialize_object<Commitment>(proof_data, num_bytes_read);
for (size_t i = 0; i < log_n; ++i) {
sumcheck_univariates.push_back(
deserialize_object<barretenberg::Univariate<FF, MAX_RANDOM_RELATION_LENGTH>>(proof_data,
num_bytes_read));
}
sumcheck_evaluations = deserialize_object<std::array<FF, NUM_ALL_ENTITIES>>(proof_data, num_bytes_read);
for (size_t i = 0; i < log_n; ++i) {
zm_cq_comms.push_back(deserialize_object<Commitment>(proof_data, num_bytes_read));
}
zm_cq_comm = deserialize_object<Commitment>(proof_data, num_bytes_read);
zm_pi_comm = deserialize_object<Commitment>(proof_data, num_bytes_read);
}

void serialize_full_transcript() override
{
size_t old_proof_length = proof_data.size();
proof_data.clear();
size_t log_n = numeric::get_msb(circuit_size);
serialize_object(circuit_size, proof_data);
serialize_object(public_input_size, proof_data);
serialize_object(pub_inputs_offset, proof_data);
for (size_t i = 0; i < public_input_size; ++i) {
serialize_object(public_inputs[i], proof_data);
}
serialize_object(w_l_comm, proof_data);
serialize_object(w_r_comm, proof_data);
serialize_object(w_o_comm, proof_data);
serialize_object(ecc_op_wire_1_comm, proof_data);
serialize_object(ecc_op_wire_2_comm, proof_data);
serialize_object(ecc_op_wire_3_comm, proof_data);
serialize_object(ecc_op_wire_4_comm, proof_data);
serialize_object(sorted_accum_comm, proof_data);
serialize_object(w_4_comm, proof_data);
serialize_object(z_perm_comm, proof_data);
serialize_object(z_lookup_comm, proof_data);
for (size_t i = 0; i < log_n; ++i) {
serialize_object(sumcheck_univariates[i], proof_data);
}
serialize_object(sumcheck_evaluations, proof_data);
for (size_t i = 0; i < log_n; ++i) {
serialize_object(zm_cq_comms[i], proof_data);
}
serialize_object(zm_cq_comm, proof_data);
serialize_object(zm_pi_comm, proof_data);

ASSERT(proof_data.size() == old_proof_length);
}
};
};

} // namespace proof_system::honk::flavor
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,140 @@ template <typename BuilderType> class GoblinUltraRecursive_ {
this->lagrange_ecc_op = verification_key->lagrange_ecc_op;
}
};

/**
* @brief Derived class that defines proof structure for GoblinUltraRecursive proofs, as well as supporting
* functions.
*
*/
class Transcript : public BaseTranscript<FF> {
public:
// Transcript objects defined as public member variables for easy access and modification
uint32_t circuit_size;
uint32_t public_input_size;
uint32_t pub_inputs_offset;
std::vector<FF> public_inputs;
Commitment w_l_comm;
Commitment w_r_comm;
Commitment w_o_comm;
Commitment ecc_op_wire_1_comm;
Commitment ecc_op_wire_2_comm;
Commitment ecc_op_wire_3_comm;
Commitment ecc_op_wire_4_comm;
Commitment sorted_accum_comm;
Commitment w_4_comm;
Commitment z_perm_comm;
Commitment z_lookup_comm;
std::vector<barretenberg::Univariate<FF, MAX_RANDOM_RELATION_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;

Transcript() = default;

// Used by verifier to initialize the transcript
Transcript(const std::vector<uint8_t>& proof)
: BaseTranscript<FF>(proof)
{}

static Transcript prover_init_empty()
{
Transcript transcript;
constexpr uint32_t init{ 42 }; // arbitrary
transcript.send_to_verifier("Init", init);
return transcript;
};

static Transcript verifier_init_empty(const Transcript& transcript)
{
Transcript verifier_transcript{ transcript.proof_data };
[[maybe_unused]] auto _ = verifier_transcript.template receive_from_prover<uint32_t>("Init");
return verifier_transcript;
};

/**
* @brief Takes a FULL GoblinUltraRecursive proof and deserializes it into the public member variables that
* compose the structure. Must be called in order to access the structure of the proof.
*
*/
void deserialize_full_transcript() override
{
// take current proof and put them into the struct
size_t num_bytes_read = 0;
circuit_size = deserialize_object<uint32_t>(BaseTranscript<FF>::proof_data, num_bytes_read);
size_t log_n = numeric::get_msb(circuit_size);

public_input_size = deserialize_object<uint32_t>(BaseTranscript<FF>::proof_data, num_bytes_read);
pub_inputs_offset = deserialize_object<uint32_t>(BaseTranscript<FF>::proof_data, num_bytes_read);
for (size_t i = 0; i < public_input_size; ++i) {
public_inputs.push_back(deserialize_object<FF>(BaseTranscript<FF>::proof_data, num_bytes_read));
}
w_l_comm = deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read);
w_r_comm = deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read);
w_o_comm = deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read);
ecc_op_wire_1_comm = deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read);
ecc_op_wire_2_comm = deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read);
ecc_op_wire_3_comm = deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read);
ecc_op_wire_4_comm = deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read);
sorted_accum_comm = deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read);
w_4_comm = deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read);
z_perm_comm = deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read);
z_lookup_comm = deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read);
for (size_t i = 0; i < log_n; ++i) {
sumcheck_univariates.push_back(
deserialize_object<barretenberg::Univariate<FF, MAX_RANDOM_RELATION_LENGTH>>(
BaseTranscript<FF>::proof_data, num_bytes_read));
}
sumcheck_evaluations =
deserialize_object<std::array<FF, NUM_ALL_ENTITIES>>(BaseTranscript<FF>::proof_data, num_bytes_read);
for (size_t i = 0; i < log_n; ++i) {
zm_cq_comms.push_back(deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read));
}
zm_cq_comm = deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read);
zm_pi_comm = deserialize_object<Commitment>(BaseTranscript<FF>::proof_data, num_bytes_read);
}
/**
* @brief Serializes the structure variables into a FULL GoblinUltraRecursive proof. Should be called only if
* deserialize_full_transcript() was called and some transcript variable was modified.
*
*/
void serialize_full_transcript() override
{
size_t old_proof_length = BaseTranscript<FF>::proof_data.size();
BaseTranscript<FF>::proof_data.clear(); // clear proof_data so the rest of the function can replace it
size_t log_n = numeric::get_msb(circuit_size);
serialize_object(circuit_size, BaseTranscript<FF>::proof_data);
serialize_object(public_input_size, BaseTranscript<FF>::proof_data);
serialize_object(pub_inputs_offset, BaseTranscript<FF>::proof_data);
for (size_t i = 0; i < public_input_size; ++i) {
serialize_object(public_inputs[i], BaseTranscript<FF>::proof_data);
}
serialize_object(w_l_comm, BaseTranscript<FF>::proof_data);
serialize_object(w_r_comm, BaseTranscript<FF>::proof_data);
serialize_object(w_o_comm, BaseTranscript<FF>::proof_data);
serialize_object(ecc_op_wire_1_comm, BaseTranscript<FF>::proof_data);
serialize_object(ecc_op_wire_2_comm, BaseTranscript<FF>::proof_data);
serialize_object(ecc_op_wire_3_comm, BaseTranscript<FF>::proof_data);
serialize_object(ecc_op_wire_4_comm, BaseTranscript<FF>::proof_data);
serialize_object(sorted_accum_comm, BaseTranscript<FF>::proof_data);
serialize_object(w_4_comm, BaseTranscript<FF>::proof_data);
serialize_object(z_perm_comm, BaseTranscript<FF>::proof_data);
serialize_object(z_lookup_comm, BaseTranscript<FF>::proof_data);
for (size_t i = 0; i < log_n; ++i) {
serialize_object(sumcheck_univariates[i], BaseTranscript<FF>::proof_data);
}
serialize_object(sumcheck_evaluations, BaseTranscript<FF>::proof_data);
for (size_t i = 0; i < log_n; ++i) {
serialize_object(zm_cq_comms[i], BaseTranscript<FF>::proof_data);
}
serialize_object(zm_cq_comm, BaseTranscript<FF>::proof_data);
serialize_object(zm_pi_comm, BaseTranscript<FF>::proof_data);

// sanity check to make sure we generate the same length of proof as before.
ASSERT(BaseTranscript<FF>::proof_data.size() == old_proof_length);
}
};
};

} // namespace proof_system::honk::flavor
Loading