status-im / nimbus-eth2

Nim implementation of the Ethereum Beacon Chain
https://nimbus.guide
Other
543 stars 233 forks source link

[Crash/Fuzzing] IndexError during AttesterSlashing processing #1207

Closed pventuzelo closed 4 years ago

pventuzelo commented 4 years ago

During fuzzing with beacon-fuzz, I triggered an IndexError during AttesterSlashing processing with mainnet preset.

Error: unhandled exception: index 6368 not in 0 .. 255 [IndexError]

Reproducing

Download: indexError_AttesterSlashing_nimbus.zip

branch: devel commit: 089b365c3747fc580764d9d8b9d675bf32ea55b2

Debug program:

import
  confutils, os, strutils, chronicles, json_serialization,
  ../beacon_chain/spec/crypto,
  ../beacon_chain/spec/datatypes,
  ../beacon_chain/spec/digest,
  ../beacon_chain/spec/validator,
  ../beacon_chain/spec/beaconstate,
  ../beacon_chain/spec/state_transition_block,
  ../beacon_chain/ssz,
  ../beacon_chain/extras,
  ../beacon_chain/state_transition,
  ../beacon_chain/eth2_discovery

cli do(beacon: string, container: string):
  try :
    var b = SSZ.loadFile(beacon, BeaconState)
    var c = SSZ.loadFile(container, AttesterSlashing)
    var cache = get_empty_per_epoch_cache()
    discard process_attester_slashing(b, c, {}, cache)
  except SSZError:
    quit 1
  quit 0

I have replace the code inside ncli_pretty to reuse makefile and run the following:

$ make ncli_pretty
# or ./env.sh nim c -d:const_preset=mainnet ncli/ncli_pretty

$ cd ncli

$ ./ncli_pretty --beacon=38542f2a6666ae61361a7d8249eb0a55.ssz --container=indexError_AttesterSlashing_nimbus.ssz 
Traceback (most recent call last, using override)
/nim-beacon-chain/vendor/nim-confutils/confutils.nim(981) confutils
/nim-beacon-chain/ncli/ncli_pretty.nim(24) CLI
/nim-beacon-chain/vendor/nimbus-build-system/vendor/Nim/lib/system/excpt.nim(407) reportUnhandledError
/nim-beacon-chain/vendor/nimbus-build-system/vendor/Nim/lib/system/excpt.nim(358) reportUnhandledErrorAux
Error: unhandled exception: index 6368 not in 0 .. 255 [IndexError]
tersec commented 4 years ago

Fixed by https://github.com/status-im/nim-beacon-chain/pull/1214