Skip to content

Commit d584afb

Browse files
authored
fix crash in invalid fc state (#3577)
* fix: crash in invalid fc state * also check for heads * add comments
1 parent f1b64fc commit d584afb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

execution_chain/core/chain/forked_chain/chain_serialize.nim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ proc deserialize*(fc: ForkedChainRef): Result[void, string] =
231231
let prevBase = fc.base
232232
var blocks = newSeq[BlockRef](state.numBlocks)
233233

234+
# Sanity Checks for the FC state
235+
if state.latest > state.numBlocks or
236+
state.base > state.numBlocks:
237+
fc.reset(prevBase)
238+
return err("Invalid state: latest block is greater than number of blocks")
239+
240+
# Sanity Checks for all the heads in FC state
241+
for head in state.heads:
242+
if head > state.numBlocks:
243+
fc.reset(prevBase)
244+
return err("Invalid state: heads greater than number of blocks")
245+
234246
try:
235247
for i in 0..<state.numBlocks:
236248
let

0 commit comments

Comments
 (0)