Skip to content

Commit

Permalink
Style adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
x-mass committed Mar 5, 2024
1 parent b8a36ab commit c975db4
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 42 deletions.
4 changes: 3 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
BasedOnStyle: WebKit
BasedOnStyle: Google
AccessModifierOffset: -4 # To keep them at the same column as `class`
AlignAfterOpenBracket: BlockIndent
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
Expand Down Expand Up @@ -68,6 +69,7 @@ IncludeCategories:
Priority: 4
- Regex: '.*'
Priority: 5
IndentAccessModifiers: false
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
Expand Down
14 changes: 7 additions & 7 deletions bin/proof-generator/include/nil/proof-generator/arg_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ namespace nil {
using HashesVariant =
typename tuple_to_variant<typename transform_tuple<HashTypes, to_type_identity>::type>::type;

struct prover_options {
struct ProverOptions {
boost::filesystem::path proof_file_path = "proof.bin";
boost::filesystem::path preprocessed_common_data_path = "preprocessed_common_data.dat";
boost::filesystem::path circuit_file_path;
boost::filesystem::path assignment_table_file_path;
boost::log::trivial::severity_level log_level = boost::log::trivial::severity_level::info;
bool skip_verification = false;
bool verification_only = false;
CurvesVariant elliptic_curve_type = type_identity<nil::crypto3::algebra::curves::pallas> {};
HashesVariant hash_type = type_identity<nil::crypto3::hashes::keccak_1600<256>> {};
columns_params columns = all_columns_params[0];
lambda_param lambda = all_lambda_params[0];
grind_param grind = all_grind_params[0];
CurvesVariant elliptic_curve_type = type_identity<nil::crypto3::algebra::curves::pallas>{};
HashesVariant hash_type = type_identity<nil::crypto3::hashes::keccak_1600<256>>{};
ColumnsParams columns = all_columns_params[0];
LambdaParam lambda = all_lambda_params[0];
GrindParam grind = all_grind_params[0];
std::size_t expand_factor = 2;
};

std::optional<prover_options> parse_args(int argc, char* argv[]);
std::optional<ProverOptions> parse_args(int argc, char* argv[]);

} // namespace proof_generator
} // namespace nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ namespace nil {
// Available in runtime columns params. Order is:
// witness | public_input | component_constant | component_selector |
// lookup_constant | lookup_selector
constexpr std::array<columns_params, 4> all_columns_params = {{
constexpr std::array<ColumnsParams, 4> all_columns_params = {{
{15, 1, 5, 50, 30, 6},
{15, 1, 5, 60, 0, 0},
{15, 1, 2, 50, 14, 6},
{15, 1, 5, 30, 30, 6}
// Add more params as needed.
}};

constexpr std::array<lambda_param, 1> all_lambda_params = {
constexpr std::array<LambdaParam, 1> all_lambda_params = {
9
// Add more params as needed.
};

constexpr std::array<grind_param, 1> all_grind_params = {
constexpr std::array<GrindParam, 1> all_grind_params = {
69
// Add more params as needed.
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
namespace nil {
namespace proof_generator {

struct columns_params {
struct ColumnsParams {
std::size_t witness_columns;
std::size_t public_input_columns;
std::size_t component_constant_columns;
std::size_t component_selector_columns;
std::size_t lookup_constant_columns;
std::size_t lookup_selector_columns;

bool operator==(const columns_params& other) const {
bool operator==(const ColumnsParams& other) const {
return witness_columns == other.witness_columns && public_input_columns == other.public_input_columns
&& component_constant_columns == other.component_constant_columns
&& component_selector_columns == other.component_selector_columns
Expand All @@ -41,32 +41,32 @@ namespace nil {

// Need this class to be derived into actual params, so we could overload
// read/write operators for parsing.
class size_t_param {
class SizeTParam {
public:
size_t_param() = default; // lexical_cast wants it
constexpr size_t_param(std::size_t value)
SizeTParam() = default; // lexical_cast wants it
constexpr SizeTParam(std::size_t value)
: value_(value) {
}

constexpr operator std::size_t() const {
return value_;
}

bool operator==(const size_t_param& other) const {
bool operator==(const SizeTParam& other) const {
return value_ == other.value_;
}

private:
std::size_t value_;
};

class lambda_param : public size_t_param {
class LambdaParam : public SizeTParam {
public:
using size_t_param::size_t_param;
using SizeTParam::SizeTParam;
};
class grind_param : public size_t_param {
class GrindParam : public SizeTParam {
public:
using size_t_param::size_t_param;
using SizeTParam::SizeTParam;
};

} // namespace proof_generator
Expand Down
26 changes: 13 additions & 13 deletions bin/proof-generator/src/arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace nil {
}
}

std::optional<prover_options> parse_args(int argc, char* argv[]) {
std::optional<ProverOptions> parse_args(int argc, char* argv[]) {
po::options_description options("Nil; Proof Generator Options");
// Declare a group of options that will be
// allowed only on command line
Expand All @@ -68,7 +68,7 @@ namespace nil {
("list-columns-params", "Print available columns params");
// clang-format on

prover_options prover_options;
ProverOptions prover_options;

// Declare a group of options that will be
// allowed both on command line and in
Expand Down Expand Up @@ -163,13 +163,13 @@ namespace nil {
// >> and << operators are needed for Boost porgram_options to read values and
// to print default values to help message: The rest of the file contains them:

std::ostream& operator<<(std::ostream& strm, const columns_params& columns) {
std::ostream& operator<<(std::ostream& strm, const ColumnsParams& columns) {
auto it = std::find(all_columns_params.cbegin(), all_columns_params.cend(), columns);
strm << std::distance(all_columns_params.cbegin(), it);
return strm;
}

std::istream& operator>>(std::istream& strm, columns_params& columns) {
std::istream& operator>>(std::istream& strm, ColumnsParams& columns) {
std::string str;
strm >> str;
std::size_t pos;
Expand All @@ -182,12 +182,12 @@ namespace nil {
return strm;
}

std::ostream& operator<<(std::ostream& strm, const lambda_param& lambda) {
std::ostream& operator<<(std::ostream& strm, const LambdaParam& lambda) {
strm << static_cast<size_t>(lambda);
return strm;
}

std::istream& operator>>(std::istream& strm, lambda_param& lambda) {
std::istream& operator>>(std::istream& strm, LambdaParam& lambda) {
std::string str;
strm >> str;
std::size_t pos;
Expand All @@ -196,7 +196,7 @@ namespace nil {
strm.setstate(std::ios_base::failbit);
} else {
auto it =
std::find(all_lambda_params.cbegin(), all_lambda_params.cend(), static_cast<lambda_param>(val));
std::find(all_lambda_params.cbegin(), all_lambda_params.cend(), static_cast<LambdaParam>(val));
if (it != all_lambda_params.cend()) {
lambda = val;
} else {
Expand All @@ -206,20 +206,20 @@ namespace nil {
return strm;
}

std::ostream& operator<<(std::ostream& strm, const grind_param& grind) {
std::ostream& operator<<(std::ostream& strm, const GrindParam& grind) {
strm << static_cast<size_t>(grind);
return strm;
}

std::istream& operator>>(std::istream& strm, grind_param& grind) {
std::istream& operator>>(std::istream& strm, GrindParam& grind) {
std::string str;
strm >> str;
std::size_t pos;
int val = std::stoi(str, &pos);
if (pos < str.size() || val < 0) {
strm.setstate(std::ios_base::failbit);
} else {
auto it = std::find(all_grind_params.cbegin(), all_grind_params.cend(), static_cast<grind_param>(val));
auto it = std::find(all_grind_params.cbegin(), all_grind_params.cend(), static_cast<GrindParam>(val));
if (it != all_grind_params.cend()) {
grind = val;
} else {
Expand Down Expand Up @@ -253,17 +253,17 @@ namespace nil {
std::istream& operator>>(std::istream& strm, VARIANT_TYPE& variant) { \
std::string str; \
strm >> str; \
auto l = [&str, &strm]() { \
auto l = [&str, &strm]() -> VARIANT_TYPE { \
STRING_TO_TYPE_LINES \
strm.setstate(std::ios_base::failbit); \
return std::variant_alternative_t<0, VARIANT_TYPE>(); \
return VARIANT_TYPE(); \
}; \
variant = l(); \
return strm; \
}
#define STRING_TO_TYPE(TYPE, NAME) \
if (NAME == str) \
return type_identity<TYPE> {};
return type_identity<TYPE>{};

#define CURVE_TYPES X(nil::crypto3::algebra::curves::pallas, "pallas")
#define X(type, name) TYPE_TO_STRING(type, name)
Expand Down
16 changes: 8 additions & 8 deletions bin/proof-generator/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ template<
std::size_t LambdaParamIdx,
typename HashType,
std::size_t GridParamIdx>
int run_prover(const nil::proof_generator::prover_options& prover_options) {
int run_prover(const nil::proof_generator::ProverOptions& prover_options) {
auto prover_task = [&] {
auto prover = nil::proof_generator::Prover<CurveType, HashType, ColumnsParamsIdx, LambdaParamIdx, GridParamIdx>(
prover_options.circuit_file_path,
Expand All @@ -63,7 +63,7 @@ int run_prover(const nil::proof_generator::prover_options& prover_options) {
// but this would lead to callback hell. Instead, we declare extra function for
// each factor. Last declared function starts the chain.
template<typename CurveType, std::size_t ColumnsParamsIdx, std::size_t LambdaParamIdx, typename HashType>
int grind_param_wrapper(const prover_options& prover_options) {
int grind_param_wrapper(const ProverOptions& prover_options) {
int ret;
auto run_prover_void = [&prover_options, &ret]<std::size_t GrindParamIdx>() {
ret = run_prover<CurveType, ColumnsParamsIdx, LambdaParamIdx, HashType, GrindParamIdx>(prover_options);
Expand All @@ -73,7 +73,7 @@ int grind_param_wrapper(const prover_options& prover_options) {
}

template<typename CurveType, std::size_t ColumnsParamsIdx, std::size_t LambdaParamIdx>
int hash_wrapper(const prover_options& prover_options) {
int hash_wrapper(const ProverOptions& prover_options) {
int ret;
auto run_prover_wrapper = [&prover_options, &ret]<typename HashTypeIdentity>() {
using HashType = typename HashTypeIdentity::type;
Expand All @@ -84,7 +84,7 @@ int hash_wrapper(const prover_options& prover_options) {
}

template<typename CurveType, std::size_t ColumnsParamsIdx>
int lambda_param_wrapper(const prover_options& prover_options) {
int lambda_param_wrapper(const ProverOptions& prover_options) {
int ret;
auto hash_wrapper_void = [&prover_options, &ret]<std::size_t LambdaParamIdx>() {
ret = hash_wrapper<CurveType, ColumnsParamsIdx, LambdaParamIdx>(prover_options);
Expand All @@ -94,7 +94,7 @@ int lambda_param_wrapper(const prover_options& prover_options) {
}

template<typename CurveType>
int columns_params_wrapper(const prover_options& prover_options) {
int columns_params_wrapper(const ProverOptions& prover_options) {
int ret;
auto columns_params_wrapper_void = [&prover_options, &ret]<std::size_t ColumnsParamsIdx>() {
ret = lambda_param_wrapper<CurveType, ColumnsParamsIdx>(prover_options);
Expand All @@ -106,7 +106,7 @@ int columns_params_wrapper(const prover_options& prover_options) {
return ret;
}

int curve_wrapper(const prover_options& prover_options) {
int curve_wrapper(const ProverOptions& prover_options) {
int ret;
auto curves_wrapper_void = [&prover_options, &ret]<typename CurveTypeIdentity>() {
using CurveType = typename CurveTypeIdentity::type;
Expand All @@ -116,12 +116,12 @@ int curve_wrapper(const prover_options& prover_options) {
return ret;
}

int initial_wrapper(const prover_options& prover_options) {
int initial_wrapper(const ProverOptions& prover_options) {
return curve_wrapper(prover_options);
}

int main(int argc, char* argv[]) {
std::optional<nil::proof_generator::prover_options> prover_options = nil::proof_generator::parse_args(argc, argv);
std::optional<nil::proof_generator::ProverOptions> prover_options = nil::proof_generator::parse_args(argc, argv);
if (!prover_options) {
// Action has already taken a place (help, version, etc.)
return 0;
Expand Down

0 comments on commit c975db4

Please sign in to comment.