-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: conventional lookups using log-deriv (#7020)
Replaces the plookup based lookup argument in UltraHonk/MegaHonk with a log-derivative based argument. This is advantageous in a number of ways including 1) no more committing to expensive z_lookup poly (especially relevant for structured trace), 2) prover work is proportional to number of lookups not size of circuit.' Below are the benchmark results (master vs branch). Note that most of the benefit is derived from no longer needing to commit to `z_lookup` which was previously the most expensive single commitment. The Lookup relation also goes from being 45% of total accumulate work, to only 10%. ``` -------------------------------------------------------------------------------- Benchmark Time CPU Iterations UserCounters... -------------------------------------------------------------------------------- ClientIVCBench/Full/6 16151 ms 11247 ms 1 function ms % sum construct_circuits(t) 3241 20.23% ProverInstance(Circuit&)(t) 1575 9.83% ProtogalaxyProver::fold_instances(t) 7627 47.61% Decider::construct_proof(t) 503 3.14% ECCVMProver(CircuitBuilder&)(t) 173 1.08% ECCVMProver::construct_proof(t) 1904 11.88% TranslatorProver::construct_proof(t) 819 5.11% Goblin::merge(t) 177 1.11% Total time accounted for: 16019ms/16151ms = 99.18% Major contributors: function ms % sum commit(t) 4114 25.68% compute_combiner(t) 2824 17.63% compute_perturbator(t) 795 4.96% compute_univariate(t) 1149 7.17% Breakdown of ProtogalaxyProver::fold_instances: ProtoGalaxyProver_::preparation_round(t) 3721 48.79% ProtoGalaxyProver_::perturbator_round(t) 795 10.43% ProtoGalaxyProver_::combiner_quotient_round(t) 2826 37.05% ProtoGalaxyProver_::accumulator_update_round(t) 284 3.73% Relation contributions (times to be interpreted relatively): function ms % sum Arithmetic::accumulate(t) 1490 5.78% Permutation::accumulate(t) 6746 26.18% Lookup::accumulate(t) 11679 45.33% DeltaRange::accumulate(t) 977 3.79% Elliptic::accumulate(t) 635 2.46% Auxiliary::accumulate(t) 3812 14.79% EccOp::accumulate(t) 0 0.00% DatabusRead::accumulate(t) 1 0.01% PoseidonExt::accumulate(t) 110 0.43% PoseidonInt::accumulate(t) 316 1.23% ``` ``` -------------------------------------------------------------------------------- Benchmark Time CPU Iterations UserCounters... -------------------------------------------------------------------------------- ClientIVCBench/Full/6 15345 ms 10707 ms 1 function ms % sum construct_circuits(t) 3183 21.01% ProverInstance(Circuit&)(t) 1697 11.20% ProtogalaxyProver::fold_instances(t) 6754 44.57% Decider::construct_proof(t) 467 3.08% ECCVMProver(CircuitBuilder&)(t) 176 1.16% ECCVMProver::construct_proof(t) 1910 12.60% TranslatorProver::construct_proof(t) 815 5.38% Goblin::merge(t) 150 0.99% Total time accounted for: 15153ms/15345ms = 98.74% Major contributors: function ms % sum commit(t) 3379 22.30% compute_combiner(t) 2200 14.52% compute_perturbator(t) 739 4.87% compute_univariate(t) 1118 7.38% Breakdown of ProtogalaxyProver::fold_instances: ProtoGalaxyProver_::preparation_round(t) 3529 52.24% ProtoGalaxyProver_::perturbator_round(t) 739 10.94% ProtoGalaxyProver_::combiner_quotient_round(t) 2202 32.60% ProtoGalaxyProver_::accumulator_update_round(t) 285 4.22% Relation contributions (times to be interpreted relatively): function ms % sum Arithmetic::accumulate(t) 1474 9.69% Permutation::accumulate(t) 6515 42.84% Lookup::accumulate(t) 1622 10.67% DeltaRange::accumulate(t) 952 6.26% Elliptic::accumulate(t) 605 3.98% Auxiliary::accumulate(t) 3616 23.78% EccOp::accumulate(t) 0 0.00% DatabusRead::accumulate(t) 1 0.01% PoseidonExt::accumulate(t) 112 0.74% PoseidonInt::accumulate(t) 309 2.03% ```
- Loading branch information
1 parent
9aabc32
commit 6f1212f
Showing
38 changed files
with
960 additions
and
924 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
barretenberg/cpp/src/barretenberg/plonk_honk_shared/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
barretenberg_module(plonk_honk_shared polynomials) | ||
barretenberg_module(plonk_honk_shared polynomials ultra_honk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 66 additions & 9 deletions
75
barretenberg/cpp/src/barretenberg/plonk_honk_shared/composer/composer_lib.test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,78 @@ | ||
#include "barretenberg/plonk_honk_shared/composer/composer_lib.hpp" | ||
#include "barretenberg/common/slab_allocator.hpp" | ||
#include "barretenberg/plonk_honk_shared/types/circuit_type.hpp" | ||
#include "barretenberg/srs/factories/crs_factory.hpp" | ||
#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" | ||
#include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp" | ||
|
||
#include <array> | ||
#include <gtest/gtest.h> | ||
|
||
using namespace bb; | ||
|
||
class ComposerLibTests : public ::testing::Test { | ||
public: | ||
using Flavor = UltraFlavor; | ||
using FF = typename Flavor::FF; | ||
|
||
protected: | ||
static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } | ||
}; | ||
|
||
/** | ||
* @brief A test to demonstrate that lookup read counts/tags are computed correctly for a simple 'hand-computable' case | ||
* using the uint32 XOR table | ||
* | ||
*/ | ||
TEST_F(ComposerLibTests, LookupReadCounts) | ||
{ | ||
using Builder = UltraCircuitBuilder; | ||
using Flavor = UltraFlavor; | ||
using FF = typename Flavor::FF; | ||
Flavor::CircuitBuilder circuit_constructor; | ||
Flavor::ProvingKey proving_key = []() { | ||
auto crs_factory = srs::factories::CrsFactory<bb::curve::BN254>(); | ||
auto crs = crs_factory.get_prover_crs(4); | ||
return Flavor::ProvingKey(/*circuit_size=*/8, /*num_public_inputs=*/0); | ||
}(); | ||
}; | ||
using Polynomial = typename Flavor::Polynomial; | ||
auto UINT32_XOR = plookup::MultiTableId::UINT32_XOR; | ||
|
||
Builder builder; | ||
|
||
// define some very simply inputs to XOR | ||
FF left{ 1 }; | ||
FF right{ 5 }; | ||
|
||
auto left_idx = builder.add_variable(left); | ||
auto right_idx = builder.add_variable(right); | ||
|
||
// create a single lookup from the uint32 XOR table | ||
auto accumulators = plookup::get_lookup_accumulators(UINT32_XOR, left, right, /*is_2_to_1_lookup*/ true); | ||
builder.create_gates_from_plookup_accumulators(UINT32_XOR, accumulators, left_idx, right_idx); | ||
|
||
EXPECT_EQ(builder.lookup_tables.size(), 1); // we only used a single table | ||
EXPECT_EQ(builder.lookup_tables[0].size(), 4096); // table has size 64*64 (6 bit operands) | ||
|
||
size_t circuit_size = 8192; | ||
|
||
Polynomial read_counts{ circuit_size }; | ||
Polynomial read_tags{ circuit_size }; | ||
|
||
construct_lookup_read_counts<Flavor>(read_counts, read_tags, builder, circuit_size); | ||
|
||
// The table polys are constructed at the bottom of the trace, thus so to are the counts/tags | ||
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace | ||
size_t offset = circuit_size - builder.get_tables_size(); | ||
|
||
// The uint32 XOR lookup table is constructed for 6 bit operands via double for loop that iterates through the left | ||
// operand externally (0 to 63) then the right operand internally (0 to 63). Computing (1 XOR 5) will thus result in | ||
// 1 lookup from the (1*64 + 5)th index in the table and 5 lookups from the (0*64 + 0)th index (for the remaining 5 | ||
// limbs that are all 0). The counts and tags at all other indices should be zero. | ||
size_t idx = 0; | ||
for (auto [count, tag] : zip_view(read_counts, read_tags)) { | ||
if (idx == (0 + offset)) { | ||
EXPECT_EQ(count, 5); | ||
EXPECT_EQ(tag, 1); | ||
} else if (idx == (69 + offset)) { | ||
EXPECT_EQ(count, 1); | ||
EXPECT_EQ(tag, 1); | ||
} else { | ||
EXPECT_EQ(count, 0); | ||
EXPECT_EQ(tag, 0); | ||
} | ||
idx++; | ||
} | ||
} |
Oops, something went wrong.