-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(proof producer): add exp circuit
- Loading branch information
Showing
6 changed files
with
136 additions
and
7 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
50 changes: 50 additions & 0 deletions
50
proof-producer/libs/assigner/include/nil/proof-generator/assigner/exp.hpp
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,50 @@ | ||
#ifndef PROOF_GENERATOR_LIBS_ASSIGNER_EXP_HPP_ | ||
#define PROOF_GENERATOR_LIBS_ASSIGNER_EXP_HPP_ | ||
|
||
#include <optional> | ||
#include <boost/log/trivial.hpp> | ||
#include <boost/filesystem.hpp> | ||
#include <nil/crypto3/zk/snark/arithmetization/plonk/assignment.hpp> | ||
#include <nil/blueprint/zkevm_bbf/exp.hpp> | ||
#include <nil/proof-generator/assigner/options.hpp> | ||
#include <nil/proof-generator/assigner/trace_parser.hpp> | ||
#include <nil/proof-generator/preset/limits.hpp> | ||
|
||
|
||
namespace nil { | ||
namespace proof_generator { | ||
|
||
/// @brief Fill assignment table | ||
template<typename BlueprintFieldType> | ||
std::optional<std::string> fill_exp_assignment_table(nil::crypto3::zk::snark::plonk_assignment_table<BlueprintFieldType>& assignment_table, | ||
const boost::filesystem::path& trace_base_path, | ||
const AssignerOptions& options) { | ||
BOOST_LOG_TRIVIAL(debug) << "fill exp table from " << trace_base_path << "\n"; | ||
|
||
using ComponentType = nil::blueprint::bbf::exponentiation<BlueprintFieldType, nil::blueprint::bbf::GenerationStage::ASSIGNMENT>; | ||
|
||
typename nil::blueprint::bbf::context<BlueprintFieldType, nil::blueprint::bbf::GenerationStage::ASSIGNMENT> context_object(assignment_table, limits::max_rows); | ||
|
||
typename ComponentType::input_type input; | ||
|
||
|
||
const auto exp_trace_path = get_exp_trace_path(trace_base_path); | ||
const auto exp_operations = deserialize_exp_traces_from_file(exp_trace_path, options); | ||
if (!exp_operations) { | ||
return "can't read exp operations from file: " + exp_trace_path.string(); | ||
} | ||
input = std::move(exp_operations->value); | ||
|
||
ComponentType instance( | ||
context_object, | ||
input, | ||
limits::max_rows, | ||
limits::max_exp_rows | ||
); | ||
|
||
return {}; | ||
} | ||
} // proof_generator | ||
} // nil | ||
|
||
#endif // PROOF_GENERATOR_LIBS_ASSIGNER_EXP_HPP_ |
70 changes: 70 additions & 0 deletions
70
proof-producer/libs/preset/include/nil/proof-generator/preset/exp.hpp
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,70 @@ | ||
#ifndef PROOF_GENERATOR_LIBS_PRESET_EXP_HPP_ | ||
#define PROOF_GENERATOR_LIBS_PRESET_EXP_HPP_ | ||
|
||
#include <boost/log/core.hpp> | ||
#include <boost/log/expressions.hpp> | ||
#include <boost/log/trivial.hpp> | ||
#include <nil/blueprint/bbf/enums.hpp> | ||
#include <nil/blueprint/blueprint/plonk/circuit.hpp> | ||
#include <nil/crypto3/zk/snark/arithmetization/plonk/assignment.hpp> | ||
#include <nil/proof-generator/preset/limits.hpp> | ||
#include <nil/blueprint/zkevm_bbf/exp.hpp> | ||
#include <nil/blueprint/bbf/l1_wrapper.hpp> | ||
#include <optional> | ||
#include <string> | ||
|
||
|
||
namespace nil { | ||
namespace proof_generator { | ||
template<typename BlueprintFieldType> | ||
std::optional<std::string> initialize_exp_circuit( | ||
std::optional<blueprint::circuit<nil::crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>>>& exp_circuit, | ||
std::optional<nil::crypto3::zk::snark::plonk_assignment_table<BlueprintFieldType>>& exp_table) { | ||
|
||
using ComponentType = nil::blueprint::bbf::exponentiation<BlueprintFieldType, nil::blueprint::bbf::GenerationStage::CONSTRAINTS>; | ||
|
||
// initialize assignment table | ||
const auto desc = ComponentType::get_table_description(limits::max_rows, limits::max_exp_rows); | ||
exp_table.emplace(desc.witness_columns, desc.public_input_columns, desc.constant_columns, desc.selector_columns); | ||
BOOST_LOG_TRIVIAL(debug) << "exp table:\n" | ||
<< "witnesses = " << exp_table->witnesses_amount() | ||
<< " public inputs = " << exp_table->public_inputs_amount() | ||
<< " constants = " << exp_table->constants_amount() | ||
<< " selectors = " << exp_table->selectors_amount() << "\n"; | ||
|
||
std::size_t start_row = 0; | ||
std::vector<std::size_t> witnesses(desc.witness_columns); | ||
std::iota(witnesses.begin(), witnesses.end(), 0); // fill 0, 1, ... | ||
std::vector<std::size_t> public_inputs(desc.public_input_columns); | ||
std::iota(public_inputs.begin(), public_inputs.end(), 0); // fill 0, 1, ... | ||
std::vector<std::size_t> constants(desc.constant_columns); | ||
std::iota(constants.begin(), constants.end(), 0); // fill 0, 1, ... | ||
|
||
using L1WrapperType = nil::blueprint::components::plonk_l1_wrapper<BlueprintFieldType, | ||
nil::blueprint::bbf::exponentiation, std::size_t, std::size_t>; | ||
L1WrapperType wrapper(witnesses, public_inputs, constants); | ||
|
||
typename ComponentType::input_type input; | ||
|
||
nil::blueprint::circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType>> circuit; | ||
|
||
nil::blueprint::components::generate_circuit<BlueprintFieldType, nil::blueprint::bbf::exponentiation, std::size_t, std::size_t>( | ||
wrapper, circuit, *exp_table, input, start_row, | ||
limits::max_rows, limits::max_exp_rows); | ||
|
||
zk::snark::pack_lookup_tables_horizontal( | ||
circuit.get_reserved_indices(), | ||
circuit.get_reserved_tables(), | ||
circuit.get_reserved_dynamic_tables(), | ||
circuit, *exp_table, | ||
exp_table->rows_amount(), | ||
100000 | ||
); | ||
|
||
exp_circuit.emplace(circuit); | ||
|
||
return {}; | ||
} | ||
} // proof_generator | ||
} // nil | ||
#endif // PROOF_GENERATOR_LIBS_PRESET_EXP_HPP_ |
7 changes: 4 additions & 3 deletions
7
proof-producer/libs/preset/include/nil/proof-generator/preset/limits.hpp
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