Skip to content

Commit

Permalink
feat: translator recursive verifier (#6327)
Browse files Browse the repository at this point in the history
First iteration of the translator recursive verifier as a standalone
component, arithmetised with either vanilla Ultra, Goblin Ultra or
simulator. This required refactoring the translator relations so their
`field_t<Builder>` instantiation is only used in the recursive verifier.
For now, we work around the fact that the transcript should be shared
between eccvm and translator which limits a bit the amount of testing we
can do. These TODOs will be addressed after we have an ECCVM recursive
verifier.
  • Loading branch information
maramihali committed May 21, 2024
1 parent 83ba29f commit 9321aef
Show file tree
Hide file tree
Showing 59 changed files with 2,287 additions and 1,839 deletions.
2 changes: 1 addition & 1 deletion barretenberg/cpp/scripts/analyze_client_ivc_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"Decider::construct_proof(t)",
"ECCVMProver(CircuitBuilder&)(t)",
"ECCVMProver::construct_proof(t)",
"GoblinTranslatorProver::construct_proof(t)",
"TranslatorProver::construct_proof(t)",
"Goblin::merge(t)"
]
with open(PREFIX/IVC_BENCH_JSON, "r") as read_file:
Expand Down
2 changes: 2 additions & 0 deletions barretenberg/cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ add_subdirectory(barretenberg/stdlib_circuit_builders)
add_subdirectory(barretenberg/sumcheck)
add_subdirectory(barretenberg/transcript)
add_subdirectory(barretenberg/translator_vm)
add_subdirectory(barretenberg/translator_vm_recursion)
add_subdirectory(barretenberg/ultra_honk)
add_subdirectory(barretenberg/vm)
add_subdirectory(barretenberg/wasi)
Expand Down Expand Up @@ -146,6 +147,7 @@ set(BARRETENBERG_TARGET_OBJECTS
$<TARGET_OBJECTS:sumcheck_objects>
$<TARGET_OBJECTS:transcript_objects>
$<TARGET_OBJECTS:translator_vm_objects>
$<TARGET_OBJECTS:translator_vm_recursion_objects>
$<TARGET_OBJECTS:ultra_honk_objects>
$<TARGET_OBJECTS:vm_objects>)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ BENCHMARK_DEFINE_F(GoblinBench, GoblinECCVMProve)(benchmark::State& state)
* @brief Benchmark only the Translator component
*
*/
BENCHMARK_DEFINE_F(GoblinBench, GoblinTranslatorProve)(benchmark::State& state)
BENCHMARK_DEFINE_F(GoblinBench, TranslatorProve)(benchmark::State& state)
{
Goblin goblin;

Expand All @@ -136,7 +136,7 @@ BENCHMARK_DEFINE_F(GoblinBench, GoblinTranslatorProve)(benchmark::State& state)
BENCHMARK_REGISTER_F(GoblinBench, GoblinFull)->Unit(benchmark::kMillisecond)->ARGS;
BENCHMARK_REGISTER_F(GoblinBench, GoblinAccumulate)->Unit(benchmark::kMillisecond)->ARGS;
BENCHMARK_REGISTER_F(GoblinBench, GoblinECCVMProve)->Unit(benchmark::kMillisecond)->ARGS;
BENCHMARK_REGISTER_F(GoblinBench, GoblinTranslatorProve)->Unit(benchmark::kMillisecond)->ARGS;
BENCHMARK_REGISTER_F(GoblinBench, TranslatorProve)->Unit(benchmark::kMillisecond)->ARGS;

} // namespace

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "barretenberg/protogalaxy/protogalaxy_prover.hpp"
#include "barretenberg/stdlib_circuit_builders/goblin_ultra_flavor.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp"
#include "barretenberg/translator_vm/goblin_translator_flavor.hpp"
#include "barretenberg/translator_vm/translator_flavor.hpp"
#include <benchmark/benchmark.h>

