Skip to content

Commit cc19815

Browse files
authored
Added special selectors (switched on all usable rows and on non-first usable rows) #82 (#90)
1 parent 79ba233 commit cc19815

File tree

31 files changed

+866
-321
lines changed

31 files changed

+866
-321
lines changed

crypto3/libs/blueprint/include/nil/blueprint/blueprint/plonk/assignment.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ namespace nil {
152152
using ranges = std::vector<std::pair<std::size_t, std::size_t>>;
153153

154154
public:
155-
static constexpr const std::size_t private_storage_index = std::numeric_limits<std::size_t>::max();
156-
static constexpr const std::size_t batch_private_storage_index = std::numeric_limits<std::size_t>::max() - 1;
157-
static constexpr const std::size_t batch_constant_storage_index = std::numeric_limits<std::size_t>::max() - 2;
155+
static constexpr const std::size_t private_storage_index = std::numeric_limits<std::size_t>::max()-2;
156+
static constexpr const std::size_t batch_private_storage_index = std::numeric_limits<std::size_t>::max() - 3;
157+
static constexpr const std::size_t batch_constant_storage_index = std::numeric_limits<std::size_t>::max() - 4;
158158

159159
assignment(std::size_t witness_amount, std::size_t public_input_amount,
160160
std::size_t constant_amount, std::size_t selector_amount)

crypto3/libs/blueprint/test/verifiers/placeholder/verifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ void test_multiple_arithmetizations(std::string folder_name){
416416
BOOST_AUTO_TEST_SUITE(blueprint_pallas_test_suite)
417417

418418
BOOST_AUTO_TEST_CASE(basic_test) {
419+
// test_multiple_arithmetizations<default_zkllvm_params>("../libs/blueprint/test/verifiers/placeholder/data/merkle_tree_poseidon");
419420
test_multiple_arithmetizations<default_zkllvm_params>("../test/verifiers/placeholder/data/merkle_tree_poseidon");
420421
}
421422

crypto3/libs/marshalling/core/include/nil/marshalling/status_type.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ namespace nil {
9797
case status_type::error_status_amount:
9898
return "unreachable";
9999
}
100+
return "unreachable";
100101
}
101102
};
102103
} // namespace marshalling

crypto3/libs/marshalling/zk/test/detail/circuits.hpp

Lines changed: 216 additions & 104 deletions
Large diffs are not rendered by default.

crypto3/libs/marshalling/zk/test/placeholder_common_data.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,10 +782,7 @@ struct placeholder_kzg_test_fixture_v2 : public test_tools::random_test_initiali
782782

783783
using policy_type = zk::snark::detail::placeholder_policy<field_type, kzg_placeholder_params_type>;
784784

785-
using circuit_type =
786-
circuit_description<field_type,
787-
placeholder_circuit_params<field_type>,
788-
UsableRowsAmount>;
785+
using circuit_type = circuit_description<field_type, placeholder_circuit_params<field_type>>;
789786

790787
placeholder_kzg_test_fixture_v2()
791788
: desc(WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns)

crypto3/libs/marshalling/zk/test/placeholder_proof.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,7 @@ struct placeholder_kzg_test_fixture_v2 : public test_tools::random_test_initiali
12931293

12941294
using circuit_type =
12951295
circuit_description<field_type,
1296-
placeholder_circuit_params<field_type>,
1297-
usable_rows_amount>;
1296+
placeholder_circuit_params<field_type>>;
12981297

12991298
placeholder_kzg_test_fixture_v2()
13001299
: desc(WitnessColumns, PublicInputColumns, ConstantColumns, SelectorColumns)

