Skip to content

Commit

Permalink
Fixing the performance test. The same test is fixed in crypto3-zk ver…
Browse files Browse the repository at this point in the history
…sion.
  • Loading branch information
martun committed Oct 10, 2023
1 parent 9d56951 commit cfa3138
Show file tree
Hide file tree
Showing 14 changed files with 356 additions and 386 deletions.
2 changes: 1 addition & 1 deletion include/nil/actor/zk/commitments/polynomial/fri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace nil {
std::map<std::size_t, std::vector<PolynomialType>> gs;
gs[0]={g};
std::map<std::size_t, typename FRI::basic_fri::merkle_tree_type> trees;
trees[0] = typename FRI::basic_fri::merkle_tree_type(tree);;
trees[0] = typename FRI::basic_fri::merkle_tree_type(tree);
return proof_eval<FRI, PolynomialType>(gs, g, trees, tree, fri_params, transcript);
}

Expand Down
11 changes: 4 additions & 7 deletions include/nil/actor/zk/commitments/polynomial/kzg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,12 @@ namespace nil {
commitment_type commit;
scalar_value_type z;
scalar_value_type eval;
public_key_type() {}
public_key_type() = default;
public_key_type(commitment_type c, scalar_value_type z, scalar_value_type e)
: commit(c), z(z), eval(e) {}
public_key_type operator=(const public_key_type &other) {
eval = other.eval;
commit = other.commit;
z = other.z;
return *this;
}

public_key_type& operator=(const public_key_type &other) = default;

};
};
} // namespace commitments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ namespace nil {

#ifdef ZK_PLACEHOLDER_PROFILING_ENABLED
#define PROFILE_PLACEHOLDER_SCOPE(name) \
nil::actor::zk::nil::crypto3::zk::snark::detail::placeholder_scoped_profiler profiler(name);
nil::actor::zk::snark::detail::placeholder_scoped_profiler profiler(name);
#else
#define PROFILE_PLACEHOLDER_SCOPE(name)
#endif

#ifdef ZK_PLACEHOLDER_PROFILING_ENABLED
#define PROFILE_PLACEHOLDER_FUNCTION_CALLS() \
nil::actor::zk::nil::crypto3::zk::snark::detail::placeholder_scoped_aggregate_profiler profiler(__PRETTY_FUNCTION__ );
nil::actor::zk::snark::detail::placeholder_scoped_aggregate_profiler profiler(__PRETTY_FUNCTION__ );
#else
#define PROFILE_PLACEHOLDER_FUNCTION_CALLS()
#endif
Expand Down
19 changes: 10 additions & 9 deletions include/nil/actor/zk/snark/systems/plonk/placeholder/verifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,16 @@ namespace nil {
}

// 10. final check
std::array<typename FieldType::value_type, f_parts> F;
F[0] = permutation_argument[0];
F[1] = permutation_argument[1];
F[2] = permutation_argument[2];
F[3] = lookup_argument[0];
F[4] = lookup_argument[1];
F[5] = lookup_argument[2];
F[6] = lookup_argument[3];
F[7] = gate_argument[0];
std::array<typename FieldType::value_type, f_parts> F = {
permutation_argument[0],
permutation_argument[1],
permutation_argument[2],
lookup_argument[0],
lookup_argument[1],
lookup_argument[2],
lookup_argument[3],
gate_argument[0]
};

typename FieldType::value_type F_consolidated = FieldType::value_type::zero();
for (std::size_t i = 0; i < f_parts; i++) {
Expand Down
2 changes: 1 addition & 1 deletion test/commitment/fri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ACTOR_THREAD_TEST_CASE(fri_basic_test) {
constexpr static const std::size_t lambda = 40;
constexpr static const std::size_t batches_num = 1;

typedef zk::commitments::fri<FieldType, merkle_hash_type, transcript_hash_type, lambda, m, true> fri_type;
typedef zk::commitments::fri<FieldType, merkle_hash_type, transcript_hash_type, lambda, m, true /* use_grinding */> fri_type;

static_assert(zk::is_commitment<fri_type>::value);
static_assert(!zk::is_commitment<merkle_hash_type>::value);
Expand Down
47 changes: 47 additions & 0 deletions test/systems/plonk/placeholder/data/many_hashes/many_hashes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <nil/crypto3/hash/algorithm/hash.hpp>
#include <nil/crypto3/hash/poseidon.hpp>
#include <nil/crypto3/hash/sha2.hpp>

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

[[circuit]] typename hashes::sha2<256>::block_type poseidon_example1(
typename pallas::base_field_type::value_type b,
typename pallas::base_field_type::value_type c,
typename hashes::sha2<256>::block_type d,
typename hashes::sha2<256>::block_type e,
__zkllvm_field_curve25519_base f,
__zkllvm_field_curve25519_base g
) {
typename pallas::base_field_type::value_type poseidon_result = hash<hashes::poseidon>(b, c);
typename pallas::base_field_type::value_type poseidon_result2 = hash<hashes::poseidon>(c, b);
typename pallas::base_field_type::value_type poseidon_tmp;

typename hashes::sha2<256>::block_type sha2_result = hash<hashes::sha2<256>>(d, e);
typename hashes::sha2<256>::block_type sha2_result2 = hash<hashes::sha2<256>>(e, d);
typename hashes::sha2<256>::block_type sha2_tmp;

__zkllvm_field_curve25519_base curve_add;
__zkllvm_field_curve25519_base curve_mul;
__zkllvm_field_curve25519_base curve_sub;

for( int i = 0; i < 3; i++ ) {
curve_add = f+g;
curve_sub = f-g;
curve_mul = f*g;

f = curve_add;
g = curve_sub;

poseidon_tmp = hash<hashes::poseidon>(poseidon_result, poseidon_result2);
poseidon_result = poseidon_result2;
poseidon_result2 = poseidon_tmp;

sha2_tmp = hash<hashes::sha2<256>>(sha2_result, sha2_result2);
sha2_result = sha2_result2;
sha2_result2 = sha2_tmp;
}

return sha2_result2;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[
{"field": 0},
{"field": 1},
{"vector": [{"field": "85070591730234615865843651857942052864"}, {"field": "85070591730234615865843651857942052865"}]},
{"vector": [{"field": "85070591730234615865843651857942052866"}, {"field": "85070591730234615865843651857942052867"}]},
{"field": "999"},
{"field": "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"}
]

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <nil/crypto3/hash/algorithm/hash.hpp>
#include <nil/crypto3/hash/poseidon.hpp>

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

[[circuit]] typename pallas::base_field_type::value_type poseidon_example1(typename pallas::base_field_type::value_type b,
typename pallas::base_field_type::value_type c) {

typename pallas::base_field_type::value_type hash_result = hash<hashes::poseidon>(b, c);

return hash_result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"field": 0}, {"field": 1}]
Loading

0 comments on commit cfa3138

Please sign in to comment.