2020-07-10 23:28:53 +00:00
|
|
|
import
|
|
|
|
testutils/fuzzing, stew/byteutils,
|
2021-09-07 14:00:01 +00:00
|
|
|
../../../eth/rlp, ../../../eth/p2p/discoveryv5/enr
|
2020-07-10 23:28:53 +00:00
|
|
|
|
|
|
|
test:
|
2024-06-27 14:18:21 +00:00
|
|
|
block testBlock:
|
2020-07-10 23:28:53 +00:00
|
|
|
# This is fuzzing the full ENR deserialisation. As ENRs contain a signature
|
|
|
|
# this will practically always fail. So the second (encoding) steps will
|
|
|
|
# never be reached.
|
|
|
|
# However, as the signature checking is done at the end, a big part of the
|
|
|
|
# parsing will still be fuzzed.
|
|
|
|
let decoded = try: rlp.decode(payload, enr.Record)
|
|
|
|
except RlpError as e:
|
|
|
|
debug "decode failed", err = e.msg
|
2024-06-27 14:18:21 +00:00
|
|
|
break testBlock
|
2020-07-10 23:28:53 +00:00
|
|
|
except ValueError as e:
|
|
|
|
debug "decode failed", err = e.msg
|
2024-06-27 14:18:21 +00:00
|
|
|
break testBlock
|
2020-07-10 23:28:53 +00:00
|
|
|
|
|
|
|
let encoded = try: rlp.encode(decoded)
|
|
|
|
except RlpError as e:
|
|
|
|
debug "decode failed", err = e.msg
|
|
|
|
doAssert(false, "decoding worked but encoding failed")
|
2024-06-27 14:18:21 +00:00
|
|
|
break testBlock
|
2020-07-10 23:28:53 +00:00
|
|
|
if encoded != payload.toOpenArray(0, encoded.len - 1):
|
|
|
|
echo "payload: ", toHex(payload.toOpenArray(0, encoded.len - 1))
|
|
|
|
echo "encoded: ", toHex(encoded)
|
|
|
|
|
|
|
|
doAssert(false, "re-encoded result does not equal original payload")
|