Skip to content

Commit

Permalink
refactor: protogalaxy relations (#1897)
Browse files Browse the repository at this point in the history
Will resolve AztecProtocol/barretenberg#682
and AztecProtocol/barretenberg#685

- Add optimization to `extend` functions in `BarycentricData`.
- Move barycentric evaluation, univariate, and relations classes for
organizations and more efficient iteration.
- Simplify relations classes.
- Simplify relation consistency tests.

Cf also my comments below.

# Checklist:
Remove the checklist to signal you've completed it. Enable auto-merge if
the PR is ready to merge.
- [x] If the pull request requires a cryptography review (e.g.
cryptographic algorithm implementations) I have added the 'crypto' tag.
- [x] I have reviewed my diff in github, line by line and removed
unexpected formatting changes, testing logs, or commented-out code.
- [x] Every change is related to the PR description.
- [x] I have
[linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue)
this pull request to relevant issues (if any exist).
  • Loading branch information
codygunton authored Sep 7, 2023
1 parent bc5d9f4 commit 35407e2
Show file tree
Hide file tree
Showing 58 changed files with 1,351 additions and 1,545 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_subdirectory(decrypt_bench)
add_subdirectory(pippenger_bench)
add_subdirectory(plonk_bench)
add_subdirectory(honk_bench)
add_subdirectory(honk_bench)
add_subdirectory(relations_bench)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

# This script is used to compare the honk benchmarks between baseline (default: master) and
# This script is used to compare a suite of benchmarks between baseline (default: master) and
# the branch from which the script is run. Simply check out the branch of interest, ensure
# it is up to date with local master, and run the script.

# Specify the benchmark suite and the "baseline" branch against which to compare
BENCH_TARGET="ultra_honk_bench"
BENCH_TARGET=${1:?"Please provide the name of a benchmark target."}
BASELINE_BRANCH="master"

echo -e "\nComparing $BENCH_TARGET between $BASELINE_BRANCH and current branch:"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Each source represents a separate benchmark suite
set(BENCHMARK_SOURCES
barycentric.bench.cpp
relations.bench.cpp
)

# Required libraries for benchmark suites
set(LINKED_LIBRARIES
polynomials
benchmark::benchmark
)

# Add executable and custom target for each suite, e.g. standard_honk_bench
foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES})
get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension
add_executable(${BENCHMARK_NAME}_bench main.bench.cpp ${BENCHMARK_SOURCE})
target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES})
add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
endforeach()
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "barretenberg/ecc/curves/bn254/fr.hpp"
#include "barretenberg/polynomials/barycentric.hpp"
#include <benchmark/benchmark.h>

using namespace benchmark;

namespace {
auto& engine = numeric::random::get_debug_engine();
}

using FF = barretenberg::fr;
using barretenberg::Univariate;
using barretenberg::BarycentricData;


namespace proof_system::benchmark {

void extend_2_to_6(State& state) noexcept
{
auto univariate = Univariate<FF, 2>::get_random();
BarycentricData<FF, 2, 6> barycentric_2_to_6;
for (auto _ : state)
{
DoNotOptimize(barycentric_2_to_6.extend(univariate));
}
}
BENCHMARK(extend_2_to_6);

} // namespace proof_system::benchmark
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include <benchmark/benchmark.h>

BENCHMARK_MAIN();
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include "barretenberg/honk/flavor/goblin_ultra.hpp"
#include "barretenberg/honk/flavor/standard.hpp"
#include "barretenberg/honk/flavor/ultra.hpp"
#include "barretenberg/proof_system/relations/arithmetic_relation.hpp"
#include "barretenberg/proof_system/relations/auxiliary_relation.hpp"
#include "barretenberg/proof_system/relations/ecc_op_queue_relation.hpp"
#include "barretenberg/proof_system/relations/elliptic_relation.hpp"
#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp"
#include "barretenberg/proof_system/relations/lookup_relation.hpp"
#include "barretenberg/proof_system/relations/permutation_relation.hpp"
#include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp"
#include <benchmark/benchmark.h>

