Skip to content

Commit e3c0fd6

Browse files
committed
Basic cleaning done
1 parent cdf84d0 commit e3c0fd6

File tree

3 files changed

+5
-58
lines changed

3 files changed

+5
-58
lines changed

crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/mul.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ namespace nil {
4848
public:
4949
using typename generic_component<FieldType,stage>::TYPE;
5050

51-
constexpr static const typename FieldType::value_type two_64 =
52-
0x10000000000000000_big_uint256;
53-
constexpr static const typename FieldType::value_type two_128 = 0x100000000000000000000000000000000_big_uint254;
54-
constexpr static const typename FieldType::value_type two_192 = 0x1000000000000000000000000000000000000000000000000_big_uint254;
55-
5651
TYPE chunk_sum_64(const std::vector<TYPE> &chunks, const unsigned char chunk_idx) const {
5752
BOOST_ASSERT(chunk_idx < 4);
5853
TYPE result;
@@ -70,7 +65,7 @@ namespace nil {
7065
) const {
7166
return
7267
a_64_chunks[3] * b_64_chunks[3] +
73-
two_64 * (a_64_chunks[3] * b_64_chunks[2] + a_64_chunks[2] * b_64_chunks[3]) - r_64_chunks[3] - two_64 * r_64_chunks[2];
68+
TYPE(two_64) * (a_64_chunks[3] * b_64_chunks[2] + a_64_chunks[2] * b_64_chunks[3]) - r_64_chunks[3] - TYPE(two_64) * r_64_chunks[2];
7469
}
7570

7671

@@ -82,7 +77,7 @@ namespace nil {
8277
return
8378
(a_64_chunks[3] * b_64_chunks[1] + a_64_chunks[2] * b_64_chunks[2] +
8479
a_64_chunks[1] * b_64_chunks[3] - r_64_chunks[1]) +
85-
two_64 * (a_64_chunks[3] * b_64_chunks[0] + a_64_chunks[1] * b_64_chunks[2] +
80+
TYPE(two_64) * (a_64_chunks[3] * b_64_chunks[0] + a_64_chunks[1] * b_64_chunks[2] +
8681
a_64_chunks[2] * b_64_chunks[1] + a_64_chunks[0] * b_64_chunks[3] - r_64_chunks[0]);
8782
}
8883

crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/sdiv_smod.hpp

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -48,60 +48,11 @@ namespace nil {
4848

4949
constexpr static const std::size_t chunk_amount = 16;
5050
constexpr static const std::size_t carry_amount = 16 / 3 + 1;
51-
constexpr static const value_type two_15 = 32768;
52-
constexpr static const value_type two_16 = 65536;
53-
constexpr static const value_type two_32 = 4294967296;
54-
constexpr static const value_type two_48 = 281474976710656;
55-
constexpr static const value_type two_64 = 0x10000000000000000_big_uint254;
56-
constexpr static const value_type two_128 =
57-
0x100000000000000000000000000000000_big_uint254;
58-
constexpr static const value_type two_192 =
59-
0x1000000000000000000000000000000000000000000000000_big_uint254;
6051

6152
public:
6253
using typename generic_component<FieldType, stage>::TYPE;
6354
using typename generic_component<FieldType, stage>::context_type;
6455

65-
template<typename T, typename V = T>
66-
T chunk_sum_64(const std::vector<V> &chunks, const unsigned char chunk_idx) const {
67-
BOOST_ASSERT(chunk_idx < 4);
68-
return chunks[4 * chunk_idx] + chunks[4 * chunk_idx + 1] * two_16 +
69-
chunks[4 * chunk_idx + 2] * two_32 + chunks[4 * chunk_idx + 3] * two_48;
70-
}
71-
72-
template<typename T>
73-
T first_carryless_construct(const std::vector<T> &a_64_chunks,
74-
const std::vector<T> &b_64_chunks,
75-
const std::vector<T> &r_64_chunks,
76-
const std::vector<T> &q_64_chunks) const {
77-
return r_64_chunks[0] * b_64_chunks[0] + q_64_chunks[0] +
78-
two_64 * (r_64_chunks[0] * b_64_chunks[1] +
79-
r_64_chunks[1] * b_64_chunks[0] + q_64_chunks[1]) -
80-
a_64_chunks[0] - two_64 * a_64_chunks[1];
81-
}
82-
83-
template<typename T>
84-
T second_carryless_construct(const std::vector<T> &a_64_chunks,
85-
const std::vector<T> &b_64_chunks,
86-
const std::vector<T> &r_64_chunks,
87-
const std::vector<T> &q_64_chunks) const {
88-
return (r_64_chunks[0] * b_64_chunks[2] + r_64_chunks[1] * b_64_chunks[1] +
89-
r_64_chunks[2] * b_64_chunks[0] + q_64_chunks[2] - a_64_chunks[2]) +
90-
two_64 *
91-
(r_64_chunks[0] * b_64_chunks[3] + r_64_chunks[1] * b_64_chunks[2] +
92-
r_64_chunks[2] * b_64_chunks[1] + r_64_chunks[3] * b_64_chunks[0] +
93-
q_64_chunks[3] - a_64_chunks[3]);
94-
}
95-
96-
template<typename T>
97-
T third_carryless_construct(const std::vector<T> &b_64_chunks,
98-
const std::vector<T> &r_64_chunks) const {
99-
return (r_64_chunks[1] * b_64_chunks[3] + r_64_chunks[2] * b_64_chunks[2] +
100-
r_64_chunks[3] * b_64_chunks[1]) +
101-
two_64 *
102-
(r_64_chunks[2] * b_64_chunks[3] + r_64_chunks[3] * b_64_chunks[2]);
103-
}
104-
10556
TYPE carry_on_addition_constraint(TYPE a_0, TYPE a_1, TYPE a_2, TYPE b_0, TYPE b_1,
10657
TYPE b_2, TYPE r_0, TYPE r_1, TYPE r_2,
10758
TYPE last_carry, TYPE result_carry,
@@ -245,7 +196,7 @@ namespace nil {
245196
// caluclate first row carries
246197
auto first_row_carries = first_carryless.data.base() >> 128;
247198
value_type c_1 =
248-
static_cast<value_type>(first_row_carries & (two_64 - 1).data.base());
199+
static_cast<value_type>(first_row_carries & (two_64 - 1));
249200
c_2 = static_cast<value_type>(first_row_carries >> 64);
250201
c_1_chunks = chunk_64_to_16<FieldType>(c_1);
251202
// no need for c_2 chunks as there is only a single chunk
@@ -608,4 +559,4 @@ namespace nil {
608559
};
609560
} // namespace bbf
610561
} // namespace blueprint
611-
} // namespace nil
562+
} // namespace nil

crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/util.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ namespace nil {
105105
// We define constants using the smallest possible bitlengths from nil/crypto3/multiprecision/literals.hpp
106106
// Maybe it would have been better to define more bitlenghts, but this will probably all disappear, once
107107
// small fields are introduced.
108+
static const unsigned int two_15 = 32768;
108109
static const unsigned int two_16 = 65536;
109110
static const nil::crypto3::multiprecision::big_uint<64> two_32 = 4294967296;
110111
static const nil::crypto3::multiprecision::big_uint<64> two_48 = 281474976710656;

0 commit comments

Comments
 (0)