Skip to content

Commit

Permalink
added tests for mnt curves #296
Browse files Browse the repository at this point in the history
  • Loading branch information
vo-nil committed Feb 25, 2024
1 parent b689bc5 commit 4a9c152
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/nil/crypto3/zk/commitments/polynomial/kzg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ namespace nil {
commit_g2(set_difference_polynom(_merged_points, this->_points.at(k)[i]))
);

left_side_accum *= left_side_pairing;
left_side_accum = left_side_accum * left_side_pairing;
factor *= gamma;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ namespace nil {
const std::size_t constant_columns = table_description.constant_columns;
const std::size_t selector_columns = table_description.selector_columns;

std::cout << "=========== VERIFIER::PROCESS START ================" << std::endl;

transcript::fiat_shamir_heuristic_sequential<transcript_hash_type> transcript(std::vector<std::uint8_t>({}));

transcript(preprocessed_public_data.common_data.vk.constraint_system_with_params_hash);
Expand Down Expand Up @@ -316,6 +318,7 @@ namespace nil {
std::map<std::size_t, typename commitment_scheme_type::commitment_type> commitments = proof.commitments;
commitments[FIXED_VALUES_BATCH] = preprocessed_public_data.common_data.commitments.fixed_values;
if (!commitment_scheme.verify_eval( proof.eval_proof.eval_proof, commitments, transcript )) {
std::cout << "commitment verify failed" << std::endl;
return false;
}

Expand Down Expand Up @@ -344,6 +347,7 @@ namespace nil {
// Z is polynomial -1, 0 ...., 0, 1
typename FieldType::value_type Z_at_challenge = preprocessed_public_data.common_data.Z.evaluate(challenge);
if (F_consolidated != Z_at_challenge * T_consolidated) {
std::cout << "Final evaluation failed" << std::endl;
return false;
}
return true;
Expand Down
15 changes: 15 additions & 0 deletions include/nil/crypto3/zk/transcript/fiat_shamir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ namespace nil {
}
};


template<typename Hash, typename Enable = void>
struct fiat_shamir_heuristic_sequential
{
Expand All @@ -139,6 +140,16 @@ namespace nil {
fiat_shamir_heuristic_sequential(const InputRange &r) : state(hash<hash_type>(r)) {
}

template<typename InputIterator>
static void dump_buffer(InputIterator first, InputIterator last)
{
std::cout << "updating transcript with [[[" << std::endl;
for(auto x = first; x!= last; ++x) {
std::cout << std::hex << std::setw(2) << std::setfill('0') << int(*x);
}
std::cout << std::endl << "]]]" << std::endl;
}

template<typename InputIterator>
fiat_shamir_heuristic_sequential(InputIterator first, InputIterator last) :
state(hash<hash_type>(first, last)) {
Expand All @@ -147,13 +158,15 @@ namespace nil {
template<typename InputRange>
void operator()(const InputRange &r) {
auto acc_convertible = hash<hash_type>(state);
dump_buffer(r.begin(), r.end());
state = accumulators::extract::hash<hash_type>(
hash<hash_type>(r, static_cast<accumulator_set<hash_type> &>(acc_convertible)));
}

template<typename InputIterator>
void operator()(InputIterator first, InputIterator last) {
auto acc_convertible = hash<hash_type>(state);
dump_buffer(first, last);
state = accumulators::extract::hash<hash_type>(
hash<hash_type>(first, last, static_cast<accumulator_set<hash_type> &>(acc_convertible)));
}
Expand All @@ -167,6 +180,7 @@ namespace nil {
nil::marshalling::status_type status;
nil::crypto3::multiprecision::cpp_int raw_result = nil::marshalling::pack(state, status);

std::cout << "transcript challenged for: " << std::hex << raw_result << std::endl;
return raw_result;
}

Expand All @@ -177,6 +191,7 @@ namespace nil {
nil::marshalling::status_type status;
Integral raw_result = nil::marshalling::pack(state, status);

std::cout << "transcript int_challenged for: " << std::hex << raw_result << std::endl;
return raw_result;
}

Expand Down
42 changes: 41 additions & 1 deletion test/systems/plonk/placeholder/placeholder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
// SOFTWARE.
//---------------------------------------------------------------------------//

#include "nil/crypto3/algebra/curves/alt_bn128.hpp"
#define BOOST_TEST_MODULE placeholder_test

#include <string>
Expand All @@ -46,6 +47,12 @@
#include <nil/crypto3/algebra/fields/arithmetic_params/vesta.hpp>
#include <nil/crypto3/algebra/random_element.hpp>

/*
#include <nil/crypto3/algebra/curves/alt_bn128.hpp>
#include <nil/crypto3/algebra/pairing/alt_bn128.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/alt_bn128.hpp>
*/

#include <nil/crypto3/algebra/curves/mnt4.hpp>
#include <nil/crypto3/algebra/pairing/mnt4.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/mnt4.hpp>
Expand Down Expand Up @@ -1288,6 +1295,7 @@ struct placeholder_kzg_test_fixture : public test_initializer {
kzg_preprocessed_public_data, kzg_proof, desc, constraint_system, kzg_scheme
);
test_initializer::teardown();
std::cout << "verifier_res: " << verifier_res << std::endl;
return verifier_res;
}

Expand All @@ -1311,7 +1319,39 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg)
constant_columns_t,
selector_columns_t,
usable_rows_t,
4, true>/*, -- Not yet implemented
4, true>
/*
, placeholder_kzg_test_fixture<
algebra::curves::alt_bn128_254,
hashes::keccak_1600<256>,
hashes::keccak_1600<256>,
witness_columns_t,
public_columns_t,
constant_columns_t,
selector_columns_t,
usable_rows_t,
4, true>*/
, placeholder_kzg_test_fixture<
algebra::curves::mnt4_298,
hashes::keccak_1600<256>,
hashes::keccak_1600<256>,
witness_columns_t,
public_columns_t,
constant_columns_t,
selector_columns_t,
usable_rows_t,
4, true>
, placeholder_kzg_test_fixture<
algebra::curves::mnt6_298,
hashes::keccak_1600<256>,
hashes::keccak_1600<256>,
witness_columns_t,
public_columns_t,
constant_columns_t,
selector_columns_t,
usable_rows_t,
4, true>
/*, -- Not yet implemented
placeholder_kzg_test_fixture<
algebra::curves::mnt6_298,
hashes::poseidon<nil::crypto3::hashes::detail::mina_poseidon_policy<algebra::curves::bls12<381>>>,
Expand Down

0 comments on commit 4a9c152

Please sign in to comment.