namespace {
auto& engine = numeric::random::get_debug_engine();
}

namespace proof_system::benchmark::relations {

using FF = barretenberg::fr;

template <typename Flavor, typename Relation> void execute_relation(::benchmark::State& state)
{
// Generate beta and gamma
auto beta = FF::random_element();
auto gamma = FF::random_element();
auto public_input_delta = FF::random_element();

RelationParameters<FF> params{
.beta = beta,
.gamma = gamma,
.public_input_delta = public_input_delta,
};

using ClaimedEvaluations = typename Flavor::ClaimedEvaluations;
using RelationValues = typename Relation::RelationValues;

// Extract an array containing all the polynomial evaluations at a given row i
ClaimedEvaluations new_value;
// Define the appropriate RelationValues type for this relation and initialize to zero
RelationValues accumulator;
// Evaluate each constraint in the relation and check that each is satisfied

Relation relation;
for (auto _ : state) {
relation.add_full_relation_value_contribution(accumulator, new_value, params);
}
}

void arithmetic_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::Standard, ArithmeticRelation<FF>>(state);
}
BENCHMARK(arithmetic_relation);

void auxiliary_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::Ultra, AuxiliaryRelation<FF>>(state);
}
BENCHMARK(auxiliary_relation);

void elliptic_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::Ultra, EllipticRelation<FF>>(state);
}
BENCHMARK(elliptic_relation);

void ecc_op_queue_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::GoblinUltra, EccOpQueueRelation<FF>>(state);
}
BENCHMARK(ecc_op_queue_relation);

void gen_perm_sort_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::Ultra, GenPermSortRelation<FF>>(state);
}
BENCHMARK(gen_perm_sort_relation);

void lookup_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::Ultra, LookupRelation<FF>>(state);
}
BENCHMARK(lookup_relation);

void permutation_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::Standard, PermutationRelation<FF>>(state);
}
BENCHMARK(permutation_relation);

void ultra_arithmetic_relation(::benchmark::State& state) noexcept
{
execute_relation<honk::flavor::Ultra, UltraArithmeticRelation<FF>>(state);
}
BENCHMARK(ultra_arithmetic_relation);

} // namespace proof_system::benchmark::relations
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ template <StandardFlavor Flavor> class StandardComposer_ {
std::shared_ptr<VerificationKey> verification_key;

// The crs_factory holds the path to the srs and exposes methods to extract the srs elements
std::shared_ptr<srs::factories::CrsFactory<typename Flavor::Curve>> crs_factory_;
std::shared_ptr<barretenberg::srs::factories::CrsFactory<typename Flavor::Curve>> crs_factory_;

// The commitment key is passed to the prover but also used herein to compute the verfication key commitments
std::shared_ptr<CommitmentKey> commitment_key;
Expand All @@ -47,11 +47,11 @@ template <StandardFlavor Flavor> class StandardComposer_ {
}
}

StandardComposer_(std::shared_ptr<srs::factories::CrsFactory<typename Flavor::Curve>> crs_factory)
StandardComposer_(std::shared_ptr<barretenberg::srs::factories::CrsFactory<typename Flavor::Curve>> crs_factory)
: crs_factory_(std::move(crs_factory))
{}

