-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR: 1. Adds a new function run_loop_in_parallel to thread.hpp so that it's easier to use parallelism in most cases without redoing the computation for splitting the workload into chunks every time. 2. Uses this new functionality to parallelise logic in IPA open and verify procedures (and used methods) (x20-x30 improvement for ECCVM proving) 3. Fixes an error in using one of the vectors in IPA opening procedure which led to an additional nlogn complexity. 4. Adds an IPA opening and verification benchmark
- Loading branch information
Showing
8 changed files
with
419 additions
and
144 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Each source represents a separate benchmark suite | ||
set(BENCHMARK_SOURCES | ||
ipa.bench.cpp | ||
) | ||
|
||
# Required libraries for benchmark suites | ||
set(LINKED_LIBRARIES | ||
benchmark::benchmark | ||
ultra_honk | ||
) | ||
|
||
# Add executable and custom target for each suite, e.g. ultra_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 ${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() |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "barretenberg/commitment_schemes/ipa/ipa.hpp" | ||
#include <benchmark/benchmark.h> | ||
|
||
using namespace benchmark; | ||
using namespace barretenberg; | ||
using namespace proof_system; | ||
using namespace proof_system::honk::pcs::ipa; | ||
namespace { | ||
using Curve = curve::Grumpkin; | ||
using Fr = Curve::ScalarField; | ||
using IPA = IPA<Curve>; | ||
using OpeningPair = honk::pcs::OpeningPair<Curve>; | ||
using OpeningClaim = honk::pcs::OpeningClaim<Curve>; | ||
using Polynomial = Polynomial<Curve::ScalarField>; | ||
using CommitmentKey = honk::pcs::CommitmentKey<Curve>; | ||
using VerifierCommitmentKey = honk::pcs::VerifierCommitmentKey<Curve>; | ||
|
||
constexpr size_t MIN_POLYNOMIAL_DEGREE_LOG2 = 10; | ||
constexpr size_t MAX_POLYNOMIAL_DEGREE_LOG2 = 16; | ||
std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::Grumpkin>> crs_factory( | ||
new barretenberg::srs::factories::FileCrsFactory<curve::Grumpkin>("../srs_db/grumpkin", 1 << 16)); | ||
|
||
auto ck = std::make_shared<CommitmentKey>(1 << MAX_POLYNOMIAL_DEGREE_LOG2, crs_factory); | ||
auto vk = std::make_shared<VerifierCommitmentKey>(1 << MAX_POLYNOMIAL_DEGREE_LOG2, crs_factory); | ||
|
||
std::vector<std::shared_ptr<honk::BaseTranscript>> prover_transcripts(MAX_POLYNOMIAL_DEGREE_LOG2 - | ||
MIN_POLYNOMIAL_DEGREE_LOG2 + 1); | ||
std::vector<OpeningClaim> opening_claims(MAX_POLYNOMIAL_DEGREE_LOG2 - MIN_POLYNOMIAL_DEGREE_LOG2 + 1); | ||
|
||
void ipa_open(State& state) noexcept | ||
{ | ||
numeric::random::Engine& engine = numeric::random::get_debug_engine(); | ||
for (auto _ : state) { | ||
state.PauseTiming(); | ||
size_t n = 1 << static_cast<size_t>(state.range(0)); | ||
// Construct the polynomial | ||
Polynomial poly(n); | ||
for (size_t i = 0; i < n; ++i) { | ||
poly[i] = Fr::random_element(&engine); | ||
} | ||
auto x = Fr::random_element(&engine); | ||
auto eval = poly.evaluate(x); | ||
const OpeningPair opening_pair = { x, eval }; | ||
const OpeningClaim opening_claim{ opening_pair, ck->commit(poly) }; | ||
// initialize empty prover transcript | ||
auto prover_transcript = std::make_shared<honk::BaseTranscript>(); | ||
state.ResumeTiming(); | ||
// Compute proof | ||
IPA::compute_opening_proof(ck, opening_pair, poly, prover_transcript); | ||
// Store info for verifier | ||
prover_transcripts[static_cast<size_t>(state.range(0)) - MIN_POLYNOMIAL_DEGREE_LOG2] = prover_transcript; | ||
opening_claims[static_cast<size_t>(state.range(0)) - MIN_POLYNOMIAL_DEGREE_LOG2] = opening_claim; | ||
} | ||
} | ||
void ipa_verify(State& state) noexcept | ||
{ | ||
for (auto _ : state) { | ||
state.PauseTiming(); | ||
// Retrieve proofs | ||
auto prover_transcript = prover_transcripts[static_cast<size_t>(state.range(0)) - MIN_POLYNOMIAL_DEGREE_LOG2]; | ||
auto opening_claim = opening_claims[static_cast<size_t>(state.range(0)) - MIN_POLYNOMIAL_DEGREE_LOG2]; | ||
// initialize verifier transcript from proof data | ||
auto verifier_transcript = std::make_shared<honk::BaseTranscript>(prover_transcript->proof_data); | ||
|
||
state.ResumeTiming(); | ||
auto result = IPA::verify(vk, opening_claim, verifier_transcript); | ||
ASSERT(result); | ||
} | ||
} | ||
} // namespace | ||
BENCHMARK(ipa_open)->Unit(kMillisecond)->DenseRange(MIN_POLYNOMIAL_DEGREE_LOG2, MAX_POLYNOMIAL_DEGREE_LOG2); | ||
BENCHMARK(ipa_verify)->Unit(kMillisecond)->DenseRange(MIN_POLYNOMIAL_DEGREE_LOG2, MAX_POLYNOMIAL_DEGREE_LOG2); | ||
BENCHMARK_MAIN(); |
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
Oops, something went wrong.