Skip to content

Commit

Permalink
libnfuzz uses the mainnet RuntimeConfig (the default one might differ…
Browse files Browse the repository at this point in the history
… in subtle ways)
  • Loading branch information
zah committed Aug 18, 2022
1 parent 7f681af commit d3dbfd6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions nfuzz/libnfuzz.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import
stew/ptrops, stew/ranges/ptr_arith, chronicles,
../beacon_chain/networking/network_metadata,
../beacon_chain/spec/datatypes/phase0,
../beacon_chain/spec/[
beaconstate, eth2_ssz_serialization, forks, validator, state_transition,
Expand Down Expand Up @@ -102,7 +103,7 @@ proc nfuzz_attestation(input: openArray[byte], xoutput: ptr byte,
proc nfuzz_attester_slashing(input: openArray[byte], xoutput: ptr byte,
xoutput_size: ptr uint, disable_bls: bool): bool {.exportc, raises: [FuzzCrashError, Defect].} =
decodeAndProcess(AttesterSlashingInput):
process_attester_slashing(defaultRuntimeConfig, data.state, data.attesterSlashing, flags, cache).isOk
process_attester_slashing(mainnetMetadata.cfg, data.state, data.attesterSlashing, flags, cache).isOk

proc nfuzz_block(input: openArray[byte], xoutput: ptr byte,
xoutput_size: ptr uint, disable_bls: bool): bool {.exportc, raises: [FuzzCrashError, Defect].} =
Expand All @@ -126,7 +127,7 @@ proc nfuzz_block(input: openArray[byte], xoutput: ptr byte,

decodeAndProcess(BlockInput):
state_transition(
defaultRuntimeConfig, data, data.beaconBlock, flags, noRollback).isOk
mainnetMetadata.cfg, data, data.beaconBlock, flags, noRollback).isOk

proc nfuzz_block_header(input: openArray[byte], xoutput: ptr byte,
xoutput_size: ptr uint, disable_bls: bool): bool {.exportc, raises: [FuzzCrashError, Defect].} =
Expand All @@ -136,17 +137,17 @@ proc nfuzz_block_header(input: openArray[byte], xoutput: ptr byte,
proc nfuzz_deposit(input: openArray[byte], xoutput: ptr byte,
xoutput_size: ptr uint, disable_bls: bool): bool {.exportc, raises: [FuzzCrashError, Defect].} =
decodeAndProcess(DepositInput):
process_deposit(defaultRuntimeConfig, data.state, data.deposit, flags).isOk
process_deposit(mainnetMetadata.cfg, data.state, data.deposit, flags).isOk

proc nfuzz_proposer_slashing(input: openArray[byte], xoutput: ptr byte,
xoutput_size: ptr uint, disable_bls: bool): bool {.exportc, raises: [FuzzCrashError, Defect].} =
decodeAndProcess(ProposerSlashingInput):
process_proposer_slashing(defaultRuntimeConfig, data.state, data.proposerSlashing, flags, cache).isOk
process_proposer_slashing(mainnetMetadata.cfg, data.state, data.proposerSlashing, flags, cache).isOk

proc nfuzz_voluntary_exit(input: openArray[byte], xoutput: ptr byte,
xoutput_size: ptr uint, disable_bls: bool): bool {.exportc, raises: [FuzzCrashError, Defect].} =
decodeAndProcess(VoluntaryExitInput):
process_voluntary_exit(defaultRuntimeConfig, data.state, data.exit, flags, cache).isOk
process_voluntary_exit(mainnetMetadata.cfg, data.state, data.exit, flags, cache).isOk

# Note: Could also accept raw input pointer and access list_size + seed here.
# However, list_size needs to be known also outside this proc to allocate xoutput.
Expand Down

0 comments on commit d3dbfd6

Please sign in to comment.