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: Execution Trace #4623

Merged
merged 71 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
f0310c2
Initial pass at ETM; construct blocks from builder
ledwards2225 Feb 9, 2024
c40162e
WiP method to test new pkey vs old one
ledwards2225 Feb 10, 2024
82790dc
basic pkey polynomials agree
ledwards2225 Feb 11, 2024
31b911c
simplify wire and sel poly construction
ledwards2225 Feb 12, 2024
c982200
perm polys agree
ledwards2225 Feb 12, 2024
86c8901
pkey using ETM in instance constructor is consistent w original
ledwards2225 Feb 12, 2024
2fd68c8
all polys agree for GU flavor
ledwards2225 Feb 12, 2024
3d3702c
todo comments
ledwards2225 Feb 13, 2024
8bcea37
cleanup plonk circuit size stuff
ledwards2225 Feb 13, 2024
1953ce9
simplify plonk circuit size and share sorted list
ledwards2225 Feb 13, 2024
efc4480
share table poly construction
ledwards2225 Feb 13, 2024
1445daa
move more stuff to methods in plonk
ledwards2225 Feb 13, 2024
285340e
initial structure of new plonk create prover
ledwards2225 Feb 13, 2024
cc525fc
try to fix build errors
ledwards2225 Feb 13, 2024
c806c32
another fix
ledwards2225 Feb 13, 2024
7947f08
woops
ledwards2225 Feb 13, 2024
9855ae4
wtf
ledwards2225 Feb 13, 2024
a4aa824
simplify
ledwards2225 Feb 13, 2024
066eca6
fix lookups size bug, with todo
ledwards2225 Feb 14, 2024
0e6320e
looks good with honk specific trace generate
ledwards2225 Feb 14, 2024
9653d02
Merge branch 'master' into lde/etm_poc
ledwards2225 Feb 14, 2024
c0e15fe
new compute prover method works for plonk, no etm yet
ledwards2225 Feb 14, 2024
7408b26
execution trace works for plonk
ledwards2225 Feb 14, 2024
849336d
Merge branch 'master' into lde/etm_poc
ledwards2225 Feb 14, 2024
be5251d
clean up permutation mapping
ledwards2225 Feb 15, 2024
045270c
Merge branch 'master' into lde/etm_poc
ledwards2225 Feb 15, 2024
8e1b322
test utilize trace everywhere
ledwards2225 Feb 15, 2024
10c0527
simplify unique ptr construction
ledwards2225 Feb 15, 2024
dba3961
exec trace for standard honk
ledwards2225 Feb 15, 2024
54e32fc
Merge branch 'master' into lde/exec_trace
ledwards2225 Feb 15, 2024
e011629
delete old lib methods
ledwards2225 Feb 15, 2024
a46bce8
more dead code deletion
ledwards2225 Feb 15, 2024
0546b61
cleanup
ledwards2225 Feb 15, 2024
86c6f2d
cleanup and go back to changing lookup_gates instead of copy
ledwards2225 Feb 15, 2024
2a86ccf
simplify plonk permuation stuff
ledwards2225 Feb 15, 2024
a2c5a87
fix build
ledwards2225 Feb 15, 2024
e8918dc
yay fix zero_idx bug
ledwards2225 Feb 16, 2024
c5a9b1b
its only tests of locations of data in the proof thats failing..
ledwards2225 Feb 16, 2024
b9284c5
disable js test to see that sweet green
ledwards2225 Feb 16, 2024
b1c15ac
class is static
ledwards2225 Feb 16, 2024
436fba2
split exec trace into hpp/cpp
ledwards2225 Feb 16, 2024
a901ce0
Merge branch 'master' into lde/exec_trace
ledwards2225 Feb 16, 2024
999f3fb
one linking option but circular dep
ledwards2225 Feb 16, 2024
3e5fa8e
typename
ledwards2225 Feb 16, 2024
1188ace
share mem read write population method
ledwards2225 Feb 17, 2024
ca4ebbc
reinstate joinsplit tests
ledwards2225 Feb 18, 2024
ee6378a
how about this
ledwards2225 Feb 18, 2024
e31ea7a
remove some special cases
ledwards2225 Feb 18, 2024
c9b21a1
neutral change breaks plonk acir
ledwards2225 Feb 18, 2024
df6b023
clean up prover instance constructor
ledwards2225 Feb 18, 2024
2ba6853
cleanup
ledwards2225 Feb 18, 2024
1b82b35
Merge branch 'master' into lde/exec_trace
ledwards2225 Feb 18, 2024
df1032b
template and resuse plonk prover construction
ledwards2225 Feb 19, 2024
9a46c19
cleanup and comments
ledwards2225 Feb 19, 2024
a87cfda
move pkey construction out of exec trace to simplify dependency
ledwards2225 Feb 19, 2024
d565070
add TODO with old issue
ledwards2225 Feb 19, 2024
edb6230
update some comments and TODOs
ledwards2225 Feb 19, 2024
6777369
constify some stuff
ledwards2225 Feb 19, 2024
5c32774
comments, cleanup and naming
ledwards2225 Feb 19, 2024
2a2a52a
make proper goblin block and simplify trace block construction
ledwards2225 Feb 19, 2024
8580f20
fix pub input flag
ledwards2225 Feb 19, 2024
b846966
clean up arithmetization
ledwards2225 Feb 19, 2024
4e391d6
use block for goblin gates
ledwards2225 Feb 19, 2024
f6fc114
Merge branch 'master' into lde/exec_trace
ledwards2225 Feb 20, 2024
93c8e8e
dont need to pass dyadic size independently
ledwards2225 Feb 20, 2024
5ee1619
Merge branch 'master' into lde/exec_trace
ledwards2225 Feb 20, 2024
7c22c87
add todo with ref to next issue
ledwards2225 Feb 20, 2024
a98ee4e
Merge branch 'master' into lde/exec_trace
ledwards2225 Feb 21, 2024
55439e9
Notes
ledwards2225 Feb 21, 2024
72c33b0
issue to move some stuff inside trace generation
ledwards2225 Feb 21, 2024
c45bf42
more gcc workarounds
ludamad0 Feb 21, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,6 @@ plonk::Prover provers[NUM_CIRCUITS];
plonk::Verifier verifiers[NUM_CIRCUITS];
plonk::proof proofs[NUM_CIRCUITS];

