Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature for fast multithreaded zkllvm #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,65 @@ namespace nil {
return v;
}

std::string add_filename_prefix(
const std::string& prefix,
const std::string& file_name
) {
boost::filesystem::path path(file_name);
boost::filesystem::path parent_path = path.parent_path();
boost::filesystem::path filename = path.filename();

std::string new_filename = prefix + filename.string();
boost::filesystem::path new_path = parent_path / new_filename;

return new_path.string();
}


bool read_column_to_vector (
std::vector<std::uint8_t>& result_vector,
const std::string& prefix,
const std::string& assignment_table_file_name

) {
std::ifstream icolumn;
icolumn.open(add_filename_prefix(prefix, assignment_table_file_name), std::ios_base::binary | std::ios_base::in);
if (!icolumn) {
BOOST_LOG_TRIVIAL(error) << "Error occurred during reading file " << add_filename_prefix(prefix, assignment_table_file_name);
return false;
}

icolumn.seekg(0, std::ios_base::end);
const auto input_size = icolumn.tellg();
std::size_t old_size = result_vector.size();
result_vector.resize(old_size + input_size);
icolumn.seekg(0, std::ios_base::beg);
icolumn.read(reinterpret_cast<char*>(result_vector.data() + old_size), input_size);
icolumn.close();
return true;
}


std::optional<std::vector<std::uint8_t>> read_table_file_to_vector(const std::string& path) {

std::vector<std::uint8_t> v;

if (
!(
read_column_to_vector(v, "header_", path) &&
read_column_to_vector(v, "witness_", path) &&
read_column_to_vector(v, "pub_inp_", path) &&
read_column_to_vector(v, "constants_", path) &&
read_column_to_vector(v, "selectors_", path)
)
) {
return std::nullopt;
}

return v;
}


bool write_vector_to_file(const std::vector<std::uint8_t>& vector, const std::string& path) {

auto file = open_file<std::ofstream>(path, std::ios_base::out | std::ios_base::binary);
Expand Down
22 changes: 21 additions & 1 deletion bin/proof-generator/include/nil/proof-generator/prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,26 @@ namespace nil {
return marshalled_data;
}


template<typename MarshallingType>
std::optional<MarshallingType> decode_table_from_file(
const boost::filesystem::path& path
) {
const auto v = read_table_file_to_vector(path.c_str());
if (!v.has_value()) {
return std::nullopt;
}

MarshallingType marshalled_data;
auto read_iter = v->begin();
auto status = marshalled_data.read(read_iter, v->size());
if (status != nil::marshalling::status_type::success) {
BOOST_LOG_TRIVIAL(error) << "Marshalled structure decoding failed";
return std::nullopt;
}
return marshalled_data;
}

template<typename MarshallingType>
bool encode_marshalling_to_file(
const boost::filesystem::path& path,
Expand Down Expand Up @@ -303,7 +323,7 @@ namespace nil {
using TableValueMarshalling =
nil::crypto3::marshalling::types::plonk_assignment_table<TTypeBase, AssignmentTable>;
auto marshalled_table =
detail::decode_marshalling_from_file<TableValueMarshalling>(assignment_table_file_);
detail::decode_table_from_file<TableValueMarshalling>(assignment_table_file_);
if (!marshalled_table) {
return false;
}
Expand Down