namespace {
Expand Down Expand Up @@ -103,12 +103,12 @@ BENCHMARK(execute_relation_for_values<GoblinUltraFlavor, Poseidon2ExternalRelati
BENCHMARK(execute_relation_for_values<GoblinUltraFlavor, Poseidon2InternalRelation<Fr>>);

// Translator VM
BENCHMARK(execute_relation_for_values<GoblinTranslatorFlavor, GoblinTranslatorDecompositionRelation<Fr>>);
BENCHMARK(execute_relation_for_values<GoblinTranslatorFlavor, GoblinTranslatorOpcodeConstraintRelation<Fr>>);
BENCHMARK(execute_relation_for_values<GoblinTranslatorFlavor, GoblinTranslatorAccumulatorTransferRelation<Fr>>);
BENCHMARK(execute_relation_for_values<GoblinTranslatorFlavor, GoblinTranslatorDeltaRangeConstraintRelation<Fr>>);
BENCHMARK(execute_relation_for_values<GoblinTranslatorFlavor, GoblinTranslatorNonNativeFieldRelation<Fr>>);
BENCHMARK(execute_relation_for_values<GoblinTranslatorFlavor, GoblinTranslatorPermutationRelation<Fr>>);
BENCHMARK(execute_relation_for_values<TranslatorFlavor, TranslatorDecompositionRelation<Fr>>);
BENCHMARK(execute_relation_for_values<TranslatorFlavor, TranslatorOpcodeConstraintRelation<Fr>>);
BENCHMARK(execute_relation_for_values<TranslatorFlavor, TranslatorAccumulatorTransferRelation<Fr>>);
BENCHMARK(execute_relation_for_values<TranslatorFlavor, TranslatorDeltaRangeConstraintRelation<Fr>>);
BENCHMARK(execute_relation_for_values<TranslatorFlavor, TranslatorNonNativeFieldRelation<Fr>>);
BENCHMARK(execute_relation_for_values<TranslatorFlavor, TranslatorPermutationRelation<Fr>>);

// ECCVM
BENCHMARK(execute_relation_for_values<ECCVMFlavor, ECCVMLookupRelation<Fq>>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ template <typename PCS> class ZeroMorphProver_ {
*
* and concatenation_term = \sum_{i=0}^{num_chunks_per_group}(x^{i * min_N + 1}concatenation_groups_batched_{i})
*
* @note The concatenation term arises from an implementation detail in the Goblin Translator and is not part of the
* @note The concatenation term arises from an implementation detail in the Translator and is not part of the
* conventional ZM protocol
* @param input_polynomial
* @param quotients
Expand Down Expand Up @@ -250,7 +250,7 @@ template <typename PCS> class ZeroMorphProver_ {
// If necessary, add to Z_x the contribution related to concatenated polynomials:
// \sum_{i=0}^{num_chunks_per_group}(x^{i * min_n + 1}concatenation_groups_batched_{i}).
// We are effectively reconstructing concatenated polynomials from their chunks now that we know x
// Note: this is an implementation detail related to Goblin Translator and is not part of the standard protocol.
// Note: this is an implementation detail related to Translator and is not part of the standard protocol.
if (!concatenation_groups_batched.empty()) {
size_t MINICIRCUIT_N = N / concatenation_groups_batched.size();
auto x_to_minicircuit_N =
Expand Down Expand Up @@ -507,7 +507,7 @@ template <typename PCS> class ZeroMorphVerifier_ {
* concatenation_term = \sum{i=0}^{o-1}\sum_{j=0}^{num_chunks_per_group}(rho^{m+l+i} * x^{j * min_N + 1}
* * concatenation_groups_commitments_{i}_{j})
*
* @note The concatenation term arises from an implementation detail in the Goblin Translator and is not part of the
* @note The concatenation term arises from an implementation detail in the Translator and is not part of the
* conventional ZM protocol
* @param first_g1 first element in the SRS
* @param f_commitments Commitments to unshifted polynomials [f_i]
Expand Down Expand Up @@ -565,7 +565,7 @@ template <typename PCS> class ZeroMorphVerifier_ {
}

// If applicable, add contribution from concatenated polynomial commitments
// Note: this is an implementation detail related to Goblin Translator and is not part of the standard protocol.
// Note: this is an implementation detail related to Translator and is not part of the standard protocol.
if (!concatenation_groups_commitments.empty()) {
size_t CONCATENATION_GROUP_SIZE = concatenation_groups_commitments[0].size();
size_t MINICIRCUIT_N = N / CONCATENATION_GROUP_SIZE;
Expand Down
3 changes: 2 additions & 1 deletion barretenberg/cpp/src/barretenberg/eccvm/eccvm_flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class ECCVMFlavor {
using Curve = curve::Grumpkin;
using G1 = typename Curve::Group;
using PCS = IPA<Curve>;
using FF = typename G1::subgroup_field;
using FF = typename Curve::ScalarField;
using BF = typename Curve::BaseField;
using Polynomial = bb::Polynomial<FF>;
using GroupElement = typename G1::element;
using Commitment = typename G1::affine_element;
Expand Down
5 changes: 3 additions & 2 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ namespace bb {
// We won't compile this class with Standard, but we will like want to compile it (at least for testing)
// with a flavor that uses the curve Grumpkin, or a flavor that does/does not have zk, etc.
class ECCVMProver {
public:
using Flavor = ECCVMFlavor;
using FF = typename Flavor::FF;
using BF = typename Flavor::BF;
using PCS = typename Flavor::PCS;
using CommitmentKey = typename Flavor::CommitmentKey;
using ProvingKey = typename Flavor::ProvingKey;
using Polynomial = typename Flavor::Polynomial;
using CommitmentLabels = typename Flavor::CommitmentLabels;
using Transcript = typename Flavor::Transcript;
using TranslationEvaluations = bb::TranslationEvaluations;
using TranslationEvaluations = bb::TranslationEvaluations_<FF, BF>;
using ZeroMorph = ZeroMorphProver_<PCS>;
using CircuitBuilder = typename Flavor::CircuitBuilder;

public:
explicit ECCVMProver(CircuitBuilder& builder,
const std::shared_ptr<Transcript>& transcript = std::make_shared<Transcript>());

Expand Down
4 changes: 3 additions & 1 deletion barretenberg/cpp/src/barretenberg/flavor/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,10 @@ namespace bb {
class UltraFlavor;
class ECCVMFlavor;
class GoblinUltraFlavor;
class TranslatorFlavor;
template <typename BuilderType> class UltraRecursiveFlavor_;
template <typename BuilderType> class GoblinUltraRecursiveFlavor_;
template <typename BuilderType> class TranslatorRecursiveFlavor_;
} // namespace bb

// Forward declare plonk flavors
Expand Down Expand Up @@ -356,7 +358,7 @@ concept IsRecursiveFlavor = IsAnyOf<T, UltraRecursiveFlavor_<UltraCircuitBuilder
UltraRecursiveFlavor_<CircuitSimulatorBN254>,
GoblinUltraRecursiveFlavor_<UltraCircuitBuilder>,
GoblinUltraRecursiveFlavor_<GoblinUltraCircuitBuilder>
,GoblinUltraRecursiveFlavor_<CircuitSimulatorBN254>>;
,GoblinUltraRecursiveFlavor_<CircuitSimulatorBN254>, TranslatorRecursiveFlavor_<UltraCircuitBuilder>, TranslatorRecursiveFlavor_<GoblinUltraCircuitBuilder>, TranslatorRecursiveFlavor_<CircuitSimulatorBN254>>;


template <typename T> concept IsGrumpkinFlavor = IsAnyOf<T, ECCVMFlavor>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
RelationImpl<Flavor::FF>::MethodName<bb::Relation<RelationImpl<Flavor::FF>>::AccumulatorType, EdgeType(Flavor)>( \
EdgeType(Flavor) const&, RelationParameters<Flavor::FF> const&);

#define SUMCHECK_RELATION_CLASS(...) _SUMCHECK_RELATION_CLASS(__VA_ARGS__)
#define DEFINE_SUMCHECK_RELATION_CLASS(RelationImpl, Flavor) \
ACCUMULATE(RelationImpl, Flavor, SumcheckTupleOfUnivariatesOverSubrelations, ExtendedEdge) \
ACCUMULATE(RelationImpl, Flavor, SumcheckArrayOfValuesOverSubrelations, EvaluationEdge) \
ACCUMULATE(RelationImpl, Flavor, SumcheckArrayOfValuesOverSubrelations, EntityEdge)

#define SUMCHECK_PERMUTATION_CLASS(...) _SUMCHECK_PERMUTATION_CLASS(__VA_ARGS__)
#define DEFINE_SUMCHECK_VERIFIER_RELATION_CLASS(RelationImpl, Flavor) \
ACCUMULATE(RelationImpl, Flavor, SumcheckArrayOfValuesOverSubrelations, EvaluationEdge)

#define DEFINE_SUMCHECK_PERMUTATION_CLASS(RelationImpl, Flavor) \
PERMUTATION_METHOD(compute_grand_product_numerator, RelationImpl, Flavor, UnivariateAccumulator0, ExtendedEdge) \
PERMUTATION_METHOD(compute_grand_product_numerator, RelationImpl, Flavor, ValueAccumulator0, EvaluationEdge) \
Expand Down
17 changes: 9 additions & 8 deletions barretenberg/cpp/src/barretenberg/goblin/goblin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include "barretenberg/stdlib/honk_recursion/verifier/merge_recursive_verifier.hpp"
#include "barretenberg/stdlib_circuit_builders/goblin_ultra_circuit_builder.hpp"
#include "barretenberg/stdlib_circuit_builders/goblin_ultra_flavor.hpp"
#include "barretenberg/translator_vm/goblin_translator_circuit_builder.hpp"
#include "barretenberg/translator_vm/goblin_translator_prover.hpp"
#include "barretenberg/translator_vm/goblin_translator_verifier.hpp"
#include "barretenberg/translator_vm/translator_circuit_builder.hpp"
#include "barretenberg/translator_vm/translator_prover.hpp"
#include "barretenberg/translator_vm/translator_verifier.hpp"
#include "barretenberg/ultra_honk/merge_prover.hpp"
#include "barretenberg/ultra_honk/merge_verifier.hpp"
#include "barretenberg/ultra_honk/ultra_prover.hpp"
Expand All @@ -32,8 +32,9 @@ class Goblin {
using ECCVMFlavor = bb::ECCVMFlavor;
using ECCVMBuilder = bb::ECCVMCircuitBuilder;
using ECCVMProver = bb::ECCVMProver;
using TranslatorBuilder = bb::GoblinTranslatorCircuitBuilder;
using TranslatorProver = bb::GoblinTranslatorProver;
using TranslationEvaluations = ECCVMProver::TranslationEvaluations;
using TranslatorBuilder = bb::TranslatorCircuitBuilder;
using TranslatorProver = bb::TranslatorProver;
using RecursiveMergeVerifier = bb::stdlib::recursion::goblin::MergeRecursiveVerifier_<GoblinUltraCircuitBuilder>;
using MergeProver = bb::MergeProver_<GoblinUltraFlavor>;
using MergeVerifier = bb::MergeVerifier_<GoblinUltraFlavor>;
Expand Down Expand Up @@ -175,7 +176,7 @@ class Goblin {
{
translator_builder = std::make_unique<TranslatorBuilder>(
eccvm_prover->translation_batching_challenge_v, eccvm_prover->evaluation_challenge_x, op_queue);
translator_prover = std::make_unique<GoblinTranslatorProver>(*translator_builder, eccvm_prover->transcript);
translator_prover = std::make_unique<TranslatorProver>(*translator_builder, eccvm_prover->transcript);
goblin_proof.translator_proof = translator_prover->construct_proof();
};

Expand Down Expand Up @@ -209,7 +210,7 @@ class Goblin {
ECCVMVerifier eccvm_verifier(eccvm_prover->key);
bool eccvm_verified = eccvm_verifier.verify_proof(proof.eccvm_proof);

GoblinTranslatorVerifier translator_verifier(translator_prover->key, eccvm_verifier.transcript);
TranslatorVerifier translator_verifier(translator_prover->key, eccvm_verifier.transcript);

bool accumulator_construction_verified = translator_verifier.verify_proof(proof.translator_proof);
// TODO(https://github.com/AztecProtocol/barretenberg/issues/799): Ensure translation_evaluations are passed
Expand Down Expand Up @@ -296,7 +297,7 @@ class Goblin {
ECCVMVerifier eccvm_verifier(eccvm_prover->key);
bool eccvm_verified = eccvm_verifier.verify_proof(goblin_proof.eccvm_proof);

GoblinTranslatorVerifier translator_verifier(translator_prover->key, eccvm_verifier.transcript);
TranslatorVerifier translator_verifier(translator_prover->key, eccvm_verifier.transcript);

bool translation_accumulator_construction_verified =
translator_verifier.verify_proof(goblin_proof.translator_proof);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
#include "barretenberg/ecc/fields/field_conversion.hpp"

namespace bb {
struct TranslationEvaluations {
fq op, Px, Py, z1, z2;
/**
* @brief Stores the evaluations from ECCVM, checked against the translator evaluations as a final step of translator.
*
* @tparam BF The base field of the curve, translation evaluations are represented in the base field.
* @tparam FF The scalar field of the curve, used in Goblin to help convert the proof into a buffer for ACIR.
*/
template <typename BF, typename FF> struct TranslationEvaluations_ {
BF op, Px, Py, z1, z2;
static constexpr uint32_t NUM_EVALUATIONS = 5;
static size_t size() { return field_conversion::calc_num_bn254_frs<fq>() * NUM_EVALUATIONS; }
std::vector<fr> to_buffer() const
static size_t size() { return field_conversion::calc_num_bn254_frs<BF>() * NUM_EVALUATIONS; }
std::vector<FF> to_buffer() const
{
std::vector<fr> result;
std::vector<FF> result;
result.reserve(size());
const auto insert = [&result](const fq& elt) {
std::vector<fr> buf = field_conversion::convert_to_bn254_frs(elt);
const auto insert = [&result](const BF& elt) {
std::vector<FF> buf = field_conversion::convert_to_bn254_frs(elt);
result.insert(result.end(), buf.begin(), buf.end());
};
insert(op);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace bb {
* commitments. This method creates concatenated version of polynomials we won't need to commit to. Used in Goblin
* Translator
*
* Concatenation in Goblin Translator mean the action of constructing a new Polynomial from existing ones by writing
* Concatenation in Translator mean the action of constructing a new Polynomial from existing ones by writing
* their multilinear representations sequentially. For example, if we have f(x₁,x₂)={0, 1, 0, 1} and
* g(x₁,x₂)={1, 0, 0, 1} then h(x₁ ,x₂ ,x₃ )=concatenation(f(x₁,x₂),g(x₁,x₂))={0, 1, 0, 1, 1, 0, 0, 1}
*
Expand All @@ -37,7 +37,7 @@ template <typename Flavor> void compute_concatenated_polynomials(typename Flavor
ASSERT(MINI_CIRCUIT_SIZE * Flavor::CONCATENATION_GROUP_SIZE == targets[0].size());
// A function that produces 1 concatenated polynomial

// Goblin Translator uses concatenated polynomials in the permutation argument. These polynomials contain the same
// Translator uses concatenated polynomials in the permutation argument. These polynomials contain the same
// coefficients as other shorter polynomials, but we don't have to commit to them due to reusing commitments of
// shorter polynomials and updating our PCS to open using them. But the prover still needs the concatenated
// polynomials. This function constructs a chunk of the polynomial.
Expand All @@ -60,13 +60,13 @@ template <typename Flavor> void compute_concatenated_polynomials(typename Flavor
}

/**
* @brief Compute denominator polynomials for Goblin Translator's range constraint permutation
* @brief Compute denominator polynomials for Translator's range constraint permutation
*
* @details We need to prove that all the range constraint wires indeed have values within the given range (unless
* changed ∈ [0 , 2¹⁴ - 1]. To do this, we use several virtual concatenated wires, each of which represents a subset
* or original wires (concatenated_range_constraints_<i>). We also generate several new polynomials of the same length
* as concatenated ones. These polynomials have values within range, but they are also constrained by the
* GoblinTranslatorFlavor's DeltaRangeConstraint relation, which ensures that sequential values differ by not more than
* TranslatorFlavor's DeltaRangeConstraint relation, which ensures that sequential values differ by not more than
* 3, the last value is the maximum and the first value is zero (zero at the start allows us not to dance around
* shifts).
*
Expand All @@ -82,8 +82,8 @@ template <typename Flavor> void compute_concatenated_polynomials(typename Flavor
* @param proving_key
*/
template <typename Flavor>
void compute_goblin_translator_range_constraint_ordered_polynomials(typename Flavor::ProverPolynomials& polynomials,
size_t mini_circuit_dyadic_size)
void compute_translator_range_constraint_ordered_polynomials(typename Flavor::ProverPolynomials& polynomials,
size_t mini_circuit_dyadic_size)
{

using FF = typename Flavor::FF;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ template <typename FF_> class UltraHonkArith {
inline static const std::vector<std::string> selector_names = {};
};

class GoblinTranslatorArith {
class TranslatorArith {
public:
static constexpr size_t NUM_WIRES = 81;
static constexpr size_t NUM_SELECTORS = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ template <typename T> struct RelationParameters {
// eccvm_set_permutation_delta is used in the set membership gadget in eccvm/ecc_set_relation.hpp
// We can remove this by modifying the relation, but increases complexity
T eccvm_set_permutation_delta = T(0);
std::array<T, NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR> accumulated_result = {
T(0), T(0), T(0), T(0)
}; // Goblin Translator
std::array<T, NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR> accumulated_result = { T(0), T(0), T(0), T(0) }; // Translator
std::array<T, NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR + NUM_NATIVE_LIMBS_IN_GOBLIN_TRANSLATOR> evaluation_input_x = {
T(0), T(0), T(0), T(0), T(0)
}; // Goblin Translator
}; // Translator
std::array<std::array<T, NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR + NUM_NATIVE_LIMBS_IN_GOBLIN_TRANSLATOR>,
NUM_CHALLENGE_POWERS_IN_GOBLIN_TRANSLATOR>
batching_challenge_v = { { { T(0), T(0), T(0), T(0), T(0) },
Expand Down
Loading

0 comments on commit 9321aef

Please sign in to comment.