Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 7e6b8f5

Browse files
authored
Merge pull request #49 from NilFoundation/47-zkllvm-compatibility
47 zkllvm compatibility
2 parents 38efda0 + 05ccd49 commit 7e6b8f5

File tree

3 files changed

+93
-55
lines changed

3 files changed

+93
-55
lines changed

include/nil/crypto3/marshalling/zk/types/commitments/eval_storage.hpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,23 @@ namespace nil {
5656
std::tuple<
5757
// batch_info.
5858
// We'll check is it good for current EVM instance
59+
// All z-s are placed into plain array
5960
nil::marshalling::types::array_list<
6061
TTypeBase,
61-
nil::marshalling::types::integral<TTypeBase, uint8_t>,
62+
field_element<TTypeBase, typename FieldType::value_type>,
6263
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<TTypeBase, std::size_t>>
6364
>,
6465

65-
// evaluation_points_num.
6666
nil::marshalling::types::array_list<
6767
TTypeBase,
6868
nil::marshalling::types::integral<TTypeBase, uint8_t>,
6969
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<TTypeBase, std::size_t>>
7070
>,
7171

72-
// All z-s are placed into plain array
72+
// evaluation_points_num.
7373
nil::marshalling::types::array_list<
7474
TTypeBase,
75-
field_element<TTypeBase, typename FieldType::value_type>,
75+
nil::marshalling::types::integral<TTypeBase, uint8_t>,
7676
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<TTypeBase, std::size_t>>
7777
>
7878
>
@@ -125,7 +125,7 @@ namespace nil {
125125
> filled_z = fill_field_element_vector<typename FieldType::value_type, Endianness>(z_val);
126126

127127
return eval_storage<TTypeBase, FieldType>(
128-
std::tuple( filled_batch_info, filled_eval_points_num, filled_z)
128+
std::tuple( filled_z, filled_batch_info, filled_eval_points_num )
129129
);
130130
}
131131

@@ -139,13 +139,13 @@ namespace nil {
139139
typename nil::crypto3::marshalling::types::batch_info_type batch_info;
140140
std::vector<std::uint8_t> eval_points_num;
141141

142-
auto filled_batch_info = std::get<0>(filled_storage.value()).value();
142+
auto filled_batch_info = std::get<1>(filled_storage.value()).value();
143143
for( std::size_t i = 0; i < filled_batch_info.size(); i+=2 ){
144144
batch_info[filled_batch_info[i].value()] = filled_batch_info[i+1].value();
145145
z.set_batch_size(filled_batch_info[i].value(), filled_batch_info[i+1].value());
146146
}
147147

148-
auto filled_eval_points_num = std::get<1>(filled_storage.value()).value();
148+
auto filled_eval_points_num = std::get<2>(filled_storage.value()).value();
149149
std::size_t cur = 0;
150150
for( const auto &it:batch_info){
151151
for( std::size_t i = 0; i < it.second; i++ ){
@@ -154,7 +154,7 @@ namespace nil {
154154
}
155155
}
156156

157-
auto filled_z = std::get<2>(filled_storage.value()).value();
157+
auto filled_z = std::get<0>(filled_storage.value()).value();
158158
cur = 0;
159159
for( const auto &it:batch_info){
160160
for( std::size_t i = 0; i < it.second; i++ ){

test/detail/circuits.hpp

+33-21
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626
// SOFTWARE.
2727
//---------------------------------------------------------------------------//
2828

29-
#ifndef CRYPTO3_ZK_MARSHALLING_TEST_PLONK_CIRCUITS_HPP
30-
#define CRYPTO3_ZK_MARSHALLING_TEST_PLONK_CIRCUITS_HPP
31-
32-
#define _RND_ algebra::random_element<FieldType>();
29+
#ifndef MARSHALLING_ZK_TEST_PLONK_CIRCUITS_HPP
30+
#define MARSHALLING_ZK_TEST_PLONK_CIRCUITS_HPP
3331

3432
#include <nil/crypto3/algebra/random_element.hpp>
3533

@@ -105,7 +103,8 @@ namespace nil {
105103

106104
template<typename FieldType>
107105
circuit_description<FieldType, placeholder_circuit_params<FieldType, arithmetization_params_1>, 4, 4> circuit_test_1(
108-
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>()
106+
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
107+
boost::random::mt11213b rnd = boost::random::mt11213b()
109108
) {
110109
using assignment_type = typename FieldType::value_type;
111110

@@ -242,7 +241,11 @@ namespace nil {
242241

243242
template<typename FieldType>
244243
circuit_description<FieldType, placeholder_circuit_params<FieldType, arithmetization_params_t>, 4, 4>
245-
circuit_test_t(typename FieldType::value_type pi0 = FieldType::value_type::zero()) {
244+
circuit_test_t(
245+
typename FieldType::value_type pi0 = 0,
246+
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
247+
boost::random::mt11213b rnd = boost::random::mt11213b()
248+
) {
246249
using assignment_type = typename FieldType::value_type;
247250

248251
constexpr static const std::size_t rows_log = 4;
@@ -372,7 +375,10 @@ namespace nil {
372375
public_columns_3, constant_columns_3, selector_columns_3>;
373376

374377
template<typename FieldType>
375-
circuit_description<FieldType, placeholder_circuit_params<FieldType, arithmetization_params_3>, 3, 3> circuit_test_3() {
378+
circuit_description<FieldType, placeholder_circuit_params<FieldType, arithmetization_params_3>, 3, 3> circuit_test_3(
379+
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
380+
boost::random::mt11213b rnd = boost::random::mt11213b()
381+
) {
376382
using assignment_type = typename FieldType::value_type;
377383
using field_type = typename FieldType::value_type;
378384

@@ -489,7 +495,10 @@ namespace nil {
489495

490496
template<typename FieldType>
491497
circuit_description<FieldType, placeholder_circuit_params<FieldType,
492-
arithmetization_params_4>, 3, 3> circuit_test_4() {
498+
arithmetization_params_4>, 3, 3> circuit_test_4(
499+
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
500+
boost::random::mt11213b rnd = boost::random::mt11213b()
501+
) {
493502
using assignment_type = typename FieldType::value_type;
494503

495504
constexpr static const std::size_t rows_log = 3;
@@ -511,12 +520,11 @@ namespace nil {
511520
table[j].resize(test_circuit.table_rows);
512521
}
513522

514-
srand(time(NULL));
515523
// lookup inputs
516524
typename FieldType::value_type one = FieldType::value_type::one();
517525
typename FieldType::value_type zero = FieldType::value_type::zero();
518-
table[0] = {rand() % 2, rand() % 2, rand(), rand() % 2, rand() % 2, 0, 0, 0};
519-
table[1] = {rand() % 2, rand() % 2, rand(), rand() % 2, rand() % 2, 0, 0, 0};;
526+
table[0] = {rnd() % 2, rnd() % 2, rnd(), rnd() % 2, rnd() % 2, 0, 0, 0};
527+
table[1] = {rnd() % 2, rnd() % 2, rnd(), rnd() % 2, rnd() % 2, 0, 0, 0};;
520528
table[2] = {table[0][0] * table[1][0], table[0][1] * table[1][1], table[0][2] * table[1][2], table[0][3] * table[1][3], table[0][4] * table[1][4], 0, 0, 0};
521529

522530

@@ -883,7 +891,10 @@ namespace nil {
883891

884892
template<typename FieldType>
885893
circuit_description<FieldType, placeholder_circuit_params<FieldType,
886-
arithmetization_params_6>, 3, 3> circuit_test_6() {
894+
arithmetization_params_6>, 3, 3> circuit_test_6(
895+
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
896+
boost::random::mt11213b rnd = boost::random::mt11213b()
897+
) {
887898
using assignment_type = typename FieldType::value_type;
888899

889900
constexpr static const std::size_t rows_log = 3;
@@ -905,11 +916,10 @@ namespace nil {
905916
table[j].resize(test_circuit.table_rows);
906917
}
907918

908-
srand(time(NULL));
909919
// lookup inputs
910920
typename FieldType::value_type one = FieldType::value_type::one();
911921
typename FieldType::value_type zero = FieldType::value_type::zero();
912-
table[0] = {rand() % 5 + 2, rand() % 5 + 2, rand() % 5 + 2, rand() % 5 + 2, rand() % 5 + 2, rand() % 5 + 2, 0, 0};
922+
table[0] = {rnd() % 5 + 2, rnd() % 5 + 2, rnd() % 5 + 2, rnd() % 5 + 2, rnd() % 5 + 2, rnd() % 5 + 2, 0, 0};
913923
table[1] = {7, table[0][0] + table[0][1], table[0][1] + table[0][2], table[0][2] + table[0][3], table[0][3] + table[0][4], table[0][4] + table[0][5], 0, 0};;
914924

915925

@@ -1030,7 +1040,10 @@ namespace nil {
10301040

10311041
template<typename FieldType>
10321042
circuit_description<FieldType, placeholder_circuit_params<FieldType,
1033-
arithmetization_params_7>, 4, 3> circuit_test_7() {
1043+
arithmetization_params_7>, 4, 3> circuit_test_7(
1044+
typename nil::crypto3::random::algebraic_engine<FieldType> alg_rnd = nil::crypto3::random::algebraic_engine<FieldType>(),
1045+
boost::random::mt11213b rnd = boost::random::mt11213b()
1046+
) {
10341047
using assignment_type = typename FieldType::value_type;
10351048

10361049
constexpr static const std::size_t rows_log = 4;
@@ -1052,12 +1065,11 @@ namespace nil {
10521065
table[j].resize(test_circuit.table_rows);
10531066
}
10541067

1055-
srand(time(NULL));
10561068
// lookup inputs
10571069
typename FieldType::value_type one = FieldType::value_type::one();
10581070
typename FieldType::value_type zero = FieldType::value_type::zero();
10591071

1060-
auto r = rand() % 8;
1072+
auto r = rnd() % 7;
10611073
table[0] = std::vector<typename FieldType::value_type>(16);
10621074
std::size_t j = 0;
10631075
for( std::size_t i = 0; i < 7; i++){
@@ -1088,8 +1100,8 @@ namespace nil {
10881100
constant_assignment[2] = {0, 3, 3, 3, 2, 2, 2, 2, 6, 7, 7, 7, 7, 7, 0, 0 }; // Lookup tables
10891101
constant_assignment[3] = {0, 4, 4, 4, 4, 3, 3, 3, 64, 128, 128, 128, 128, 128, 0, 0 }; // Lookup tables
10901102
constant_assignment[4] = {0, 5, 5, 5, 5, 5, 4, 4, 1, 2, 4, 8, 16, 32, 0, 0 }; // Lookup tables
1091-
constant_assignment[5] = {0, 6, 6, 6, 6, 6, 5, 5, 64, 128, 256, 512, 1024, 2048, 0, 0 }; // Lookup tables
1092-
constant_assignment[6] = {0, 7, 7, 7, 7, 7, 7, 6,4096,8192,16384,16384,16384,16384, 0, 0 }; // Lookup tables
1103+
constant_assignment[5] = {0, 6, 6, 6, 6, 6, 6, 5, 64, 128, 256, 512, 1024, 2048, 0, 0 }; // Lookup tables
1104+
constant_assignment[6] = {0, 7, 7, 7, 7, 7, 7, 7,4096,8192,16384,16384,16384,16384, 0, 0 }; // Lookup tables
10931105

10941106
std::array<plonk_column<FieldType>, witness_columns> private_assignment;
10951107
for (std::size_t i = 0; i < witness_columns; i++) {
@@ -1137,7 +1149,7 @@ namespace nil {
11371149

11381150
std::vector<plonk_lookup_constraint<FieldType>> lookup_constraints = {lookup_constraint1};
11391151
plonk_lookup_gate<FieldType, plonk_lookup_constraint<FieldType>> lookup_gate(1, lookup_constraints);
1140-
// test_circuit.lookup_gates.push_back(lookup_gate);
1152+
test_circuit.lookup_gates.push_back(lookup_gate);
11411153

11421154
plonk_variable<assignment_type> w1( 1, 0, true, plonk_variable<assignment_type>::column_type::witness);
11431155
plonk_lookup_constraint<FieldType> lookup_constraint2;
@@ -1182,4 +1194,4 @@ namespace nil {
11821194
} // namespace nil
11831195

11841196

1185-
#endif // CRYPTO3_MARSHALLING_ZK_TEST_PLONK_CIRCUITS_HPP
1197+
#endif // MARSHALLING_ZK_TEST_PLONK_CIRCUITS_HPP

0 commit comments

Comments
 (0)