Skip to content

Commit

Permalink
Resolved GitHub comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
HristoStaykov committed Jan 3, 2024
1 parent caa7c0e commit 279c7c1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace circuit_byte_utils {
}

template<typename... Args>
Bytes32 calc_hash(const Args&... args) {
Bytes32 sha256(const Args&... args) {
std::array<Byte, SizeSum<Args...>::value> buffer;
size_t offset = 0;
hash_recursive(buffer, offset, args...);
Expand All @@ -175,7 +175,7 @@ namespace circuit_byte_utils {
}

template<size_t NBytesToHash, typename Arg>
Bytes32 calc_hash(const Arg& arg, size_t offset = 0) {
Bytes32 sha256(const Arg& arg, size_t offset = 0) {
std::array<Byte, NBytesToHash> buffer;
to_bytes(arg, buffer, offset, NBytesToHash);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ssz_utils {

gindex /= 2;

hash = calc_hash(left, right);
hash = sha256(left, right);
}

return hash;
Expand All @@ -49,7 +49,7 @@ namespace ssz_utils {

Bytes32 hash_tree_root(const CheckpointVariable& checkpoint) {
auto epoch_leaf = hash_tree_root(checkpoint.epoch);
return calc_hash(epoch_leaf, checkpoint.root);
return sha256(epoch_leaf, checkpoint.root);
}

Bytes32 hash_tree_root(const JustificationBitsVariable& checkpoint) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ uint64_t compute_shuffled_index_impl(uint64_t index, uint64_t index_count, Bytes
// See the 'generalized domain' algorithm on page 3
for (Byte current_round = 0; current_round < shuffle_round_count; current_round++) {

auto pivot = bytes_to_int<uint64_t>(take<8>(calc_hash(seed, current_round))) % index_count;
auto pivot = bytes_to_int<uint64_t>(take<8>(sha256(seed, current_round))) % index_count;
uint64_t flip = (pivot + index_count - index) % index_count;
auto position = std::max(index, flip);

Bytes32 seed_hash = calc_hash(seed, current_round, int_to_bytes(uint32_t(position / 256)));
Bytes32 seed_hash = sha256(seed, current_round, int_to_bytes(uint32_t(position / 256)));
auto byte = seed_hash[(position % 256) / 8];
auto bit = (byte >> (position % 8)) % 2;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ namespace weigh_justification_and_finalization_ {

CheckpointVariable new_finalized_checkpoint;
// The 2nd/3rd/4th most recent epochs are justified, the 2nd using the 4th as source
if (justification_bits.test_range(1, 4) && (previous_justified_checkpoint.epoch + 3 == current_epoch))
if (justification_bits.test_range(1, 4) && previous_justified_checkpoint.epoch + 3 == current_epoch)
new_finalized_checkpoint = previous_justified_checkpoint;
// The 2nd/3rd most recent epochs are justified, the 2nd using the 3rd as source
if (justification_bits.test_range(1, 3) && (previous_justified_checkpoint.epoch + 2 == current_epoch))
if (justification_bits.test_range(1, 3) && previous_justified_checkpoint.epoch + 2 == current_epoch)
new_finalized_checkpoint = previous_justified_checkpoint;
// The 1st/2nd/3rd most recent epochs are justified, the 1st using the 3rd as source
if (justification_bits.test_range(0, 3) && (current_justified_checkpoint.epoch + 2 == current_epoch))
if (justification_bits.test_range(0, 3) && current_justified_checkpoint.epoch + 2 == current_epoch)
new_finalized_checkpoint = current_justified_checkpoint;
// The 1st/2nd most recent epochs are justified, the 1st using the 2nd as source
if (justification_bits.test_range(0, 2) && (current_justified_checkpoint.epoch + 1 == current_epoch))
if (justification_bits.test_range(0, 2) && current_justified_checkpoint.epoch + 1 == current_epoch)
new_finalized_checkpoint = current_justified_checkpoint;

return new_finalized_checkpoint;
Expand Down

0 comments on commit 279c7c1

Please sign in to comment.