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: Refactor WitnessEntities to be able to derive WitnessCommitments from it #3479

Merged
merged 10 commits into from
Dec 1, 2023
37 changes: 16 additions & 21 deletions barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class GoblinUltra {
// assignment of witnesses. We again choose a neutral name.
static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 28;
// The total number of witness entities not including shifts.
static constexpr size_t NUM_WITNESS_ENTITIES = 18;
static constexpr size_t NUM_WITNESS_ENTITIES = 14;

using GrandProductRelations =
std::tuple<proof_system::UltraPermutationRelation<FF>, proof_system::LookupRelation<FF>>;
Expand Down Expand Up @@ -167,30 +167,22 @@ class GoblinUltra {
DataType w_r; // column 1
DataType w_o; // column 2
DataType w_4; // column 3
DataType sorted_1; // column 4
DataType sorted_2; // column 5
DataType sorted_3; // column 6
DataType sorted_4; // column 7
DataType sorted_accum; // column 8
DataType z_perm; // column 9
DataType z_lookup; // column 10
DataType ecc_op_wire_1; // column 11
DataType ecc_op_wire_2; // column 12
DataType ecc_op_wire_3; // column 13
DataType ecc_op_wire_4; // column 14
DataType calldata; // column 15
DataType calldata_read_counts; // column 16
DataType lookup_inverses; // column 17
DataType sorted_accum; // column 4
DataType z_perm; // column 5
DataType z_lookup; // column 6
DataType ecc_op_wire_1; // column 7
DataType ecc_op_wire_2; // column 8
DataType ecc_op_wire_3; // column 9
DataType ecc_op_wire_4; // column 10
DataType calldata; // column 11
DataType calldata_read_counts; // column 12
DataType lookup_inverses; // column 13

DEFINE_POINTER_VIEW(NUM_WITNESS_ENTITIES,
&w_l,
&w_r,
&w_o,
&w_4,
&sorted_1,
&sorted_2,
&sorted_3,
&sorted_4,
&sorted_accum,
&z_perm,
&z_lookup,
Expand All @@ -207,8 +199,6 @@ class GoblinUltra {
{
return { ecc_op_wire_1, ecc_op_wire_2, ecc_op_wire_3, ecc_op_wire_4 };
};
// The sorted concatenations of table and witness data needed for plookup.
std::vector<HandleType> get_sorted_polynomials() { return { sorted_1, sorted_2, sorted_3, sorted_4 }; };
};

/**
Expand Down Expand Up @@ -482,6 +472,11 @@ class GoblinUltra {
}
};

/**
* @brief A container for the witness commitments.
*/
using WitnessCommitments = WitnessEntities<Commitment, CommitmentHandle>;

/**
* @brief A container for commitment labels.
* @note It's debatable whether this should inherit from AllEntities. since most entries are not strictly needed. It
Expand Down
32 changes: 11 additions & 21 deletions barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ template <typename BuilderType> class GoblinUltraRecursive_ {
// assignment of witnesses. We again choose a neutral name.
static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 28;
// The total number of witness entities not including shifts.
static constexpr size_t NUM_WITNESS_ENTITIES = 18;
static constexpr size_t NUM_WITNESS_ENTITIES = 14;

// define the tuple of Relations that comprise the Sumcheck relation
using Relations = std::tuple<proof_system::UltraArithmeticRelation<FF>,
Expand Down Expand Up @@ -180,30 +180,22 @@ template <typename BuilderType> class GoblinUltraRecursive_ {
DataType w_r; // column 1
DataType w_o; // column 2
DataType w_4; // column 3
DataType sorted_1; // column 4
DataType sorted_2; // column 5
DataType sorted_3; // column 6
DataType sorted_4; // column 7
DataType sorted_accum; // column 8
DataType z_perm; // column 9
DataType z_lookup; // column 10
DataType ecc_op_wire_1; // column 11
DataType ecc_op_wire_2; // column 12
DataType ecc_op_wire_3; // column 13
DataType ecc_op_wire_4; // column 14
DataType calldata; // column 15
DataType calldata_read_counts; // column 16
DataType lookup_inverses; // column 17
DataType sorted_accum; // column 4
DataType z_perm; // column 5
DataType z_lookup; // column 6
DataType ecc_op_wire_1; // column 7
DataType ecc_op_wire_2; // column 8
DataType ecc_op_wire_3; // column 9
DataType ecc_op_wire_4; // column 10
DataType calldata; // column 11
DataType calldata_read_counts; // column 12
DataType lookup_inverses; // column 13

DEFINE_POINTER_VIEW(NUM_WITNESS_ENTITIES,
&w_l,
&w_r,
&w_o,
&w_4,
&sorted_1,
&sorted_2,
&sorted_3,
&sorted_4,
&sorted_accum,
&z_perm,
&z_lookup,
Expand All @@ -220,8 +212,6 @@ template <typename BuilderType> class GoblinUltraRecursive_ {
{
return { ecc_op_wire_1, ecc_op_wire_2, ecc_op_wire_3, ecc_op_wire_4 };
};
// The sorted concatenations of table and witness data needed for plookup.
std::vector<HandleType> get_sorted_polynomials() { return { sorted_1, sorted_2, sorted_3, sorted_4 }; };
};

/**
Expand Down
34 changes: 11 additions & 23 deletions barretenberg/cpp/src/barretenberg/flavor/ultra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Ultra {
// assignment of witnesses. We again choose a neutral name.
static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 25;
// The total number of witness entities not including shifts.
static constexpr size_t NUM_WITNESS_ENTITIES = 11;
static constexpr size_t NUM_WITNESS_ENTITIES = 7;

using GrandProductRelations =
std::tuple<proof_system::UltraPermutationRelation<FF>, proof_system::LookupRelation<FF>>;
Expand Down Expand Up @@ -158,30 +158,13 @@ class Ultra {
DataType w_r; // column 1
DataType w_o; // column 2
DataType w_4; // column 3
DataType sorted_1; // column 4
DataType sorted_2; // column 5
DataType sorted_3; // column 6
DataType sorted_4; // column 7
DataType sorted_accum; // column 8
DataType z_perm; // column 9
DataType z_lookup; // column 10

DEFINE_POINTER_VIEW(NUM_WITNESS_ENTITIES,
&w_l,
&w_r,
&w_o,
&w_4,
&sorted_1,
&sorted_2,
&sorted_3,
&sorted_4,
&sorted_accum,
&z_perm,
&z_lookup)
DataType sorted_accum; // column 4
DataType z_perm; // column 5
DataType z_lookup; // column 6

DEFINE_POINTER_VIEW(NUM_WITNESS_ENTITIES, &w_l, &w_r, &w_o, &w_4, &sorted_accum, &z_perm, &z_lookup)

std::vector<HandleType> get_wires() override { return { w_l, w_r, w_o, w_4 }; };
// The sorted concatenations of table and witness data needed for plookup.
std::vector<HandleType> get_sorted_polynomials() { return { sorted_1, sorted_2, sorted_3, sorted_4 }; };
};

/**
Expand Down Expand Up @@ -392,6 +375,11 @@ class Ultra {
*/
using ExtendedEdges = ProverUnivariates<MAX_PARTIAL_RELATION_LENGTH>;

/**
* @brief A container for the witness commitments.
*/
using WitnessCommitments = WitnessEntities<Commitment, CommitmentHandle>;

/**
* @brief A container for commitment labels.
* @note It's debatable whether this should inherit from AllEntities. since most entries are not strictly needed. It
Expand Down
29 changes: 6 additions & 23 deletions barretenberg/cpp/src/barretenberg/flavor/ultra_recursive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ template <typename BuilderType> class UltraRecursive_ {
// assignment of witnesses. We again choose a neutral name.
static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 25;
// The total number of witness entities not including shifts.
static constexpr size_t NUM_WITNESS_ENTITIES = 11;
static constexpr size_t NUM_WITNESS_ENTITIES = 7;

// define the tuple of Relations that comprise the Sumcheck relation
using Relations = std::tuple<proof_system::UltraArithmeticRelation<FF>,
Expand Down Expand Up @@ -143,30 +143,13 @@ template <typename BuilderType> class UltraRecursive_ {
DataType w_r; // column 1
DataType w_o; // column 2
DataType w_4; // column 3
DataType sorted_1; // column 4
DataType sorted_2; // column 5
DataType sorted_3; // column 6
DataType sorted_4; // column 7
DataType sorted_accum; // column 8
DataType z_perm; // column 9
DataType z_lookup; // column 10

DEFINE_POINTER_VIEW(NUM_WITNESS_ENTITIES,
&w_l,
&w_r,
&w_o,
&w_4,
&sorted_1,
&sorted_2,
&sorted_3,
&sorted_4,
&sorted_accum,
&z_perm,
&z_lookup, )
DataType sorted_accum; // column 4
DataType z_perm; // column 5
DataType z_lookup; // column 6

DEFINE_POINTER_VIEW(NUM_WITNESS_ENTITIES, &w_l, &w_r, &w_o, &w_4, &sorted_accum, &z_perm, &z_lookup, )

std::vector<HandleType> get_wires() override { return { w_l, w_r, w_o, w_4 }; };
// The sorted concatenations of table and witness data needed for plookup.
std::vector<HandleType> get_sorted_polynomials() { return { sorted_1, sorted_2, sorted_3, sorted_4 }; };
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,20 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi
InnerComposer inner_composer;
auto instance = inner_composer.create_instance(inner_circuit);
auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK
const auto native_verification_key = instance->compute_verification_key();

// Instantiate the recursive verification key from the native verification key
OuterBuilder outer_circuit;
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, native_verification_key);
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, instance->verification_key);

// Spot check some values in the recursive VK to ensure it was constructed correctly
EXPECT_EQ(verification_key->circuit_size, native_verification_key->circuit_size);
EXPECT_EQ(verification_key->log_circuit_size, native_verification_key->log_circuit_size);
EXPECT_EQ(verification_key->num_public_inputs, native_verification_key->num_public_inputs);
EXPECT_EQ(verification_key->q_m.get_value(), native_verification_key->q_m);
EXPECT_EQ(verification_key->q_r.get_value(), native_verification_key->q_r);
EXPECT_EQ(verification_key->sigma_1.get_value(), native_verification_key->sigma_1);
EXPECT_EQ(verification_key->id_3.get_value(), native_verification_key->id_3);
EXPECT_EQ(verification_key->lagrange_ecc_op.get_value(), native_verification_key->lagrange_ecc_op);
EXPECT_EQ(verification_key->circuit_size, instance->verification_key->circuit_size);
EXPECT_EQ(verification_key->log_circuit_size, instance->verification_key->log_circuit_size);
EXPECT_EQ(verification_key->num_public_inputs, instance->verification_key->num_public_inputs);
EXPECT_EQ(verification_key->q_m.get_value(), instance->verification_key->q_m);
EXPECT_EQ(verification_key->q_r.get_value(), instance->verification_key->q_r);
EXPECT_EQ(verification_key->sigma_1.get_value(), instance->verification_key->sigma_1);
EXPECT_EQ(verification_key->id_3.get_value(), instance->verification_key->id_3);
EXPECT_EQ(verification_key->lagrange_ecc_op.get_value(), instance->verification_key->lagrange_ecc_op);
}

/**
Expand All @@ -166,11 +165,10 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi
auto instance = inner_composer.create_instance(inner_circuit);
auto inner_prover = inner_composer.create_prover(instance);
auto inner_proof = inner_prover.construct_proof();
const auto native_verification_key = instance->compute_verification_key();

// Create a recursive verification circuit for the proof of the inner circuit
OuterBuilder outer_circuit;
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, native_verification_key);
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, instance->verification_key);
RecursiveVerifier verifier(&outer_circuit, verification_key);
auto pairing_points = verifier.verify_proof(inner_proof);

Expand Down Expand Up @@ -213,7 +211,6 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi
auto instance = inner_composer.create_instance(inner_circuit);
auto inner_prover = inner_composer.create_prover(instance);
auto inner_proof = inner_prover.construct_proof();
const auto native_verification_key = instance->compute_verification_key();

// Arbitrarily tamper with the proof to be verified
inner_prover.transcript.deserialize_full_transcript();
Expand All @@ -223,7 +220,7 @@ template <typename BuilderType> class GoblinRecursiveVerifierTest : public testi

// Create a recursive verification circuit for the proof of the inner circuit
OuterBuilder outer_circuit;
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, native_verification_key);
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, instance->verification_key);
RecursiveVerifier verifier(&outer_circuit, verification_key);
verifier.verify_proof(inner_proof);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,18 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te
InnerComposer inner_composer;
auto instance = inner_composer.create_instance(inner_circuit);
auto prover = inner_composer.create_prover(instance); // A prerequisite for computing VK
const auto native_verification_key = instance->compute_verification_key();

// Instantiate the recursive verification key from the native verification key
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, native_verification_key);
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, instance->verification_key);

// Spot check some values in the recursive VK to ensure it was constructed correctly
EXPECT_EQ(verification_key->circuit_size, native_verification_key->circuit_size);
EXPECT_EQ(verification_key->log_circuit_size, native_verification_key->log_circuit_size);
EXPECT_EQ(verification_key->num_public_inputs, native_verification_key->num_public_inputs);
EXPECT_EQ(verification_key->q_m.get_value(), native_verification_key->q_m);
EXPECT_EQ(verification_key->q_r.get_value(), native_verification_key->q_r);
EXPECT_EQ(verification_key->sigma_1.get_value(), native_verification_key->sigma_1);
EXPECT_EQ(verification_key->id_3.get_value(), native_verification_key->id_3);
EXPECT_EQ(verification_key->circuit_size, instance->verification_key->circuit_size);
EXPECT_EQ(verification_key->log_circuit_size, instance->verification_key->log_circuit_size);
EXPECT_EQ(verification_key->num_public_inputs, instance->verification_key->num_public_inputs);
EXPECT_EQ(verification_key->q_m.get_value(), instance->verification_key->q_m);
EXPECT_EQ(verification_key->q_r.get_value(), instance->verification_key->q_r);
EXPECT_EQ(verification_key->sigma_1.get_value(), instance->verification_key->sigma_1);
EXPECT_EQ(verification_key->id_3.get_value(), instance->verification_key->id_3);
}

/**
Expand All @@ -150,11 +149,10 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te
auto instance = inner_composer.create_instance(inner_circuit);
auto inner_prover = inner_composer.create_prover(instance);
auto inner_proof = inner_prover.construct_proof();
const auto native_verification_key = instance->compute_verification_key();

// Create a recursive verification circuit for the proof of the inner circuit
OuterBuilder outer_circuit;
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, native_verification_key);
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, instance->verification_key);
RecursiveVerifier verifier(&outer_circuit, verification_key);
auto pairing_points = verifier.verify_proof(inner_proof);

Expand Down Expand Up @@ -198,7 +196,6 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te
auto instance = inner_composer.create_instance(inner_circuit);
auto inner_prover = inner_composer.create_prover(instance);
auto inner_proof = inner_prover.construct_proof();
const auto native_verification_key = instance->compute_verification_key();

// Arbitrarily tamper with the proof to be verified
inner_prover.transcript.deserialize_full_transcript();
Expand All @@ -208,7 +205,7 @@ template <typename BuilderType> class RecursiveVerifierTest : public testing::Te

// Create a recursive verification circuit for the proof of the inner circuit
OuterBuilder outer_circuit;
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, native_verification_key);
auto verification_key = std::make_shared<VerificationKey>(&outer_circuit, instance->verification_key);
RecursiveVerifier verifier(&outer_circuit, verification_key);
verifier.verify_proof(inner_proof);

Expand Down
Loading