void construct_witnesses_bench(State& state) noexcept
ledwards2225 marked this conversation as resolved.
Show resolved Hide resolved
{
for (auto _ : state) {
state.PauseTiming();
auto builder = Builder(static_cast<size_t>(state.range(0)));
generate_test_plonk_circuit(builder, static_cast<size_t>(state.range(0)));
auto composer = Composer();
composer.compute_proving_key(builder);
state.ResumeTiming();

composer.compute_witness(builder);
}
}
BENCHMARK(construct_witnesses_bench)->RangeMultiplier(2)->Range(START, MAX_GATES);

void construct_proving_keys_bench(State& state) noexcept
{
for (auto _ : state) {
Expand Down
4 changes: 4 additions & 0 deletions barretenberg/cpp/src/barretenberg/flavor/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class ProvingKey_ : public PrecomputedPolynomials, public WitnessPolynomials {
RefVector<Polynomial> get_all() { return concatenate(get_precomputed_polynomials(), get_witness_polynomials()); }
RefVector<Polynomial> get_witness_polynomials() { return WitnessPolynomials::get_all(); }
RefVector<Polynomial> get_precomputed_polynomials() { return PrecomputedPolynomials::get_all(); }
RefVector<Polynomial> get_selectors() { return PrecomputedPolynomials::get_selectors(); }
ProvingKey_() = default;
ProvingKey_(const size_t circuit_size, const size_t num_public_inputs)
{
Expand Down Expand Up @@ -285,6 +286,9 @@ namespace bb {
template <typename T>
concept IsPlonkFlavor = IsAnyOf<T, plonk::flavor::Standard, plonk::flavor::Ultra>;

template <typename T>
concept IsUltraPlonkFlavor = IsAnyOf<T, plonk::flavor::Ultra>;

template <typename T>
concept IsHonkFlavor = IsAnyOf<T, UltraFlavor, GoblinUltraFlavor>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Prover new_join_split_prover(join_split_tx const& tx, bool mock)

info("public inputs: ", builder.public_inputs.size());

Composer composer(proving_key, nullptr);
Composer composer;
if (!mock) {
info("composer gates: ", builder.get_num_gates());
return composer.create_prover(builder);
Expand Down
33 changes: 0 additions & 33 deletions barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,6 @@ struct SelectorProperties {
bool requires_lagrange_base_polynomial = false;
};

/**
* @brief Initilalize proving key and load the crs
*
* @param circuit_constructor Object containing the circuit
* @param crs_factory Produces the prover's reference string
* @param minimum_circuit_size The minimum size of polynomials without randomized elements
* @param num_randomized_gates Number of gates with randomized witnesses
* @param circuit_type This is passed in the case of Plonk since we use flavor-independent proving and verification keys
* in that case.
* @return std::shared_ptr<typename Flavor::ProvingKey>
*/
std::shared_ptr<plonk::proving_key> initialize_proving_key(const auto& circuit_constructor,
bb::srs::factories::CrsFactory<curve::BN254>* crs_factory,
const size_t minimum_circuit_size,
const size_t num_randomized_gates,
CircuitType circuit_type)
{
const size_t num_gates = circuit_constructor.num_gates;

const size_t num_public_inputs = circuit_constructor.public_inputs.size();
const size_t num_constraints = num_gates + num_public_inputs;
const size_t total_num_constraints = std::max(minimum_circuit_size, num_constraints);
const size_t subgroup_size =
circuit_constructor.get_circuit_subgroup_size(total_num_constraints + num_randomized_gates); // next power of 2

auto crs = crs_factory->get_prover_crs(subgroup_size + 1);

// Differentiate between Honk and Plonk here since Plonk pkey requires crs whereas Honk pkey does not
auto proving_key = std::make_shared<plonk::proving_key>(subgroup_size, num_public_inputs, crs, circuit_type);

return proving_key;
}

/**
* @brief Fill the last index of each selector polynomial in lagrange form with a non-zero value
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,6 @@

namespace bb::plonk {

/**
* Compute witness polynomials (w_1, w_2, w_3, w_4).
*
* @details Fills 3 or 4 witness polynomials w_1, w_2, w_3, w_4 with the values of in-circuit variables. The beginning
* of w_1, w_2 polynomials is filled with public_input values.
* @return Witness with computed witness polynomials.
*
* @tparam Program settings needed to establish if w_4 is being used.
* */
void StandardComposer::compute_witness(const CircuitBuilder& circuit_constructor, const size_t minimum_circuit_size)
{

if (computed_witness) {
return;
}
const size_t num_gates = circuit_constructor.num_gates;
const size_t num_public_inputs = circuit_constructor.public_inputs.size();

const size_t num_constraints = std::max(minimum_circuit_size, num_gates + num_public_inputs);

const size_t subgroup_size = circuit_constructor.get_circuit_subgroup_size(num_constraints + NUM_RESERVED_GATES);

auto wire_polynomial_evaluations =
construct_wire_polynomials_base<StandardComposer::Flavor>(circuit_constructor, subgroup_size);

for (size_t j = 0; j < program_width; ++j) {
std::string index = std::to_string(j + 1);
circuit_proving_key->polynomial_store.put("w_" + index + "_lagrange",
std::move(wire_polynomial_evaluations[j]));
}
computed_witness = true;
}

/**
* Compute proving key
*
Expand All @@ -63,27 +30,30 @@ std::shared_ptr<plonk::proving_key> StandardComposer::compute_proving_key(const
if (circuit_proving_key) {
return circuit_proving_key;
}
const size_t minimum_circuit_size = 0;
const size_t num_randomized_gates = NUM_RESERVED_GATES;
// Initialize circuit_proving_key
// TODO(#392)(Kesha): replace composer types.
circuit_proving_key = initialize_proving_key(
circuit_constructor, crs_factory_.get(), minimum_circuit_size, num_randomized_gates, CircuitType::STANDARD);
// Compute lagrange selectors
construct_selector_polynomials<Flavor>(circuit_constructor, circuit_proving_key.get());

const size_t total_num_gates =
circuit_constructor.num_gates + circuit_constructor.public_inputs.size() + NUM_RESERVED_GATES;
const size_t subgroup_size = circuit_constructor.get_circuit_subgroup_size(total_num_gates); // next power of 2

auto crs = srs::get_crs_factory()->get_prover_crs(subgroup_size + 1);
// TODO(https://github.com/AztecProtocol/barretenberg/issues/392): Composer type
circuit_proving_key = std::make_shared<plonk::proving_key>(
subgroup_size, circuit_constructor.public_inputs.size(), crs, CircuitType::STANDARD);

// Construct and add to proving key the wire, selector and copy constraint polynomials
Trace::generate(circuit_constructor, circuit_proving_key);

// Make all selectors nonzero
enforce_nonzero_selector_polynomials(circuit_constructor, circuit_proving_key.get());
// Compute selectors in monomial form
compute_monomial_and_coset_selector_forms(circuit_proving_key.get(), standard_selector_properties());

// Compute sigma polynomials (we should update that late)
compute_standard_plonk_sigma_permutations<Flavor>(circuit_constructor, circuit_proving_key.get());

circuit_proving_key->recursive_proof_public_input_indices =
std::vector<uint32_t>(circuit_constructor.recursive_proof_public_input_indices.begin(),
circuit_constructor.recursive_proof_public_input_indices.end());
// What does this line do exactly?

circuit_proving_key->contains_recursive_proof = circuit_constructor.contains_recursive_proof;

return circuit_proving_key;
}

Expand Down Expand Up @@ -144,12 +114,8 @@ plonk::Verifier StandardComposer::create_verifier(const CircuitBuilder& circuit_
* */
plonk::Prover StandardComposer::create_prover(const CircuitBuilder& circuit_constructor)
{
// Compute q_l, etc. and sigma polynomials.
compute_proving_key(circuit_constructor);

// Compute witness polynomials.
compute_witness(circuit_constructor);

plonk::Prover output_state(circuit_proving_key, create_manifest(circuit_constructor.public_inputs.size()));

std::unique_ptr<plonk::ProverPermutationWidget<3, false>> permutation_widget =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp"
#include "barretenberg/plonk/proof_system/verifier/verifier.hpp"
#include "barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp"
#include "barretenberg/proof_system/execution_trace/execution_trace.hpp"
#include "barretenberg/srs/factories/file_crs_factory.hpp"
#include <utility>

Expand All @@ -16,6 +17,7 @@ class StandardComposer {
using Flavor = plonk::flavor::Standard;

using CircuitBuilder = StandardCircuitBuilder;
using Trace = ExecutionTrace_<Flavor>;

static constexpr std::string_view NAME_STRING = "StandardPlonk";
static constexpr size_t NUM_RESERVED_GATES = 4; // equal to the number of evaluations leaked
Expand Down Expand Up @@ -60,7 +62,6 @@ class StandardComposer {
plonk::Verifier create_verifier(const CircuitBuilder& circuit_constructor);
plonk::Prover create_prover(const CircuitBuilder& circuit_constructor);

void compute_witness(const CircuitBuilder& circuit_constructor, const size_t minimum_circuit_size = 0);
/**
* Create a manifest, which specifies proof rounds, elements and who supplies them.
*
Expand Down
Loading
Loading