crypto3/libs/marshalling/zk/test/plonk_constraint_system.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,69 @@ BOOST_FIXTURE_TEST_CASE(constraint_system_marshalling_test, test_tools::random_t
533533
test_constraint_system<Endianness, typename policy_type::constraint_system_type>(constraint_system);
534534
}
535535
BOOST_AUTO_TEST_SUITE_END()
536+
537+
BOOST_AUTO_TEST_SUITE(placeholder_circuit8)
538+
using Endianness = nil::marshalling::option::big_endian;
539+
using TTypeBase = nil::marshalling::field_type<Endianness>;
540+
using curve_type = algebra::curves::pallas;
541+
using field_type = typename curve_type::base_field_type;
542+
543+
constexpr static const std::size_t table_rows_log = 4;
544+
constexpr static const std::size_t table_rows = 1 << table_rows_log;
545+
constexpr static const std::size_t usable_rows = 14;
546+
547+
struct placeholder_test_params {
548+
using merkle_hash_type = hashes::keccak_1600<512>;
549+
using transcript_hash_type = hashes::keccak_1600<512>;
550+
551+
constexpr static const std::size_t witness_columns = witness_columns_8;
552+
constexpr static const std::size_t public_input_columns = public_columns_8;
553+
constexpr static const std::size_t constant_columns = constant_columns_8;
554+
constexpr static const std::size_t selector_columns = selector_columns_8;
555+
556+
constexpr static const std::size_t lambda = 40;
557+
constexpr static const std::size_t m = 2;
558+
};
559+
560+
using circuit_params = placeholder_circuit_params<field_type>;
561+
using transcript_type = typename transcript::fiat_shamir_heuristic_sequential<typename placeholder_test_params::transcript_hash_type>;
562+
using lpc_params_type = commitments::list_polynomial_commitment_params<
563+
typename placeholder_test_params::merkle_hash_type,
564+
typename placeholder_test_params::transcript_hash_type,
565+
placeholder_test_params::m
566+
>;
567+
568+
using lpc_type = commitments::list_polynomial_commitment<field_type, lpc_params_type>;
569+
using lpc_scheme_type = typename commitments::lpc_commitment_scheme<lpc_type>;
570+
using lpc_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params<circuit_params, lpc_scheme_type>;
571+
using policy_type = zk::snark::detail::placeholder_policy<field_type, circuit_params>;
572+
573+
BOOST_FIXTURE_TEST_CASE(constraint_system_marshalling_test, test_tools::random_test_initializer<field_type>) {
574+
auto circuit = circuit_test_8<field_type>(
575+
alg_random_engines.template get_alg_engine<field_type>(),
576+
generic_random_engine
577+
);
578+
plonk_table_description<field_type> desc(
579+
placeholder_test_params::witness_columns,
580+
placeholder_test_params::public_input_columns,
581+
placeholder_test_params::constant_columns,
582+
placeholder_test_params::selector_columns
583+
);
584+
585+
desc.rows_amount = circuit.table_rows;
586+
desc.usable_rows_amount = circuit.usable_rows;
587+
588+
typename policy_type::constraint_system_type constraint_system(
589+
circuit.gates,
590+
circuit.copy_constraints,
591+
circuit.lookup_gates,
592+
circuit.lookup_tables
593+
);
594+
typename policy_type::variable_assignment_type assignments = circuit.table;
595+
596+
if(has_argv("--print"))
597+
test_constraint_system<Endianness, typename policy_type::constraint_system_type>(constraint_system, "circuit7");
598+
else
599+
test_constraint_system<Endianness, typename policy_type::constraint_system_type>(constraint_system);
600+
}
601+
BOOST_AUTO_TEST_SUITE_END()

crypto3/libs/transpiler/include/nil/blueprint/transpiler/lpc_evm_verifier_gen.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,6 @@ namespace nil {
709709
"\t\t\tstate.l_shifted = addmod( state.l_shifted, mulmod(state.shifted_selector_value, mulmod( state.theta_acc, basic_marshalling.get_uint256_be(blob, " << _var_indices.at(shifted_var) * 0x20 << "), modulus), modulus), modulus);" << std::endl;
710710
lookup_str << "\t\t\tstate.theta_acc = mulmod(state.theta_acc, state.theta, modulus);" << std::endl;
711711
}
712-
lookup_str <<
713-
"\t\t\tl = mulmod( l, state.mask, modulus);" << std::endl;
714-
lookup_str <<
715-
"\t\t\tstate.l_shifted = mulmod( state.l_shifted, state.shifted_mask, modulus);" << std::endl;
716712
lookup_str << "\t\t\tstate.g = mulmod(state.g, addmod( state.factor, addmod(l, mulmod(state.beta, state.l_shifted, modulus), modulus), modulus), modulus);" << std::endl;
717713
j++;
718714
}

crypto3/libs/transpiler/include/nil/blueprint/transpiler/templates/modular_verifier.hpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,19 +205,6 @@ contract modular_verifier_$TEST_NAME$ is IModularVerifier{
205205
uint256 theta = transcript.get_field_challenge(tr_state, modulus);
206206
207207
state.F[7] = modular_gate_argument.verify(blob[table_offset:table_end_offset], theta);
208-
state.F[7] = mulmod(
209-
state.F[7],
210-
addmod(
211-
1,
212-
modulus - addmod(
213-
basic_marshalling.get_uint256_be(blob, special_selectors_offset),
214-
basic_marshalling.get_uint256_be(blob, special_selectors_offset + 0x40),
215-
modulus
216-
),
217-
modulus
218-
),
219-
modulus
220-
);
221208
// console.log("F[0] = ", state.F[0]);
222209
// console.log("F[1] = ", state.F[1]);
223210
// console.log("F[2] = ", state.F[2]);

crypto3/libs/zk/include/nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ namespace nil {
5050
namespace crypto3 {
5151
namespace zk {
5252
namespace snark {
53-
5453
/************************* PLONK constraint system ****************************/
54+
constexpr static std::size_t const PLONK_SPECIAL_SELECTOR_ALL_USABLE_ROWS_SELECTED = std::numeric_limits<std::size_t>::max();
55+
constexpr static std::size_t const PLONK_SPECIAL_SELECTOR_ALL_NON_FIRST_USABLE_ROWS_SELECTED = std::numeric_limits<std::size_t>::max() - 1; // Useful for lookup tables
5556

5657
template<typename FieldType>
5758
struct plonk_constraint_system {

0 commit comments

Comments
 (0)