Skip to content

Commit

Permalink
chore: Refactor WitnessEntities to be able to derive `WitnessCommit…
Browse files Browse the repository at this point in the history
…ments` from it (#3479)

This PR removes the sorted polynomials from `WitnessEntities` and moves
them as part of the `ProverInstance` since they are not actual witness
polynomials that we _commit_ to, just used to compute the sorted
accumulator polynomial. This allows us to define a `WitnessCommitments`
structure from `WitnessEntities`. The Prover will be responsible for
computing the `Instance`'s` WitnessCommitments`. Moreover, the task of
computing the `VerificationKey` is moved to the `Composer`, as the
Instance should not have the `CommitmentKey`.
  • Loading branch information
maramihali committed Dec 1, 2023
1 parent d78775a commit 9c9b561
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 204 deletions.
33 changes: 16 additions & 17 deletions barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,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 @@ -139,28 +139,22 @@ class GoblinUltra {
w_r, // column 1
w_o, // column 2
w_4, // column 3
sorted_1, // column 4
sorted_2, // column 5
sorted_3, // column 6
sorted_4, // column 7
sorted_accum, // column 8
z_perm, // column 9
z_lookup, // column 10
ecc_op_wire_1, // column 11
ecc_op_wire_2, // column 12
ecc_op_wire_3, // column 13
ecc_op_wire_4, // column 14
calldata, // column 15
calldata_read_counts, // column 16
lookup_inverses // column 17
sorted_accum, // column 4
z_perm, // column 5
z_lookup, // column 6
ecc_op_wire_1, // column 7
ecc_op_wire_2, // column 8
ecc_op_wire_3, // column 9
ecc_op_wire_4, // column 10
calldata, // column 11
calldata_read_counts, // column 12
lookup_inverses // column 13
)
RefVector<DataType> get_wires() { return { w_l, w_r, w_o, w_4 }; };
RefVector<DataType> get_ecc_op_wires()
{
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.
RefVector<DataType> get_sorted_polynomials() { return { sorted_1, sorted_2, sorted_3, sorted_4 }; };
};

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

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

/**
* @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
28 changes: 11 additions & 17 deletions barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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 @@ -153,29 +153,23 @@ template <typename BuilderType> class GoblinUltraRecursive_ {
w_r, // column 1
w_o, // column 2
w_4, // column 3
sorted_1, // column 4
sorted_2, // column 5
sorted_3, // column 6
sorted_4, // column 7
sorted_accum, // column 8
z_perm, // column 9
z_lookup, // column 10
ecc_op_wire_1, // column 11
ecc_op_wire_2, // column 12
ecc_op_wire_3, // column 13
ecc_op_wire_4, // column 14
calldata, // column 15
calldata_read_counts, // column 16
lookup_inverses // column 17
sorted_accum, // column 4
z_perm, // column 5
z_lookup, // column 6
ecc_op_wire_1, // column 7
ecc_op_wire_2, // column 8
ecc_op_wire_3, // column 9
ecc_op_wire_4, // column 10
calldata, // column 11
calldata_read_counts, // column 12
lookup_inverses // column 13
)

RefVector<DataType> get_wires() { return { w_l, w_r, w_o, w_4 }; };
RefVector<DataType> get_ecc_op_wires()
{
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.
RefVector<DataType> get_sorted_polynomials() { return { sorted_1, sorted_2, sorted_3, sorted_4 }; };
};

/**
Expand Down
19 changes: 9 additions & 10 deletions barretenberg/cpp/src/barretenberg/flavor/ultra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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 @@ -133,17 +133,11 @@ class Ultra {
w_r, // column 1
w_o, // column 2
w_4, // column 3
sorted_1, // column 4
sorted_2, // column 5
sorted_3, // column 6
sorted_4, // column 7
sorted_accum, // column 8
z_perm, // column 9
z_lookup) // column 10
sorted_accum, // column 4
z_perm, // column 5
z_lookup) // column 6

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

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

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

/**
* @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
14 changes: 4 additions & 10 deletions barretenberg/cpp/src/barretenberg/flavor/ultra_recursive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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 @@ -145,19 +145,13 @@ template <typename BuilderType> class UltraRecursive_ {
w_r, // column 1
w_o, // column 2
w_4, // column 3
sorted_1, // column 4
sorted_2, // column 5
sorted_3, // column 6
sorted_4, // column 7
sorted_accum, // column 8
z_perm, // column 9
z_lookup // column 10
sorted_accum, // column 4
z_perm, // column 5
z_lookup // column 6

);

RefVector<DataType> get_wires() { return { w_l, w_r, w_o, w_4 }; };
// The sorted concatenations of table and witness data needed for plookup.
RefVector<DataType> 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

0 comments on commit 9c9b561

Please sign in to comment.