Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
native_crs_factory.hpp
Go to the documentation of this file.
1#pragma once
6#include <filesystem>
7#include <memory>
8#ifndef NO_MULTITHREADING
9#include <mutex>
10#endif
11
12namespace bb::srs::factories {
13
28MemBn254CrsFactory init_bn254_crs(const std::filesystem::path& path,
29 size_t dyadic_circuit_size,
30 bool allow_download = true);
31MemGrumpkinCrsFactory init_grumpkin_crs(const std::filesystem::path& path,
32 size_t eccvm_dyadic_circuit_size,
33 bool allow_download = true);
34
38class NativeBn254CrsFactory : public CrsFactory<curve::BN254> {
39 public:
40 NativeBn254CrsFactory(const std::filesystem::path& path, bool allow_download = true)
41 : path_(path)
42 , allow_download_(allow_download)
43 {}
45 {
46#ifndef NO_MULTITHREADING
48#endif
49 if (degree > last_degree_ || mem_crs_ == nullptr) {
51 last_degree_ = degree;
52 }
53 return mem_crs_->get_crs(degree);
54 }
55
56 private:
57 std::filesystem::path path_;
58 bool allow_download_ = true;
59 size_t last_degree_ = 0;
61#ifndef NO_MULTITHREADING
62 std::mutex mutex_;
63#endif
64};
65
66class NativeGrumpkinCrsFactory : public CrsFactory<curve::Grumpkin> {
67 public:
68 NativeGrumpkinCrsFactory(const std::filesystem::path& path, bool allow_download = true)
69 : path_(path)
70 , allow_download_(allow_download)
71 {}
72
74 {
75#ifndef NO_MULTITHREADING
77#endif
78 if (degree > last_degree_ || mem_crs_ == nullptr) {
80 last_degree_ = degree;
81 }
82 return mem_crs_->get_crs(degree);
83 }
84
85 private:
86 std::filesystem::path path_;
87 bool allow_download_ = true;
88 size_t last_degree_ = 0;
90#ifndef NO_MULTITHREADING
91 std::mutex mutex_;
92#endif
93};
94
95} // namespace bb::srs::factories
NativeBn254CrsFactory(const std::filesystem::path &path, bool allow_download=true)
std::shared_ptr< MemBn254CrsFactory > mem_crs_
std::shared_ptr< Crs< curve::BN254 > > get_crs(size_t degree) override
std::shared_ptr< Crs< curve::Grumpkin > > get_crs(size_t degree) override
NativeGrumpkinCrsFactory(const std::filesystem::path &path, bool allow_download=true)
std::unique_ptr< MemGrumpkinCrsFactory > mem_crs_
MemBn254CrsFactory init_bn254_crs(const std::filesystem::path &path, size_t dyadic_circuit_size, bool allow_download)
Initialize a memory crs factory for bn254 based on a known dyadic circuit size.
MemGrumpkinCrsFactory init_grumpkin_crs(const std::filesystem::path &path, size_t eccvm_dyadic_circuit_size, bool allow_download)
Initialize a memory crs factory for grumpkin based on a known dyadic circuit size.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13