Skip to content

Commit ba21e4f

Browse files
committed
--check parameter added to assigner for satisfiability check. #125
1 parent 8b0f167 commit ba21e4f

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,20 @@ ${ZKLLVM_BUILD:-build}/bin/assigner/assigner -b ${ZKLLVM_BUILD:-build}/examples/
195195
make -C ${ZKLLVM_BUILD:-build} circuit_examples -j$(sysctl -n hw.logicalcpu)
196196
${ZKLLVM_BUILD:-build}/bin/assigner/assigner -b ${ZKLLVM_BUILD:-build}/examples/arithmetics_example.bc -i examples/arithmetics.inp -t assignment.tbl -c circuit.crct -e pallas
197197
```
198+
199+
### Validating the circuit
200+
201+
You can also run the `assigner` with `--check` flag to validate the satisfiability of the circuit. If the circuit is satisfiable, the `assigner` will output the satisfying assignment in the `assignment.tbl` file. If there is an error, the `assigner` will output the error message and throw an exception via `std::abort`.
202+
203+
#### Linux
204+
205+
```bash
206+
make -C ${ZKLLVM_BUILD:-build} circuit_examples -j$(nproc)
207+
${ZKLLVM_BUILD:-build}/bin/assigner/assigner -b ${ZKLLVM_BUILD:-build}/examples/arithmetics_example.bc -i examples/arithmetics.inp -t assignment.tbl -c circuit.crct -e pallas --check
208+
```
209+
210+
#### macOS
211+
```bash
212+
make -C ${ZKLLVM_BUILD:-build} circuit_examples -j$(sysctl -n hw.logicalcpu)
213+
${ZKLLVM_BUILD:-build}/bin/assigner/assigner -b ${ZKLLVM_BUILD:-build}/examples/arithmetics_example.bc -i examples/arithmetics.inp -t assignment.tbl -c circuit.crct -e pallas --check
214+
```

bin/assigner/src/main.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <nil/crypto3/marshalling/zk/types/plonk/constraint_system.hpp>
4949

5050
#include <nil/blueprint/parser.hpp>
51+
#include <nil/blueprint/asserts.hpp>
5152
#include <nil/blueprint/transpiler/table_profiling.hpp>
5253
#include <nil/blueprint/utils/satisfiability_check.hpp>
5354

@@ -86,7 +87,8 @@ template<typename CurveType>
8687
int curve_dependent_main(std::string bytecode_file_name,
8788
std::string public_input_file_name,
8889
std::string assignment_table_file_name,
89-
std::string circuit_file_name) {
90+
std::string circuit_file_name,
91+
bool check_validity) {
9092
using BlueprintFieldType = typename CurveType::base_field_type;
9193
constexpr std::size_t WitnessColumns = 15;
9294
constexpr std::size_t PublicInputColumns = 5;
@@ -163,7 +165,12 @@ int curve_dependent_main(std::string bytecode_file_name,
163165
print_circuit<nil::marshalling::option::big_endian, ConstraintSystemType>(parser_instance.bp, ocircuit);
164166
ocircuit.close();
165167

166-
return !nil::blueprint::is_satisfied(parser_instance.bp, parser_instance.assignmnt);
168+
if (check_validity){
169+
bool is_satisfied = nil::blueprint::is_satisfied(parser_instance.bp, parser_instance.assignmnt);
170+
ASSERT_MSG(is_satisfied, "The circuit is not satisfied" );
171+
}
172+
173+
return 0;
167174
}
168175

169176
int main(int argc, char *argv[]) {
@@ -177,7 +184,8 @@ int main(int argc, char *argv[]) {
177184
("public-input,i", boost::program_options::value<std::string>(), "Public input file")
178185
("assignment-table,t", boost::program_options::value<std::string>(), "Assignment table output file")
179186
("circuit,c", boost::program_options::value<std::string>(), "Circuit output file")
180-
("elliptic-curve-type,e", boost::program_options::value<std::string>(), "Native elliptic curve type (pallas, vesta, ed25519, bls12-381)");
187+
("elliptic-curve-type,e", boost::program_options::value<std::string>(), "Native elliptic curve type (pallas, vesta, ed25519, bls12-381)")
188+
("check", "Check satisfiability of the generated circuit");
181189
// clang-format on
182190

183191
boost::program_options::variables_map vm;
@@ -251,7 +259,7 @@ int main(int argc, char *argv[]) {
251259

252260
switch (curve_options[elliptic_curve]) {
253261
case 0: {
254-
return curve_dependent_main<typename algebra::curves::pallas>(bytecode_file_name, public_input_file_name, assignment_table_file_name, circuit_file_name);
262+
return curve_dependent_main<typename algebra::curves::pallas>(bytecode_file_name, public_input_file_name, assignment_table_file_name, circuit_file_name, vm.count("check"));
255263
break;
256264
}
257265
case 1: {

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function(add_example example_target)
4949
set(binary_name ${example_target}.bc)
5050
endif()
5151
add_custom_target(${example_target}_run
52-
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
52+
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
5353
DEPENDS ${example_target} ${ARG_INPUT} $<TARGET_FILE:assigner>
5454
COMMAND_EXPAND_LISTS
5555
VERBATIM)

0 commit comments

Comments
 (0)