Skip to content

Commit ff45f40

Browse files
committed
Transpiler interface changed. Now it is more convinient to use it right after assigner.
1 parent e8f131e commit ff45f40

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

bin/transpiler/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ target_link_libraries(${CURRENT_PROJECT_NAME}
6666
crypto3::random
6767
crypto3::zk
6868

69+
crypto3::assigner
6970
crypto3::transpiler
7071

7172
marshalling::core

bin/transpiler/src/main.cpp

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <nil/crypto3/math/polynomial/polynomial.hpp>
3838
#include <nil/crypto3/math/algorithms/calculate_domain_set.hpp>
3939

40+
#include <nil/blueprint/asserts.hpp>
4041
#include <nil/blueprint/transpiler/minimized_profiling_plonk_circuit.hpp>
4142
#include <nil/blueprint/transpiler/public_input.hpp>
4243

@@ -222,11 +223,12 @@ int main(int argc, char *argv[]) {
222223
("mode,m", boost::program_options::value<std::string>(), "Transpiler mode (gen-test-proof, gen-gate-argument).\
223224
gen-test-proof prepares gate argument, placeholder params and sample proof for testing.\
224225
gen-gate-argument prepares gate argument and some placeholder params")
225-
("input-folder-path,i", boost::program_options::value<std::string>(), "Input folder absolute path")
226+
("public-input,i", boost::program_options::value<std::string>(), "Public input file")
227+
("assignment-table,t", boost::program_options::value<std::string>(), "Assignment table input file")
228+
("circuit,c", boost::program_options::value<std::string>(), "Circuit input file")
226229
("output-folder-path,o", boost::program_options::value<std::string>(), "Output folder absolute path.\
227230
It'll be better to create an empty folder for output")
228231
("optimize-gates", "Put multiple sequental small gates into one .sol file")
229-
("public-input-path,p", boost::program_options::value<std::string>(), "Public input file path")
230232
;
231233
// clang-format on
232234

@@ -241,9 +243,10 @@ int main(int argc, char *argv[]) {
241243
}
242244

243245
std::string mode;
244-
std::string input_folder_path;
246+
std::string assignment_table_file_name;
247+
std::string circuit_file_name;
245248
std::string output_folder_path;
246-
std::string public_input_path;
249+
std::string public_input;
247250

248251
if (vm.count("mode")) {
249252
mode = vm["mode"].as<std::string>();
@@ -259,10 +262,18 @@ int main(int argc, char *argv[]) {
259262
return 1;
260263
}
261264

262-
if (vm.count("input-folder-path")) {
263-
input_folder_path = vm["input-folder-path"].as<std::string>();
265+
if (vm.count("assignment-table")) {
266+
assignment_table_file_name = vm["assignment-table"].as<std::string>();
264267
} else {
265-
std::cerr << "Invalid command line argument - input folder path is not specified" << std::endl;
268+
std::cerr << "Invalid command line argument - assignment table file name is not specified" << std::endl;
269+
std::cout << options_desc << std::endl;
270+
return 1;
271+
}
272+
273+
if (vm.count("circuit")) {
274+
circuit_file_name = vm["circuit"].as<std::string>();
275+
} else {
276+
std::cerr << "Invalid command line argument - circuit file name is not specified" << std::endl;
266277
std::cout << options_desc << std::endl;
267278
return 1;
268279
}
@@ -280,21 +291,15 @@ int main(int argc, char *argv[]) {
280291
return 1;
281292
}
282293

283-
std::string ifile_path;
284-
std::string iassignment_path;
285-
286-
ifile_path = input_folder_path + "/circuit.crct";
287-
iassignment_path = input_folder_path + "/assignment.tbl";
288-
289294
std::ifstream ifile;
290-
ifile.open(ifile_path);
295+
ifile.open(circuit_file_name);
291296
if (!ifile.is_open()) {
292-
std::cout << "Cannot find input file " << ifile_path << std::endl;
297+
std::cout << "Cannot find input file " << circuit_file_name << std::endl;
293298
return 1;
294299
}
295300
std::vector<std::uint8_t> v;
296301
if (!read_buffer_from_file(ifile, v)) {
297-
std::cout << "Cannot parse input file " << ifile_path << std::endl;
302+
std::cout << "Cannot parse input file " << circuit_file_name << std::endl;
298303
return 1;
299304
}
300305
ifile.close();
@@ -320,16 +325,16 @@ int main(int argc, char *argv[]) {
320325
using ColumnsRotationsType = std::array<std::set<int>, ArithmetizationParams::total_columns>;
321326
using ProfilingType = nil::blueprint::minimized_profiling_plonk_circuit<BlueprintFieldType, ArithmetizationParams>;
322327

323-
if( vm.count("public-input-path") ){
324-
public_input_path = vm["public-input-path"].as<std::string>();
325-
if( !boost::filesystem::exists(public_input_path) ){
328+
if( vm.count("public-input") ){
329+
public_input = vm["public-input"].as<std::string>();
330+
if( !boost::filesystem::exists(public_input) ){
326331
std::cerr << "Invalid command line argument - public input file does not exist" << std::endl;
327332
return 1;
328333
}
329334

330335
std::ofstream pfile;
331336
pfile.open(output_folder_path+"/public_input.json");
332-
pfile << nil::blueprint::convert_numeric_public_input_to_json<BlueprintFieldType>(public_input_path);
337+
pfile << nil::blueprint::convert_numeric_public_input_to_json<BlueprintFieldType>(public_input);
333338
pfile.close();
334339
}
335340

@@ -346,9 +351,9 @@ int main(int argc, char *argv[]) {
346351
nil::crypto3::zk::snark::plonk_table<BlueprintFieldType, ArithmetizationParams, ColumnType>;
347352

348353
std::ifstream iassignment;
349-
iassignment.open(iassignment_path);
354+
iassignment.open(assignment_table_file_name);
350355
if (!iassignment) {
351-
std::cout << "Cannot open " << iassignment_path << std::endl;
356+
std::cout << "Cannot open " << assignment_table_file_name << std::endl;
352357
return 1;
353358
}
354359
TableAssignmentType assignment_table;
@@ -399,22 +404,19 @@ int main(int argc, char *argv[]) {
399404
public_preprocessed_data, private_preprocessed_data, table_description, constraint_system, assignment_table,
400405
fri_params);
401406

402-
bool verifier_res =
407+
bool verification_result =
403408
nil::crypto3::zk::snark::placeholder_verifier<BlueprintFieldType, placeholder_params>::process(
404409
public_preprocessed_data, proof, constraint_system, fri_params);
410+
405411

406-
if (verifier_res) {
407-
auto filled_placeholder_proof =
408-
nil::crypto3::marshalling::types::fill_placeholder_proof<Endianness, ProofType>(proof);
409-
proof_print<Endianness, ProofType>(proof, output_folder_path + "/proof.bin");
410-
std::cout << "Proof is verified" << std::endl;
411-
iassignment.close();
412-
return 0;
413-
} else {
414-
std::cout << "Proof is not verified" << std::endl;
415-
iassignment.close();
416-
return 1;
417-
}
412+
ASSERT_MSG(verification_result, "Proof is not verified" );
413+
414+
auto filled_placeholder_proof =
415+
nil::crypto3::marshalling::types::fill_placeholder_proof<Endianness, ProofType>(proof);
416+
proof_print<Endianness, ProofType>(proof, output_folder_path + "/proof.bin");
417+
std::cout << "Proof is verified" << std::endl;
418+
iassignment.close();
419+
return 0;
418420
}
419421

420422
return 0;

0 commit comments

Comments
 (0)