Skip to content

Commit

Permalink
Split trace files
Browse files Browse the repository at this point in the history
  • Loading branch information
makxenov committed Dec 10, 2024
1 parent c8a9301 commit c458ac8
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ namespace nil {
BOOST_LOG_TRIVIAL(error) << "Proof verification failed";
return false;
}

BOOST_LOG_TRIVIAL(info) << "Writing proof to " << proof_file_;
auto filled_placeholder_proof =
nil::crypto3::marshalling::types::fill_placeholder_proof<Endianness, Proof>(proof, lpc_scheme_->get_fri_params());
Expand Down Expand Up @@ -585,7 +585,7 @@ namespace nil {
return false;
}

writer::write_binary_circuit(out, *constraint_system_, constraint_system_->public_input_sizes());
writer::write_binary_circuit(out, *constraint_system_, constraint_system_->public_input_sizes());
return true;
}

Expand All @@ -604,7 +604,7 @@ namespace nil {
if (!marshalled_table) {
return false;
}

auto [table_description, assignment_table] =
nil::crypto3::marshalling::types::make_assignment_table<Endianness, AssignmentTable>(
*marshalled_table
Expand Down Expand Up @@ -634,7 +634,7 @@ namespace nil {
using writer = assignment_table_writer<Endianness, BlueprintField>;

BOOST_LOG_TRIVIAL(info) << "Writing binary assignment table to " << output_filename;

if (!assignment_table_.has_value() || !table_description_.has_value()) {
BOOST_LOG_TRIVIAL(error) << "No assignment table is currently loaded";
return false;
Expand Down Expand Up @@ -677,8 +677,8 @@ namespace nil {

const auto write = [&](std::ostream& out) -> bool {
return assignment_table_writer<Endianness, BlueprintField>::write_text_assignment(
out,
assignment_table_.value(),
out,
assignment_table_.value(),
table_description_.value(),
opts
);
Expand Down Expand Up @@ -1141,7 +1141,7 @@ namespace nil {
return assignment_table_.value();
}

bool fill_assignment_table(const boost::filesystem::path& trace_file_path) {
bool fill_assignment_table(const boost::filesystem::path& trace_base_path) {
if (!constraint_system_.has_value()) {
BOOST_LOG_TRIVIAL(error) << "Circuit is not initialized";
return false;
Expand All @@ -1150,9 +1150,9 @@ namespace nil {
BOOST_LOG_TRIVIAL(error) << "Assignment table is not initialized";
return false;
}
const auto err = fill_assignment_table_single_thread(*assignment_table_, *table_description_, circuit_name_, trace_file_path);
const auto err = fill_assignment_table_single_thread(*assignment_table_, *table_description_, circuit_name_, trace_base_path);
if (err) {
BOOST_LOG_TRIVIAL(error) << "Can't fill assignment table rom trace " << trace_file_path << ": " << err.value();
BOOST_LOG_TRIVIAL(error) << "Can't fill assignment table from trace " << trace_base_path << ": " << err.value();
return false;
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions proof-producer/bin/proof-producer/src/arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace nil {
("preprocessed-data", make_defaulted_option(prover_options.preprocessed_public_data_path), "Preprocessed public data file")
("commitment-state-file", make_defaulted_option(prover_options.commitment_scheme_state_path), "Commitment state data file")
("updated-commitment-state-file", make_defaulted_option(prover_options.updated_commitment_scheme_state_path), "Updated commitment state data file")
("trace", po::value(&prover_options.trace_file_path), "EVM trace input file")
("trace", po::value(&prover_options.trace_base_path), "Base path for EVM trace files")
("circuit", po::value(&prover_options.circuit_file_path), "Circuit input file")
("circuit-name", po::value(&prover_options.circuit_name), "Target circuit name")
("assignment-table,t", po::value(&prover_options.assignment_table_file_path), "Assignment table input file")
Expand Down Expand Up @@ -121,7 +121,7 @@ namespace nil {
("proof-of-work-file", make_defaulted_option(prover_options.proof_of_work_output_file), "File with proof of work.");

register_output_artifacts_cli_args(prover_options.output_artifacts, config);

// clang-format on
po::options_description cmdline_options("nil; Proof Producer");
cmdline_options.add(generic).add(config);
Expand Down
2 changes: 1 addition & 1 deletion proof-producer/bin/proof-producer/src/arg_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace nil {
boost::filesystem::path preprocessed_public_data_path = "preprocessed_data.dat";
boost::filesystem::path commitment_scheme_state_path = "commitment_scheme_state.dat";
boost::filesystem::path updated_commitment_scheme_state_path = "updated_commitment_scheme_state.dat";
boost::filesystem::path trace_file_path;
boost::filesystem::path trace_base_path;
boost::filesystem::path circuit_file_path;
boost::filesystem::path assignment_table_file_path;
boost::filesystem::path assignment_description_file_path;
Expand Down
4 changes: 2 additions & 2 deletions proof-producer/bin/proof-producer/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) {
}
break;
case nil::proof_generator::detail::ProverStage::ASSIGNMENT:
prover_result = prover.setup_prover() && prover.fill_assignment_table(prover_options.trace_file_path);
prover_result = prover.setup_prover() && prover.fill_assignment_table(prover_options.trace_base_path);
if (!prover_options.assignment_table_file_path.empty() && prover_result) {
prover_result = prover.save_binary_assignment_table_to_file(prover_options.assignment_table_file_path);
}
Expand Down Expand Up @@ -129,7 +129,7 @@ int run_prover(const nil::proof_generator::ProverOptions& prover_options) {
// Preset, fill assignment table, preprocess
prover_result =
prover.setup_prover() &&
prover.fill_assignment_table(prover_options.trace_file_path) &&
prover.fill_assignment_table(prover_options.trace_base_path) &&
prover.preprocess_public_data() &&
prover.save_preprocessed_common_data_to_file(prover_options.preprocessed_common_data_path) &&
prover.preprocess_private_data() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace nil {
template<typename BlueprintFieldType>
std::map<const std::string, std::function<std::optional<std::string>(
nil::crypto3::zk::snark::plonk_assignment_table<BlueprintFieldType>& assignment_table,
const boost::filesystem::path& trace_file_path)>> circuit_selector = {
const boost::filesystem::path& trace_base_path)>> circuit_selector = {
{circuits::BYTECODE, fill_bytecode_assignment_table<BlueprintFieldType>},
{circuits::RW, fill_rw_assignment_table<BlueprintFieldType>},
{circuits::ZKEVM, fill_zkevm_assignment_table<BlueprintFieldType>},
Expand Down Expand Up @@ -63,12 +63,12 @@ namespace nil {
std::optional<std::string> fill_assignment_table_single_thread(nil::crypto3::zk::snark::plonk_assignment_table<BlueprintFieldType>& assignment_table,
nil::crypto3::zk::snark::plonk_table_description<BlueprintFieldType>& desc,
const std::string& circuit_name,
const boost::filesystem::path& trace_file_path) {
const boost::filesystem::path& trace_base_path) {
auto find_it = circuit_selector<BlueprintFieldType>.find(circuit_name);
if (find_it == circuit_selector<BlueprintFieldType>.end()) {
return "Unknown circuit name " + circuit_name;
}
const auto err = find_it->second(assignment_table, trace_file_path);
const auto err = find_it->second(assignment_table, trace_base_path);
if (err) {
return err;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ namespace nil {
/// @brief Fill assignment table
template<typename BlueprintFieldType>
std::optional<std::string> fill_bytecode_assignment_table(nil::crypto3::zk::snark::plonk_assignment_table<BlueprintFieldType>& assignment_table,
const boost::filesystem::path& trace_file_path) {
BOOST_LOG_TRIVIAL(debug) << "fill bytecode table from " << trace_file_path << "\n";
const boost::filesystem::path& trace_base_path) {
BOOST_LOG_TRIVIAL(debug) << "fill bytecode table from " << trace_base_path << "\n";

using ComponentType = nil::blueprint::bbf::bytecode<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 contract_bytecodes = deserialize_bytecodes_from_file(trace_file_path);
const auto bytecode_trace_path = get_bytecode_trace_path(trace_base_path);
const auto contract_bytecodes = deserialize_bytecodes_from_file(bytecode_trace_path);
if (!contract_bytecodes) {
return "can't read bytecode trace from file";
return "can't read bytecode trace from file: " + bytecode_trace_path.string();
}

for (const auto& bytecode_it : contract_bytecodes.value()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,38 @@ namespace nil {
/// @brief Fill assignment table
template<typename BlueprintFieldType>
std::optional<std::string> fill_copy_events_assignment_table(nil::crypto3::zk::snark::plonk_assignment_table<BlueprintFieldType>& assignment_table,
const boost::filesystem::path& trace_file_path) {
BOOST_LOG_TRIVIAL(debug) << "fill copy table from " << trace_file_path << "\n";
const boost::filesystem::path& trace_base_path) {
BOOST_LOG_TRIVIAL(debug) << "fill copy table from " << trace_base_path << "\n";

using ComponentType = nil::blueprint::bbf::copy<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;
input.rlc_challenge = limits::RLC_CHALLENGE;

auto copy_events = deserialize_copy_events_from_file(trace_file_path);

const auto copy_trace_path = get_copy_trace_path(trace_base_path);
auto copy_events = deserialize_copy_events_from_file(copy_trace_path);
if (!copy_events) {
return "can't read copy events from file";
return "can't read copy events from file: " + copy_trace_path.string();
}
input.copy_events = std::move(copy_events.value());

const auto contract_bytecodes = deserialize_bytecodes_from_file(trace_file_path);
const auto bytecode_trace_path = get_bytecode_trace_path(trace_base_path);
const auto contract_bytecodes = deserialize_bytecodes_from_file(bytecode_trace_path);
if (!contract_bytecodes) {
return "can't read bytecode trace from file";
return "can't read bytecode trace from file: " + bytecode_trace_path.string();
}
for (const auto& bytecode_it : contract_bytecodes.value()) {
const auto raw_bytecode = string_to_bytes(bytecode_it.second);
input.bytecodes.new_buffer(raw_bytecode);
input.keccak_buffers.new_buffer(raw_bytecode);
}

const auto rw_operations = deserialize_rw_traces_from_file(trace_file_path);
const auto rw_trace_path = get_rw_trace_path(trace_base_path);
const auto rw_operations = deserialize_rw_traces_from_file(rw_trace_path);
if (!rw_operations) {
return "can't read rw operations trace from file";
return "can't read rw operations trace from file: " + rw_trace_path.string();
}
for (const auto& stack_op : rw_operations->stack_ops) {
input.rw_operations.push_back(stack_op);
Expand All @@ -62,11 +65,11 @@ namespace nil {

auto start = std::chrono::high_resolution_clock::now();
ComponentType instance(
context_object,
input,
limits::max_copy,
limits::max_rw_size,
limits::max_keccak_blocks,
context_object,
input,
limits::max_copy,
limits::max_rw_size,
limits::max_keccak_blocks,
limits::max_bytecode_size
);
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - start);
Expand All @@ -78,4 +81,3 @@ namespace nil {
} // nil

#endif // PROOF_GENERATOR_LIBS_ASSIGNER_COPY_HPP_

Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ namespace nil {
/// @brief Fill assignment table
template<typename BlueprintFieldType>
std::optional<std::string> fill_rw_assignment_table(nil::crypto3::zk::snark::plonk_assignment_table<BlueprintFieldType>& assignment_table,
const boost::filesystem::path& trace_file_path) {
BOOST_LOG_TRIVIAL(debug) << "fill rw table from " << trace_file_path << "\n";
const boost::filesystem::path& trace_base_path) {
BOOST_LOG_TRIVIAL(debug) << "fill rw table from " << trace_base_path << "\n";

using ComponentType = nil::blueprint::bbf::rw<BlueprintFieldType, nil::blueprint::bbf::GenerationStage::ASSIGNMENT>;

typename nil::blueprint::bbf::context<BlueprintFieldType, nil::blueprint::bbf::GenerationStage::ASSIGNMENT> context_object(assignment_table, limits::max_rows);

nil::blueprint::bbf::rw_operations_vector input;
const auto rw_operations = deserialize_rw_traces_from_file(trace_file_path);
const auto rw_trace_path = get_rw_trace_path(trace_base_path);
const auto rw_operations = deserialize_rw_traces_from_file(rw_trace_path);
if (!rw_operations) {
return "can't read rw from file";
return "can't read rw from file: " + rw_trace_path.string();
}
for (const auto& stack_op : rw_operations->stack_ops) {
input.push_back(stack_op);
Expand Down
Loading

0 comments on commit c458ac8

Please sign in to comment.