Skip to content

Commit

Permalink
proof_producer: support alt_bn128<254>
Browse files Browse the repository at this point in the history
  • Loading branch information
akokoshn committed Feb 10, 2025
1 parent 4580b49 commit 2f387ce
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <tuple>

#include <nil/crypto3/algebra/curves/pallas.hpp>
#include <nil/crypto3/algebra/curves/alt_bn128.hpp>
#include <nil/crypto3/algebra/curves/vesta.hpp>
#include <nil/crypto3/hash/keccak.hpp>
#include <nil/crypto3/hash/poseidon.hpp>
Expand All @@ -30,17 +31,9 @@
namespace nil {
namespace proof_producer {

using CurveTypes = std::tuple<nil::crypto3::algebra::curves::pallas
// Add more curves as needed.
using CurveTypes = std::tuple<nil::crypto3::algebra::curves::pallas,
nil::crypto3::algebra::curves::alt_bn128<254>
// Add more hashes as needed.
>;

using HashTypes = std::tuple<
nil::crypto3::hashes::keccak_1600<256>,
nil::crypto3::hashes::sha2<256>,
nil::crypto3::hashes::poseidon<nil::crypto3::hashes::detail::pasta_poseidon_policy<
nil::crypto3::algebra::curves::pallas::base_field_type>>
// Add more hashes as needed.
>;

} // namespace proof_producer
} // namespace nil
21 changes: 5 additions & 16 deletions proof-producer/bin/proof-producer/src/arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ namespace nil {
("assignment-table,t", po::value(&prover_options.assignment_table_file_path), "Assignment table input file")
("assignment-description-file", po::value(&prover_options.assignment_description_file_path), "Assignment description file")
("log-level,l", make_defaulted_option(prover_options.log_level), "Log level (trace, debug, info, warning, error, fatal)") // TODO is does not work
("elliptic-curve-type,e", make_defaulted_option(prover_options.elliptic_curve_type), "Elliptic curve type (pallas)")
("hash-type", make_defaulted_option(prover_options.hash_type), "Hash type (keccak, poseidon, sha256)")
("elliptic-curve-type,e", make_defaulted_option(prover_options.elliptic_curve_type), "Elliptic curve type (pallas, alt_bn128_254)")
("hash-type", po::value(&prover_options.hash_type_str), "Hash type (keccak, poseidon, sha256)")
("lambda-param", make_defaulted_option(prover_options.lambda), "Lambda param (9)")
("grind-param", make_defaulted_option(prover_options.grind), "Grind param (0)")
("expand-factor,x", make_defaulted_option(prover_options.expand_factor), "Expand factor")
Expand Down Expand Up @@ -234,26 +234,15 @@ namespace nil {
if (NAME == str) \
return type_identity<TYPE>{};

#define CURVE_TYPES X(nil::crypto3::algebra::curves::pallas, "pallas")
#define CURVE_TYPES \
X(nil::crypto3::algebra::curves::alt_bn128<254>, "alt_bn128_254") \
X(nil::crypto3::algebra::curves::pallas, "pallas")
#define X(type, name) TYPE_TO_STRING(type, name)
GENERATE_WRITE_OPERATOR(CURVE_TYPES, CurvesVariant)
#undef X
#define X(type, name) STRING_TO_TYPE(type, name)
GENERATE_READ_OPERATOR(CURVE_TYPES, CurvesVariant)
#undef X

#define HASH_TYPES \
X(nil::crypto3::hashes::keccak_1600<256>, "keccak") \
X(nil::crypto3::hashes::poseidon<nil::crypto3::hashes::detail::pasta_poseidon_policy< \
typename nil::crypto3::algebra::curves::pallas::base_field_type>>, \
"poseidon") \
X(nil::crypto3::hashes::sha2<256>, "sha256")
#define X(type, name) TYPE_TO_STRING(type, name)
GENERATE_WRITE_OPERATOR(HASH_TYPES, HashesVariant)
#undef X
#define X(type, name) STRING_TO_TYPE(type, name)
GENERATE_READ_OPERATOR(HASH_TYPES, HashesVariant)
#undef X

} // namespace proof_producer
} // namespace nil
4 changes: 1 addition & 3 deletions proof-producer/bin/proof-producer/src/arg_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ namespace nil {

using CurvesVariant =
typename tuple_to_variant<typename transform_tuple<CurveTypes, to_type_identity>::type>::type;
using HashesVariant =
typename tuple_to_variant<typename transform_tuple<HashTypes, to_type_identity>::type>::type;

struct ProverOptions {
std::string stage = "all";
Expand Down Expand Up @@ -65,7 +63,7 @@ namespace nil {
boost::filesystem::path proof_of_work_output_file = "proof_of_work.dat";
boost::log::trivial::severity_level log_level = boost::log::trivial::severity_level::info;
CurvesVariant elliptic_curve_type = type_identity<nil::crypto3::algebra::curves::pallas>{};
HashesVariant hash_type = type_identity<nil::crypto3::hashes::keccak_1600<256>>{};
std::string hash_type_str = "keccak";

std::size_t lambda = 9;
std::size_t grind = 0;
Expand Down
21 changes: 16 additions & 5 deletions proof-producer/bin/proof-producer/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,22 @@ int run_prover(const nil::proof_producer::ProverOptions& prover_options) {
template<typename CurveType>
int hash_wrapper(const ProverOptions& prover_options) {
int ret;
auto run_prover_wrapper_void = [&prover_options, &ret]<typename HashTypeIdentity>() {
using HashType = typename HashTypeIdentity::type;
ret = run_prover<CurveType, HashType>(prover_options);
};
pass_variant_type_to_template_func<HashesVariant>(prover_options.hash_type, run_prover_wrapper_void);
if (prover_options.hash_type_str == "keccak") {
ret = run_prover<CurveType, nil::crypto3::hashes::keccak_1600<256>>(prover_options);
} else if (prover_options.hash_type_str == "sha256") {
ret = run_prover<CurveType, nil::crypto3::hashes::sha2<256>>(prover_options);
} else if (prover_options.hash_type_str == "poseidon") {
if constexpr (std::is_same<CurveType,nil::crypto3::algebra::curves::pallas>::value) {
ret = run_prover<CurveType,
nil::crypto3::hashes::poseidon<nil::crypto3::hashes::detail::pasta_poseidon_policy<typename CurveType::scalar_field_type>>>(prover_options);
} else {
ret = run_prover<CurveType,
nil::crypto3::hashes::poseidon<nil::crypto3::hashes::detail::poseidon_policy<typename CurveType::scalar_field_type, 128, 2>>>(prover_options);
}
} else {
BOOST_LOG_TRIVIAL(error) << "Unknown hash type " << prover_options.hash_type_str;
return static_cast<int>(ResultCode::InvalidInput);
}
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <nil/marshalling/status_type.hpp>

#include <nil/crypto3/algebra/fields/arithmetic_params/pallas.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/alt_bn128.hpp>
#include <nil/crypto3/marshalling/zk/types/commitments/eval_storage.hpp>
#include <nil/crypto3/marshalling/zk/types/commitments/lpc.hpp>
#include <nil/crypto3/marshalling/zk/types/placeholder/common_data.hpp>
Expand Down Expand Up @@ -61,7 +62,7 @@ namespace nil {
// common type definitions needed for proof generation & verification steps
template<typename CurveType, typename HashType>
struct TypeSystem {
using BlueprintField = typename CurveType::base_field_type;
using BlueprintField = typename CurveType::scalar_field_type;
using LpcParams = nil::crypto3::zk::commitments::list_polynomial_commitment_params<HashType, HashType, 2>;
using Lpc = nil::crypto3::zk::commitments::list_polynomial_commitment<BlueprintField, LpcParams>;
using LpcScheme = typename nil::crypto3::zk::commitments::lpc_commitment_scheme<Lpc>;
Expand Down

0 comments on commit 2f387ce

Please sign in to comment.