NilFoundation / zkLLVM

Zero-Knowledge Proof Systems Circuit Compiler
https://docs.nil.foundation/zkllvm
292 stars 48 forks source link

[Possible bug] exit_check does not work correctly with multi prover #437

Closed CblPOK-git closed 10 months ago

CblPOK-git commented 10 months ago

When running code below with no --max-num-provers, assigner works successfully, all constraints are satisfied, but prover fails. If all __builtin_assigner_exit_check's are removed, then transpiler works succesfully. That means than __builtin_assigner_exit_check does not work correctly with multi prover.

code: #include <nil/crypto3/hash/algorithm/hash.hpp> #include <nil/crypto3/hash/poseidon.hpp>

using namespace nil::crypto3; using namespace nil::crypto3::algebra::curves;

bool check_root ( typename pallas::base_field_type::value_type expected_root, [[private_input]] std::array<typename pallas::base_field_type::value_type, 0x2> layer_0_leaves) {

typename pallas::base_field_type::value_type real_root = hash<hashes::poseidon>(layer_0_leaves[0], layer_0_leaves[1]);

bool res = (real_root == expected_root);

__builtin_assigner_exit_check(res); return res; }

[[circuit]] bool merkle_tree_poseidon ( typename pallas::base_field_type::value_type expected_root1, [[private_input]] std::array<typename pallas::base_field_type::value_type, 0x2> layer_0_leaves1, typename pallas::base_field_type::value_type expected_root2, [[private_input]] std::array<typename pallas::base_field_type::value_type, 0x2> layer_0_leaves2 ) {

bool res1 = check_root(expected_root1, layer_0_leaves1); __builtin_assigner_exit_check(res1);

bool res2;

#pragma zk_multi_prover 1 { res2 = check_root(expected_root2, layer_0_leaves2); __builtin_assigner_exit_check(res2); }

return res1 & res2; }

public input: [ {"field":"21913878639234629625182886224943457788656817334362361879028597155693549969111"}, {"field":"21913878639234629625182886224943457788656817334362361879028597155693549969111"} ]

private_input: [ {"array": [ {"field":1}, {"field":2} ]}, {"array": [ {"field":1}, {"field":2} ] } ]

akokoshn commented 10 months ago

The reason of issue - wrong setting next_prover when index of the next prover violate max-num-provers limitation. Quick fix: https://github.com/NilFoundation/zkllvm-assigner/commit/88100fcbc0d6dac2f7e12f9b3d46c89d90a4ce8b, on the dev branch https://github.com/NilFoundation/zkllvm-assigner/tree/fix-handling-max-num-provers-option.

Also issue should gone after remove next_prover at all: https://github.com/NilFoundation/zkLLVM/pull/429

akokoshn commented 10 months ago

Issue gone on the latest master of zkLLVM: https://github.com/NilFoundation/zkLLVM/commit/df8d73e0f06b3c034f5d3131a36c64f0647504a3

Manually check: