Skip to content

Commit

Permalink
Tests are now working #46
Browse files Browse the repository at this point in the history
  • Loading branch information
vo-nil committed Dec 7, 2023
1 parent ca554d1 commit cb90f7f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion include/nil/blueprint/transpiler/evm_verifier_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,10 +859,10 @@ namespace nil {
eta_hash::digest_type hash_result = crypto3::hash<eta_hash>(eta_buf);
result << "\t\t\t/* Check keccak(points) */" << std::endl;
result << "\t\t\tif ( bytes32(0x" << std::to_string(hash_result).data() << ") != keccak256(abi.encode(points))) {" << std::endl;
// result << "\t\t\t\temit WrongEtaPointValues();" << std::endl;
result << "\t\t\t\treturn false;" << std::endl;
result << "\t\t\t}" << std::endl;
result << "\t\t}" << std::endl;

return result.str();
}

Expand Down
18 changes: 9 additions & 9 deletions test/detail/circuits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ namespace nil {
template<typename FieldType>
circuit_description<FieldType, placeholder_circuit_params<FieldType, arithmetization_params_t>, 5, 4>
circuit_test_t(
typename FieldType::value_type pi0 = 0,
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
boost::random::mt11213b rnd = boost::random::mt11213b()
typename FieldType::value_type pi0,// = 0,
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd, //= nil::crypto3::random::algebraic_engine<FieldType>(),
boost::random::mt11213b rnd// = boost::random::mt11213b()
) {
using assignment_type = typename FieldType::value_type;

Expand All @@ -268,16 +268,16 @@ namespace nil {

// init values
typename FieldType::value_type one = FieldType::value_type::one();
table[0][0] = algebra::random_element<FieldType>();
table[1][0] = algebra::random_element<FieldType>();
table[2][0] = algebra::random_element<FieldType>();
table[0][0] = alg_rnd();
table[1][0] = alg_rnd();
table[2][0] = alg_rnd();
table[3][0] = pi0;
q_add[0] = FieldType::value_type::zero();
q_mul[0] = FieldType::value_type::zero();

// fill rows with ADD gate
for (std::size_t i = 1; i < 3; i++) {
table[0][i] = algebra::random_element<FieldType>();
table[0][i] = alg_rnd();
table[1][i] = table[2][i - 1];
table[2][i] = table[0][i] + table[1][i];
table[3][i] = FieldType::value_type::zero();
Expand All @@ -293,7 +293,7 @@ namespace nil {

// fill rows with MUL gate
for (std::size_t i = 3; i < 5; i++) {
table[0][i] = algebra::random_element<FieldType>();
table[0][i] = alg_rnd();
table[1][i] = table[3][0];
table[2][i] = table[0][i] * table[1][i] + table[0][i - 1];
table[3][i] = FieldType::value_type::zero();
Expand Down Expand Up @@ -357,7 +357,7 @@ namespace nil {

std::vector<plonk_constraint<FieldType>> mul_gate_costraints {mul_constraint};
plonk_gate<FieldType, plonk_constraint<FieldType>> mul_gate(1, mul_gate_costraints);
//test_circuit.gates.push_back(mul_gate);
test_circuit.gates.push_back(mul_gate);

return test_circuit;
}
Expand Down
32 changes: 22 additions & 10 deletions test/transpiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ typename fri_type::params_type create_fri_params(std::size_t degree_log, const i

return params;
}

// *******************************************************************************
// * Randomness setup
// *******************************************************************************/
Expand All @@ -132,7 +133,7 @@ nil::crypto3::random::algebraic_engine<FieldType> test_global_alg_rnd_engine;
struct test_initializer {
// Enumerate all fields used in tests;
using field1_type = algebra::curves::pallas::base_field_type;

using field2_type = algebra::curves::bls12<381>::scalar_field_type;
test_initializer() {
test_global_seed = 0;

Expand All @@ -155,6 +156,7 @@ struct test_initializer {
BOOST_TEST_MESSAGE("test_global_seed = " << test_global_seed);
test_global_rnd_engine = boost::random::mt11213b(test_global_seed);
test_global_alg_rnd_engine<field1_type> = nil::crypto3::random::algebraic_engine<field1_type>(test_global_seed);
test_global_alg_rnd_engine<field2_type> = nil::crypto3::random::algebraic_engine<field2_type>(test_global_seed);
}

void setup() {
Expand All @@ -176,7 +178,6 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit1)
using merkle_hash_type = hashes::keccak_1600<256>;
using transcript_hash_type = hashes::keccak_1600<256>;
constexpr static const std::size_t table_rows_log = 4;
constexpr static const std::size_t table_rows = 1 << table_rows_log;

struct placeholder_test_params {
constexpr static const std::size_t table_rows = 1 << table_rows_log;
Expand All @@ -192,7 +193,7 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit1)
using arithmetization_params =
plonk_arithmetization_params<witness_columns, public_input_columns, constant_columns, selector_columns>;

constexpr static const std::size_t lambda = 1;
constexpr static const std::size_t lambda = 40;
constexpr static const std::size_t m = 2;
};
typedef placeholder_circuit_params<field_type, typename placeholder_test_params::arithmetization_params> circuit_params;
Expand All @@ -207,16 +208,17 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit1)
crypto3::zk::commitments::proof_of_work<transcript_hash_type, std::uint32_t, 0xFFFF8000 >
>;


using lpc_type = commitments::list_polynomial_commitment<field_type, lpc_params_type>;
using lpc_scheme_type = typename commitments::lpc_commitment_scheme<lpc_type>;
using lpc_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params<circuit_params, lpc_scheme_type>;
using policy_type = zk::snark::detail::placeholder_policy<field_type, lpc_placeholder_params_type>;

BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) {
auto circuit = circuit_test_1<field_type>(test_global_alg_rnd_engine<field_type>);

plonk_table_description<field_type, typename circuit_params::arithmetization_params> desc;

desc.rows_amount = table_rows;
desc.rows_amount = placeholder_test_params::table_rows;
desc.usable_rows_amount = placeholder_test_params::usable_rows;

typename policy_type::constraint_system_type constraint_system(
Expand All @@ -227,7 +229,6 @@ BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) {
);
typename policy_type::variable_assignment_type assignments = circuit.table;


std::vector<std::size_t> columns_with_copy_constraints = {0, 1, 2, 3};


Expand Down Expand Up @@ -261,7 +262,7 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit2)
using curve_type = algebra::curves::bls12<381>;
using field_type = typename curve_type::scalar_field_type;

constexpr static const std::size_t table_rows_log = 4;
constexpr static const std::size_t table_rows_log = 3;
constexpr static const std::size_t table_rows = 1 << table_rows_log;
constexpr static const std::size_t permutation_size = 4;
constexpr static const std::size_t usable_rows = (1 << table_rows_log) - 3;
Expand Down Expand Up @@ -300,6 +301,7 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit2)
using lpc_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params<circuit_t_params, lpc_scheme_type>;

using policy_type = zk::snark::detail::placeholder_policy<field_type, circuit_t_params>;

BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) {
auto pi0 = test_global_alg_rnd_engine<field_type>();
auto circuit = circuit_test_t<field_type>(pi0, test_global_alg_rnd_engine<field_type>, test_global_rnd_engine);
Expand All @@ -316,7 +318,7 @@ BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) {
);
typename policy_type::variable_assignment_type assignments = circuit.table;

std::vector<std::size_t> columns_with_copy_constraints = {0, 1, 2, 3};
std::vector<std::size_t> columns_with_copy_constraints = {0, 1, 2, 3};

bool verifier_res;

Expand Down Expand Up @@ -384,8 +386,10 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit3)
using lpc_scheme_type = typename commitments::lpc_commitment_scheme<lpc_type>;
using lpc_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params<circuit_params, lpc_scheme_type>;
using policy_type = zk::snark::detail::placeholder_policy<field_type, circuit_params>;

BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) {
auto circuit = circuit_test_3<field_type>();
auto circuit = circuit_test_3<field_type>(test_global_alg_rnd_engine<field_type>, test_global_rnd_engine);

plonk_table_description<field_type, typename circuit_params::arithmetization_params> desc;

desc.rows_amount = table_rows;
Expand Down Expand Up @@ -461,10 +465,12 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit4)
using lpc_scheme_type = typename commitments::lpc_commitment_scheme<lpc_type>;
using lpc_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params<circuit_params, lpc_scheme_type>;
using policy_type = zk::snark::detail::placeholder_policy<field_type, circuit_params>;

BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) {
auto circuit = circuit_test_4<field_type>(test_global_alg_rnd_engine<field_type>, test_global_rnd_engine);
auto circuit = circuit_test_4<field_type>(test_global_alg_rnd_engine<field_type>);

plonk_table_description<field_type, typename circuit_params::arithmetization_params> desc;

desc.rows_amount = table_rows;
desc.usable_rows_amount = usable_rows;

Expand Down Expand Up @@ -540,10 +546,12 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit6)
using lpc_scheme_type = typename commitments::lpc_commitment_scheme<lpc_type>;
using lpc_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params<circuit_params, lpc_scheme_type>;
using policy_type = zk::snark::detail::placeholder_policy<field_type, circuit_params>;

BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) {
auto circuit = circuit_test_6<field_type>(test_global_alg_rnd_engine<field_type>, test_global_rnd_engine);

plonk_table_description<field_type, typename circuit_params::arithmetization_params> desc;

desc.rows_amount = table_rows;
desc.usable_rows_amount = usable_rows;

Expand All @@ -563,6 +571,7 @@ BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) {
typename placeholder_public_preprocessor<field_type, lpc_placeholder_params_type>::preprocessed_data_type
preprocessed_public_data = placeholder_public_preprocessor<field_type, lpc_placeholder_params_type>::process(
constraint_system, assignments.public_table(), desc, lpc_scheme, columns_with_copy_constraints.size());

auto printer = nil::blueprint::evm_verifier_printer<lpc_placeholder_params_type>(
constraint_system,
preprocessed_public_data.common_data,
Expand Down Expand Up @@ -619,6 +628,7 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit7)
using lpc_scheme_type = typename commitments::lpc_commitment_scheme<lpc_type>;
using lpc_placeholder_params_type = nil::crypto3::zk::snark::placeholder_params<circuit_params, lpc_scheme_type>;
using policy_type = zk::snark::detail::placeholder_policy<field_type, circuit_params>;

BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) {
auto circuit = circuit_test_7<field_type>(test_global_alg_rnd_engine<field_type>, test_global_rnd_engine);
plonk_table_description<field_type, typename circuit_params::arithmetization_params> desc;
Expand All @@ -639,6 +649,7 @@ BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) {
lpc_scheme_type lpc_scheme(fri_params);

std::vector<std::size_t> columns_with_copy_constraints = {0, 1, 2, 3};

transcript_type transcript;

typename placeholder_public_preprocessor<field_type, lpc_placeholder_params_type>::preprocessed_data_type
Expand All @@ -660,6 +671,7 @@ BOOST_FIXTURE_TEST_CASE(transpiler_test, test_initializer) {
printer.print();
}
BOOST_AUTO_TEST_SUITE_END()

#if 0
BOOST_AUTO_TEST_SUITE(recursive_circuit1)
using Endianness = nil::marshalling::option::big_endian;
Expand Down

0 comments on commit cb90f7f

Please sign in to comment.