Skip to content

Commit ba82843

Browse files
committed
Submodules assigner, circifier updated to support bit (de)composition builtins. #154
1 parent ad0afc0 commit ba82843

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

examples/cpp/balances_tree.cpp

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#include <nil/crypto3/hash/algorithm/hash.hpp>
22
#include <nil/crypto3/hash/sha2.hpp>
3+
#include <cstdint>
34

45
using namespace nil::crypto3;
56

6-
constexpr std::size_t validators_amount_log2 = 20;
7+
constexpr std::size_t validators_amount_log2 = 6;
78
constexpr std::size_t validators_per_leaf_log2 = 2;
89

910
const std::array<typename hashes::sha2<256>::block_type, 39> precomputed_zero_hashes = {{
@@ -47,8 +48,8 @@ const std::array<typename hashes::sha2<256>::block_type, 39> precomputed_zero_ha
4748
{0xf7210d4f8e7e1039790e7bf4efa20755_cppui255, 0x5a10a6db1dd4b95da313aaa88b88fe76_cppui255},
4849
{0xad21b516cbc645ffe34ab5de1c8aef8c_cppui255, 0xd4e7f8d2b51e8e1456adc7563cda206f_cppui255}
4950
}};
50-
51-
constexpr std::array<unsigned long long, 39> precomputed_powers_of_two = {{
51+
// The more precomputed powers of two are uncommented, the more RAM is used during circuit generation phase.
52+
constexpr std::array<unsigned long long, 11> precomputed_powers_of_two = {{
5253
1,
5354
2,
5455
4,
@@ -60,34 +61,34 @@ constexpr std::array<unsigned long long, 39> precomputed_powers_of_two = {{
6061
256,
6162
512,
6263
1024,
63-
2048,
64-
4096,
65-
8192,
66-
16384,
67-
32768,
68-
65536,
69-
131072,
70-
262144,
71-
524288,
72-
1048576,
73-
2097152,
74-
4194304,
75-
8388608,
76-
16777216,
77-
33554432,
78-
67108864,
79-
134217728,
80-
268435456,
81-
536870912,
82-
1073741824,
83-
2147483648,
84-
4294967296,
85-
8589934592,
86-
17179869184,
87-
34359738368,
88-
68719476736,
89-
137438953472,
90-
274877906944
64+
// 2048,
65+
// 4096,
66+
// 8192,
67+
// 16384,
68+
// 32768,
69+
// 65536,
70+
// 131072,
71+
// 262144,
72+
// 524288,
73+
// 1048576,
74+
// 2097152,
75+
// 4194304,
76+
// 8388608,
77+
// 16777216,
78+
// 33554432,
79+
// 67108864,
80+
// 134217728,
81+
// 268435456,
82+
// 536870912,
83+
// 1073741824,
84+
// 2147483648,
85+
// 4294967296,
86+
// 8589934592,
87+
// 17179869184,
88+
// 34359738368,
89+
// 68719476736,
90+
// 137438953472,
91+
// 274877906944
9192
}};
9293

9394
bool is_same(typename hashes::sha2<256>::block_type block0,
@@ -111,7 +112,7 @@ typename hashes::sha2<256>::block_type hash_layer(std::array<typename hashes::sh
111112
}
112113

113114
[[circuit]] bool balance_tree(
114-
[[private]] std::array<unsigned long long, precomputed_powers_of_two[validators_amount_log2]> validator_balances,
115+
[[private]] std::array<int64_t, precomputed_powers_of_two[validators_amount_log2]> validator_balances,
115116
typename hashes::sha2<256>::block_type expected_root,
116117
unsigned long long expected_total_balance) {
117118

@@ -148,7 +149,7 @@ typename hashes::sha2<256>::block_type hash_layer(std::array<typename hashes::sh
148149

149150
typename hashes::sha2<256>::block_type non_zero_balances_subtree_root = hash_layer<potentially_non_zero_leaves_amount>(potentially_non_zero_leaves);
150151

151-
constexpr std::size_t leaves_total_amount_log2 = precomputed_powers_of_two.size();
152+
constexpr std::size_t leaves_total_amount_log2 = precomputed_powers_of_two.size() - 1;
152153
constexpr std::size_t layer_with_zero_balance_subtrees_roots_size_log2 = leaves_total_amount_log2 - potentially_non_zero_leaves_amount_log2;
153154
constexpr std::size_t layer_with_zero_balance_subtrees_roots_size = precomputed_powers_of_two[layer_with_zero_balance_subtrees_roots_size_log2];
154155

0 commit comments

Comments
 (0)