StandardComposer_(std::unique_ptr<srs::factories::CrsFactory<typename Flavor::Curve>>&& crs_factory)
StandardComposer_(std::unique_ptr<barretenberg::srs::factories::CrsFactory<typename Flavor::Curve>>&& crs_factory)
: crs_factory_(std::move(crs_factory))
{}
StandardComposer_(std::shared_ptr<ProvingKey> p_key, std::shared_ptr<VerificationKey> v_key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#include "barretenberg/honk/composer/standard_composer.hpp"
#include "barretenberg/honk/proof_system/prover.hpp"
#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp"
#include "barretenberg/proof_system/relations/permutation_relation.hpp"
#include "barretenberg/proof_system/relations/relation_parameters.hpp"
#include "barretenberg/honk/sumcheck/sumcheck_round.hpp"
#include "barretenberg/honk/utils/grand_product_delta.hpp"
#include "barretenberg/numeric/uint256/uint256.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "barretenberg/honk/composer/ultra_composer.hpp"
#include "barretenberg/honk/proof_system/prover.hpp"
#include "barretenberg/honk/proof_system/ultra_prover.hpp"
#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp"
#include "barretenberg/proof_system/relations/permutation_relation.hpp"
#include "barretenberg/proof_system/relations/relation_parameters.hpp"
#include "barretenberg/honk/sumcheck/sumcheck_round.hpp"
#include "barretenberg/honk/utils/grand_product_delta.hpp"
#include "barretenberg/numeric/uint256/uint256.hpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
#pragma once
#include "barretenberg/ecc/curves/bn254/g1.hpp"
#include "barretenberg/honk/pcs/kzg/kzg.hpp"
#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp"
#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp"
#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/ecc_op_queue_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/lookup_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp"
#include "barretenberg/proof_system/relations/auxiliary_relation.hpp"
#include "barretenberg/proof_system/relations/ecc_op_queue_relation.hpp"
#include "barretenberg/proof_system/relations/elliptic_relation.hpp"
#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp"
#include "barretenberg/proof_system/relations/lookup_relation.hpp"
#include "barretenberg/proof_system/relations/permutation_relation.hpp"
#include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp"
#include "barretenberg/honk/transcript/transcript.hpp"
#include "barretenberg/polynomials/evaluation_domain.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
#include "barretenberg/polynomials/univariate.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/proof_system/flavor/flavor.hpp"
#include "barretenberg/srs/factories/crs_factory.hpp"
#include <array>
#include <concepts>
#include <span>
#include <string>
#include <type_traits>
#include <vector>

namespace proof_system::honk::flavor {

Expand Down Expand Up @@ -50,16 +39,17 @@ class GoblinUltra {
// The total number of witness entities not including shifts.
static constexpr size_t NUM_WITNESS_ENTITIES = 15; // 11 (UH) + 4 op wires

using GrandProductRelations = std::tuple<sumcheck::UltraPermutationRelation<FF>, sumcheck::LookupRelation<FF>>;
using GrandProductRelations =
std::tuple<proof_system::UltraPermutationRelation<FF>, proof_system::LookupRelation<FF>>;

// define the tuple of Relations that comprise the Sumcheck relation
using Relations = std::tuple<sumcheck::UltraArithmeticRelation<FF>,
sumcheck::UltraPermutationRelation<FF>,
sumcheck::LookupRelation<FF>,
sumcheck::GenPermSortRelation<FF>,
sumcheck::EllipticRelation<FF>,
sumcheck::AuxiliaryRelation<FF>,
sumcheck::EccOpQueueRelation<FF>>;
using Relations = std::tuple<proof_system::UltraArithmeticRelation<FF>,
proof_system::UltraPermutationRelation<FF>,
proof_system::LookupRelation<FF>,
proof_system::GenPermSortRelation<FF>,
proof_system::EllipticRelation<FF>,
proof_system::AuxiliaryRelation<FF>,
proof_system::EccOpQueueRelation<FF>>;

static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length<Relations>();

Expand Down Expand Up @@ -338,8 +328,8 @@ class GoblinUltra {
* @todo TODO(#390): Simplify this by moving MAX_RELATION_LENGTH?
*/
template <size_t MAX_RELATION_LENGTH>
using ExtendedEdges =
AllEntities<sumcheck::Univariate<FF, MAX_RELATION_LENGTH>, sumcheck::Univariate<FF, MAX_RELATION_LENGTH>>;
using ExtendedEdges = AllEntities<barretenberg::Univariate<FF, MAX_RELATION_LENGTH>,
barretenberg::Univariate<FF, MAX_RELATION_LENGTH>>;

/**
* @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
#pragma once
#include "barretenberg/ecc/curves/bn254/g1.hpp"
#include "barretenberg/honk/pcs/kzg/kzg.hpp"
#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp"
#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp"
#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp"
#include "barretenberg/proof_system/relations/arithmetic_relation.hpp"
#include "barretenberg/proof_system/relations/permutation_relation.hpp"
#include "barretenberg/honk/transcript/transcript.hpp"
#include "barretenberg/polynomials/barycentric.hpp"
#include "barretenberg/polynomials/evaluation_domain.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
#include "barretenberg/polynomials/univariate.hpp"
#include "barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp"
#include "barretenberg/proof_system/flavor/flavor.hpp"
#include "barretenberg/srs/factories/crs_factory.hpp"
#include <array>
#include <concepts>
#include <span>
#include <string>
#include <type_traits>
#include <vector>

namespace proof_system::honk::flavor {

Expand Down Expand Up @@ -52,9 +46,9 @@ class Standard {
// The total number of witness entities not including shifts.
static constexpr size_t NUM_WITNESS_ENTITIES = 4;

using GrandProductRelations = std::tuple<sumcheck::PermutationRelation<FF>>;
using GrandProductRelations = std::tuple<proof_system::PermutationRelation<FF>>;
// define the tuple of Relations that comprise the Sumcheck relation
using Relations = std::tuple<sumcheck::ArithmeticRelation<FF>, sumcheck::PermutationRelation<FF>>;
using Relations = std::tuple<proof_system::ArithmeticRelation<FF>, proof_system::PermutationRelation<FF>>;

static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length<Relations>();

Expand Down Expand Up @@ -234,8 +228,8 @@ class Standard {
* @todo TODO(#390): Simplify this by moving MAX_RELATION_LENGTH?
*/
template <size_t MAX_RELATION_LENGTH>
using ExtendedEdges =
AllEntities<sumcheck::Univariate<FF, MAX_RELATION_LENGTH>, sumcheck::Univariate<FF, MAX_RELATION_LENGTH>>;
using ExtendedEdges = AllEntities<barretenberg::Univariate<FF, MAX_RELATION_LENGTH>,
barretenberg::Univariate<FF, MAX_RELATION_LENGTH>>;

/**
* @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#pragma once
#include "barretenberg/ecc/curves/bn254/g1.hpp"
#include "barretenberg/honk/pcs/ipa/ipa.hpp"
#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp"
#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp"
#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/permutation_relation.hpp"
#include "barretenberg/polynomials/barycentric.hpp"
#include "barretenberg/polynomials/univariate.hpp"

#include "barretenberg/proof_system/relations/arithmetic_relation.hpp"
#include "barretenberg/proof_system/relations/permutation_relation.hpp"
#include "barretenberg/honk/transcript/transcript.hpp"
#include "barretenberg/polynomials/evaluation_domain.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
Expand Down Expand Up @@ -45,9 +46,9 @@ class StandardGrumpkin {
static constexpr size_t NUM_WITNESS_ENTITIES = 4;

// define the tuple of Relations that require grand products
using GrandProductRelations = std::tuple<sumcheck::PermutationRelation<FF>>;
using GrandProductRelations = std::tuple<proof_system::PermutationRelation<FF>>;
// define the tuple of Relations that comprise the Sumcheck relation
using Relations = std::tuple<sumcheck::ArithmeticRelation<FF>, sumcheck::PermutationRelation<FF>>;
using Relations = std::tuple<proof_system::ArithmeticRelation<FF>, proof_system::PermutationRelation<FF>>;

static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length<Relations>();

Expand Down Expand Up @@ -226,7 +227,7 @@ class StandardGrumpkin {
*/
template <size_t MAX_RELATION_LENGTH>
using ExtendedEdges =
AllEntities<sumcheck::Univariate<FF, MAX_RELATION_LENGTH>, sumcheck::Univariate<FF, MAX_RELATION_LENGTH>>;
AllEntities<barretenberg::Univariate<FF, MAX_RELATION_LENGTH>, barretenberg::Univariate<FF, MAX_RELATION_LENGTH>>;

/**
* @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the
Expand Down
Loading

0 comments on commit 35407e2

Please sign in to comment.