debugging asserts
This commit is contained in:
parent
86cbad3d49
commit
9a11f5a7d8
|
@ -375,6 +375,21 @@ proc checkAttestation*(
|
|||
it.shard == attestation.data.shard),
|
||||
it.committee)[0]
|
||||
|
||||
# Extra checks not in specs
|
||||
# https://github.com/status-im/nim-beacon-chain/pull/105#issuecomment-462432544
|
||||
assert attestation.aggregation_bitfield.len == (
|
||||
crosslink_committee.len + 7) div 8, (
|
||||
"Error: got " & $attestation.aggregation_bitfield.len &
|
||||
" but expected " & $((crosslink_committee.len + 7) div 8)
|
||||
)
|
||||
|
||||
assert attestation.custody_bitfield.len == (
|
||||
crosslink_committee.len + 7) div 8, (
|
||||
"Error: got " & $attestation.custody_bitfield.len &
|
||||
" but expected " & $((crosslink_committee.len + 7) div 8)
|
||||
)
|
||||
# End extra checks
|
||||
|
||||
assert allIt(0 ..< len(crosslink_committee),
|
||||
if get_bitfield_bit(attestation.aggregation_bitfield, it) == 0b0:
|
||||
# Should always be true in phase 0, because of above assertion
|
||||
|
|
|
@ -17,6 +17,8 @@ func bitSet*(bitfield: var openArray[byte], index: int) =
|
|||
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#get_bitfield_bit
|
||||
func get_bitfield_bit*(bitfield: openarray[byte], i: int): byte =
|
||||
# Extract the bit in ``bitfield`` at position ``i``.
|
||||
assert 0 <= i div 8, "i: " & $i & " i div 8: " & $(i div 8)
|
||||
assert i div 8 < bitfield.len, "i: " & $i & " i div 8: " & $(i div 8)
|
||||
(bitfield[i div 8] shr (7 - (i mod 8))) mod 2
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#verify_bitfield
|
||||
|
|
Loading…
Reference in New Issue