Skip to content

Commit

Permalink
Removed unnecessary copying of buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
HristoStaykov committed Nov 30, 2023
1 parent 67d6f42 commit f59b345
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@ using namespace circuit_byte_utils;
uint64_t compute_shuffled_index_impl(uint64_t index, uint64_t index_count, Bytes32 seed, int SHUFFLE_ROUND_COUNT = 90) {
assert_true(index < index_count);

Bytes32 source_buffer {};

std::copy(seed.begin(), seed.end(), source_buffer.begin());

// Swap or not (https://link.springer.com/content/pdf/10.1007%2F978-3-642-32009-5_1.pdf)
// See the 'generalized domain' algorithm on page 3
for (Byte current_round = 0; current_round < SHUFFLE_ROUND_COUNT; current_round++) {

Bytes32 source_round_hash = calc_hash(source_buffer, current_round);
Bytes32 source_round_hash = calc_hash(seed, current_round);
auto first8bytes = take_n_elements<8>(source_round_hash);

auto first8bytes_int = bytes_to_int<uint64_t>(first8bytes);
auto pivot = first8bytes_int % index_count;
uint64_t flip = (pivot + index_count - index) % index_count;
auto position = std::max(index, flip);

Bytes32 source_buffer_hash = calc_hash(source_buffer, current_round, int_to_bytes(uint32_t(position >> 8)));
auto byte_value = source_buffer_hash[(position % 256) >> 3];
Bytes32 seed_hash = calc_hash(seed, current_round, int_to_bytes(uint32_t(position >> 8)));
auto byte_value = seed_hash[(position % 256) >> 3];
auto bit = (byte_value >> (position % 8)) % 2;

if (bit != 0) {
Expand Down

0 comments on commit f59b345

Please sign in to comment.