Skip to content

Commit

Permalink
standard honk on grumpkin
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Jul 28, 2023
1 parent a0b01e7 commit 758d319
Show file tree
Hide file tree
Showing 96 changed files with 1,186 additions and 926 deletions.
2 changes: 1 addition & 1 deletion build-system
6 changes: 6 additions & 0 deletions circuits/cpp/barretenberg/cpp/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ echo "#################################"
cmake --preset $PRESET -DCMAKE_BUILD_TYPE=RelWithAssert
cmake --build --preset $PRESET ${@/#/--target }

cd ./build
# The Grumpkin SRS is generated manually at the moment only up to a large enough size for tests
cmake --build . --parallel --target grumpkin_srs_gen
./bin/grumpkin_srs_gen 4096
echo "Generated Grumpkin SRS successfully"

# Install wasi-sdk.
./scripts/install-wasi-sdk.sh

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ struct acir_format {
// A standard plonk arithmetic constraint, as defined in the poly_triple struct, consists of selector values
// for q_M,q_L,q_R,q_O,q_C and indices of three variables taking the role of left, right and output wire
// This could be a large vector so use slab allocator, we don't expect the blackbox implementations to be so large.
std::vector<poly_triple, ContainerSlabAllocator<poly_triple>> constraints;
std::vector<poly_triple_<curve::BN254::ScalarField>,
ContainerSlabAllocator<poly_triple_<curve::BN254::ScalarField>>>
constraints;
std::vector<BlockConstraint> block_constraints;

// For serialization, update with any new fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ void AcirComposer::create_circuit(acir_format::acir_format& constraint_system)
size_hint_ = circuit_subgroup_size_;
}

void AcirComposer::init_proving_key(std::shared_ptr<barretenberg::srs::factories::CrsFactory> const& crs_factory,
acir_format::acir_format& constraint_system)
void AcirComposer::init_proving_key(
std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::BN254>> const& crs_factory,
acir_format::acir_format& constraint_system)
{
vinfo("building circuit... ", size_hint_);
builder_ = acir_format::Builder(size_hint_);
Expand All @@ -52,7 +53,7 @@ void AcirComposer::init_proving_key(std::shared_ptr<barretenberg::srs::factories
}

std::vector<uint8_t> AcirComposer::create_proof(
std::shared_ptr<barretenberg::srs::factories::CrsFactory> const& crs_factory,
std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::BN254>> const& crs_factory,
acir_format::acir_format& constraint_system,
acir_format::WitnessVector& witness,
bool is_recursive)
Expand Down Expand Up @@ -107,8 +108,9 @@ std::shared_ptr<proof_system::plonk::verification_key> AcirComposer::init_verifi
return verification_key_;
}

void AcirComposer::load_verification_key(std::shared_ptr<barretenberg::srs::factories::CrsFactory> const& crs_factory,
proof_system::plonk::verification_key_data&& data)
void AcirComposer::load_verification_key(
std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::BN254>> const& crs_factory,
proof_system::plonk::verification_key_data&& data)
{
verification_key_ =
std::make_shared<proof_system::plonk::verification_key>(std::move(data), crs_factory->get_verifier_crs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ class AcirComposer {

void create_circuit(acir_format::acir_format& constraint_system);

void init_proving_key(std::shared_ptr<barretenberg::srs::factories::CrsFactory> const& crs_factory,
void init_proving_key(std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::BN254>> const& crs_factory,
acir_format::acir_format& constraint_system);

std::vector<uint8_t> create_proof(std::shared_ptr<barretenberg::srs::factories::CrsFactory> const& crs_factory,
acir_format::acir_format& constraint_system,
acir_format::WitnessVector& witness,
bool is_recursive);
std::vector<uint8_t> create_proof(
std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::BN254>> const& crs_factory,
acir_format::acir_format& constraint_system,
acir_format::WitnessVector& witness,
bool is_recursive);

void load_verification_key(std::shared_ptr<barretenberg::srs::factories::CrsFactory> const& crs_factory,
proof_system::plonk::verification_key_data&& data);
void load_verification_key(
std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::BN254>> const& crs_factory,
proof_system::plonk::verification_key_data&& data);

std::shared_ptr<proof_system::plonk::verification_key> init_verification_key();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct GrumpkinG1Params {
};
static constexpr barretenberg::fr a{ 0UL, 0UL, 0UL, 0UL };

// generator point = (x, y) = (1, sqrt(-15))
// generator point = (x, y) = (1, sqrt(-16)), sqrt(-16) = 4i
static constexpr barretenberg::fr one_x = barretenberg::fr::one();
static constexpr barretenberg::fr one_y{
0x11b2dff1448c41d8UL, 0x23d3446f21c77dc3UL, 0xaa7b8cf435dfafbbUL, 0x14b34cf69dc25d68UL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void build_circuit(Builder& builder)
}

BuilderComposerPtrs create_builder_and_composer(
std::shared_ptr<barretenberg::srs::factories::CrsFactory> const& crs_factory)
std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::BN254>> const& crs_factory)
{
// WARNING: Size hint is essential to perform 512k circuits!
auto builder = std::make_unique<Builder>(CIRCUIT_SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct BuilderComposerPtrs {
};

BuilderComposerPtrs create_builder_and_composer(
std::shared_ptr<barretenberg::srs::factories::CrsFactory> const& crs_factory);
std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::BN254>> const& crs_factory);

proof create_proof(BuilderComposerPtrs pair);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace examples::simple {
TEST(examples_simple, create_proof)
{
auto srs_path = std::filesystem::absolute("../srs_db/ignition");
auto crs_factory = std::make_shared<barretenberg::srs::factories::FileCrsFactory>(srs_path);
auto crs_factory = std::make_shared<barretenberg::srs::factories::FileCrsFactory<curve::BN254>>(srs_path);
auto ptrs = create_builder_and_composer(crs_factory);
auto proof = create_proof(ptrs);
bool valid = verify_proof(ptrs, proof);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const std::string protocol_name = "BARRETENBERG_GRUMPKIN_IPA_CRS";
/**
* @brief Generates a monomial basis Grumpkin SRS.
*
* @details We only provide functionality create a single transcript file.
* @details We only provide functionality to create a single transcript file.
* ! Note that, unlike the bn254 SRS, the first element of the Grumpkin SRS will not be equal to point one defined in
* grumpkin.hpp as this function finds Grumpkin points in an arbitrary order.
*
*/
int main(int argc, char** argv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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> crs_factory_;
std::shared_ptr<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<PCSCommitmentKey> commitment_key;
Expand All @@ -37,15 +37,22 @@ template <StandardFlavor Flavor> class StandardComposer_ {

bool computed_witness = false;
// TODO(Luke): use make_shared
// TODO(#637): design the crs factory better
StandardComposer_()
: StandardComposer_(
std::shared_ptr<srs::factories::CrsFactory>(new srs::factories::FileCrsFactory("../srs_db/ignition")))
{}
StandardComposer_(std::shared_ptr<srs::factories::CrsFactory> crs_factory)
{
if constexpr (IsGrumpkinFlavor<Flavor>) {
crs_factory_ = barretenberg::srs::get_grumpkin_crs_factory();

} else {
crs_factory_ = barretenberg::srs::get_crs_factory();
}
}

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

StandardComposer_(std::unique_ptr<srs::factories::CrsFactory>&& crs_factory)
StandardComposer_(std::unique_ptr<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
Loading

0 comments on commit 758d319

Please sign in to comment.