Skip to content

Commit 4ef7a68

Browse files
authored
Merge branch 'master' into 125-add-check-parameter-to-assigner
2 parents ba21e4f + a63b47d commit 4ef7a68

File tree

6 files changed

+66
-45
lines changed

6 files changed

+66
-45
lines changed

.github/workflows/build_linux.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,18 @@ jobs:
104104
run: |
105105
make -C build assigner clang transpiler -j$(nproc)
106106
107-
- name: Build examples
107+
- name: Build IR of the examples
108108
run: |
109109
make -C build circuit_examples -j$(nproc)
110110
ls -al ./build/examples
111111
112-
- name: Build circuits
112+
- name: Build circuit and assigner of the examples
113113
run: |
114-
make -C build run_examples -j$(nproc)
114+
make -C build assign_examples -j$(nproc)
115+
116+
- name: Build proof for the circuit of the examples
117+
run: |
118+
make -C build prove_examples -j$(nproc)
115119
116120
- name: Build rslang
117121
run: |

.github/workflows/build_macos.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,15 @@ jobs:
7676
run: |
7777
make -C build assigner clang transpiler -j$(sysctl -n hw.logicalcpu)
7878
79-
- name: Build examples
79+
- name: Build IR of the examples
8080
run: |
8181
make -C build circuit_examples -j$(sysctl -n hw.logicalcpu)
82+
ls -al ./build/examples
8283
83-
- name: Build circuits
84+
- name: Build circuit and assigner of the examples
8485
run: |
85-
make -C build run_examples -j$(sysctl -n hw.logicalcpu)
86+
make -C build assign_examples -j$(sysctl -n hw.logicalcpu)
87+
88+
- name: Build proof for the circuit of the examples
89+
run: |
90+
make -C build prove_examples -j$(sysctl -n hw.logicalcpu)

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;

examples/CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
add_custom_target(circuit_examples)
2-
add_custom_target(run_examples)
2+
add_custom_target(assign_examples)
3+
add_custom_target(prove_examples)
34

45
function(add_example example_target)
56
set(prefix ARG)
@@ -48,12 +49,20 @@ function(add_example example_target)
4849
else()
4950
set(binary_name ${example_target}.bc)
5051
endif()
51-
add_custom_target(${example_target}_run
52+
53+
add_custom_target(${example_target}_assign
5254
COMMAND $<TARGET_FILE:assigner> -b ${binary_name} -i ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_INPUT} -c circuit_${example_target}.crct -t assignment_${example_target}.tbl -e pallas --check
5355
DEPENDS ${example_target} ${ARG_INPUT} $<TARGET_FILE:assigner>
5456
COMMAND_EXPAND_LISTS
5557
VERBATIM)
56-
add_dependencies(run_examples ${example_target}_run)
58+
add_dependencies(assign_examples ${example_target}_assign)
59+
60+
add_custom_target(${example_target}_prove
61+
COMMAND $<TARGET_FILE:transpiler> -m gen-test-proof -i ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_INPUT} -c circuit_${example_target}.crct -t assignment_${example_target}.tbl -o .
62+
DEPENDS ${example_target} ${ARG_INPUT} $<TARGET_FILE:transpiler>
63+
COMMAND_EXPAND_LISTS
64+
VERBATIM)
65+
add_dependencies(prove_examples ${example_target}_prove)
5766
endfunction()
5867

5968
add_example(arithmetics_example SOURCES arithmetics.cpp INPUT arithmetics.inp)

0 commit comments

Comments
 (0)