catch invalid 0-raw-byte Bitlist SSZ inputs during parsing (#936)
* catch invalid 0-raw-byte Bitlist SSZ inputs during parsing * bump a couple more spec refs to v0.11.1
This commit is contained in:
parent
4e9fa51ae9
commit
be475a82d7
|
@ -148,9 +148,9 @@ proc process_justification_and_finalization*(
|
||||||
## matter -- in the next epoch, they'll be 2 epochs old, when BeaconState
|
## matter -- in the next epoch, they'll be 2 epochs old, when BeaconState
|
||||||
## tracks current_epoch_attestations and previous_epoch_attestations only
|
## tracks current_epoch_attestations and previous_epoch_attestations only
|
||||||
## per
|
## per
|
||||||
## https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#attestations
|
## https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#attestations
|
||||||
## and `get_matching_source_attestations(...)` via
|
## and `get_matching_source_attestations(...)` via
|
||||||
## https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#helper-functions-1
|
## https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#helper-functions-1
|
||||||
## and
|
## and
|
||||||
## https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#final-updates
|
## https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#final-updates
|
||||||
## after which the state.previous_epoch_attestations is replaced.
|
## after which the state.previous_epoch_attestations is replaced.
|
||||||
|
|
|
@ -58,6 +58,14 @@ template fromSszBytes*(T: type BitSeq, bytes: openarray[byte]): auto =
|
||||||
BitSeq @bytes
|
BitSeq @bytes
|
||||||
|
|
||||||
func fromSszBytes*[N](T: type BitList[N], bytes: openarray[byte]): auto {.raisesssz.} =
|
func fromSszBytes*[N](T: type BitList[N], bytes: openarray[byte]): auto {.raisesssz.} =
|
||||||
|
if bytes.len == 0:
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/ssz/simple-serialize.md#bitlistn
|
||||||
|
# "An additional 1 bit is added to the end, at index e where e is the
|
||||||
|
# length of the bitlist (not the limit), so that the length in bits will
|
||||||
|
# also be known."
|
||||||
|
# It's not possible to have a literally 0-byte (raw) Bitlist.
|
||||||
|
# https://github.com/status-im/nim-beacon-chain/issues/931
|
||||||
|
raise newException(MalformedSszError, "SSZ input Bitlist too small")
|
||||||
BitList[N] @bytes
|
BitList[N] @bytes
|
||||||
|
|
||||||
func fromSszBytes*[N](T: type BitArray[N], bytes: openarray[byte]): T {.raisesssz.} =
|
func fromSszBytes*[N](T: type BitArray[N], bytes: openarray[byte]): T {.raisesssz.} =
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
{.used.}
|
||||||
|
|
||||||
import
|
import
|
||||||
unittest,
|
unittest,
|
||||||
chronos, web3/ethtypes,
|
chronos, web3/ethtypes,
|
||||||
|
|
Loading…
Reference in New Issue