Skip to content

Commit

Permalink
reduce stack space usage in process_final_updates(...) (#925)
Browse files Browse the repository at this point in the history
* reduce stack space usage in process_final_updates(...) to avoid fuzzed segfault in #921

* document motivation behind manually constructing hash_tree_root of a HistoricalBatch
  • Loading branch information
tersec authored Apr 23, 2020
1 parent 7e94482 commit 7cd4b0b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions beacon_chain/spec/state_transition_epoch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,12 @@ func process_final_updates*(state: var BeaconState) {.nbench.}=

# Set historical root accumulator
if next_epoch mod (SLOTS_PER_HISTORICAL_ROOT div SLOTS_PER_EPOCH).uint64 == 0:
let historical_batch = HistoricalBatch(
block_roots: state.block_roots,
state_roots: state.state_roots,
)
state.historical_roots.add (hash_tree_root(historical_batch))
# Equivalent to hash_tree_root(foo: HistoricalBatch), but without using
# significant additional stack or heap.
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#historicalbatch
# In response to https://github.com/status-im/nim-beacon-chain/issues/921
state.historical_roots.add hash_tree_root(
[hash_tree_root(state.block_roots), hash_tree_root(state.state_roots)])

# Rotate current/previous epoch attestations
state.previous_epoch_attestations = state.current_epoch_attestations
Expand Down

0 comments on commit 7cd4b0b

Please sign in to comment.