Skip to content

Commit

Permalink
Small toOpenArray optim + notes on in-place hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed May 9, 2019
1 parent 144b972 commit ef24e63
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions beacon_chain/spec/digest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func shortLog*(x: Eth2Digest): string =
# result = is needed to fix https://github.com/status-im/nim-beacon-chain/issues/209
result = ($x)[0..7]

# TODO: expose an in-place digest function
# when hashing in loop or into a buffer
# See: https://github.com/cheatfate/nimcrypto/blob/b90ba3abd/nimcrypto/sha2.nim#L570
func eth2hash*(v: openArray[byte]): Eth2Digest {.inline.} =
result = sha256.digest(v)

Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/spec/validator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func get_shuffled_seq*(seed: Eth2Digest,
source_buffer[32] = round_bytes1

# Only one pivot per round.
let pivot = bytes_to_int(eth2hash(pivot_buffer).data[0..7]) mod list_size
let pivot = bytes_to_int(eth2hash(pivot_buffer).data.toOpenArray(0, 7)) mod list_size

## Only need to run, per round, position div 256 hashes, so precalculate
## them. This consumes memory, but for low-memory devices, it's possible
Expand Down

0 comments on commit ef24e63

Please sign in to comment.