assert() -> doAssert()

This commit is contained in:
Ștefan Talpalaru 2019-03-14 00:04:43 +01:00
parent 562eafe124
commit de295619be
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
12 changed files with 31 additions and 31 deletions

View File

@ -29,7 +29,7 @@ proc combine*(tgt: var Attestation, src: Attestation, flags: UpdateFlags) =
# Combine the signature and participation bitfield, with the assumption that
# the same data is being signed!
assert tgt.data == src.data
doAssert tgt.data == src.data
# TODO:
# when BLS signatures are combined, we must ensure that

View File

@ -36,7 +36,7 @@ proc init*(T: type BlockPool, db: BeaconChainDB): BlockPool =
for root, _ in db.getAncestors(headRoot):
if root == tailRef.root:
assert(not curRef.isNil)
doAssert(not curRef.isNil)
link(tailRef, curRef)
curRef = curRef.parent
break

View File

@ -421,8 +421,8 @@ proc checkAttestation*(
crosslink_data_root = attestation.data.crosslink_data_root)
return
assert allIt(attestation.custody_bitfield, it == 0) #TO BE REMOVED IN PHASE 1
assert anyIt(attestation.aggregation_bitfield, it != 0)
doAssert allIt(attestation.custody_bitfield, it == 0) #TO BE REMOVED IN PHASE 1
doAssert anyIt(attestation.aggregation_bitfield, it != 0)
let crosslink_committee = mapIt(
filterIt(get_crosslink_committees_at_slot(state, attestation_data_slot),
@ -431,20 +431,20 @@ proc checkAttestation*(
# Extra checks not in specs
# https://github.com/status-im/nim-beacon-chain/pull/105#issuecomment-462432544
assert attestation.aggregation_bitfield.len == (
doAssert 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 == (
doAssert 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),
doAssert 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
get_bitfield_bit(attestation.custody_bitfield, it) == 0b0
@ -463,7 +463,7 @@ proc checkAttestation*(
if skipValidation notin flags:
# Verify that aggregate_signature verifies using the group pubkey.
assert bls_verify_multiple(
doAssert bls_verify_multiple(
@[
bls_aggregate_pubkeys(mapIt(custody_bit_0_participants,
state.validator_registry[it].pubkey)),

View File

@ -102,7 +102,7 @@ func merkle_root*(values: openArray[Eth2Digest]): Eth2Digest =
# These ``o`` indices get filled from ``values``.
let highest_internally_filled_index = (num_values div 2) - 1
assert (highest_internally_filled_index + 1) * 2 >= num_values
doAssert (highest_internally_filled_index + 1) * 2 >= num_values
for i in countdown(num_values-1, highest_internally_filled_index + 1):
hash_buffer[0..31] = values[i*2 - num_values].data
@ -110,7 +110,7 @@ func merkle_root*(values: openArray[Eth2Digest]): Eth2Digest =
o[i] = eth2hash(hash_buffer)
## These ``o`` indices get filled from other ``o`` indices.
assert highest_internally_filled_index * 2 + 1 < num_values
doAssert highest_internally_filled_index * 2 + 1 < num_values
for i in countdown(highest_internally_filled_index, 1):
hash_buffer[0..31] = o[i*2].data
@ -191,8 +191,8 @@ func get_randao_mix*(state: BeaconState,
## Returns the randao mix at a recent ``epoch``.
# Cannot underflow, since GENESIS_EPOCH > LATEST_RANDAO_MIXES_LENGTH
assert get_current_epoch(state) - LATEST_RANDAO_MIXES_LENGTH < epoch
assert epoch <= get_current_epoch(state)
doAssert get_current_epoch(state) - LATEST_RANDAO_MIXES_LENGTH < epoch
doAssert epoch <= get_current_epoch(state)
state.latest_randao_mixes[epoch mod LATEST_RANDAO_MIXES_LENGTH]
@ -209,7 +209,7 @@ func get_active_index_root(state: BeaconState, epoch: Epoch): Eth2Digest =
# https://github.com/ethereum/eth2.0-specs/blob/v0.2.0/specs/core/0_beacon-chain.md#bytes_to_int
func bytes_to_int*(data: seq[byte]): uint64 =
assert data.len == 8
doAssert data.len == 8
# Little-endian data representation
result = 0
@ -227,14 +227,14 @@ func int_to_bytes32*(x: uint64): array[32, byte] =
func int_to_bytes32*(x: Epoch): array[32, byte] {.borrow.}
func int_to_bytes1*(x: int): array[1, byte] =
assert x >= 0
assert x < 256
doAssert x >= 0
doAssert x < 256
result[0] = x.byte
func int_to_bytes4*(x: uint64): array[4, byte] =
assert x >= 0'u64
assert x < 2'u64^32
doAssert x >= 0'u64
doAssert x < 2'u64^32
# Little-endian data representation
result[0] = ((x shr 0) and 0xff).byte

View File

@ -101,7 +101,7 @@ func get_shuffling*(seed: Eth2Digest,
# Split the shuffled list into committees_per_epoch pieces
result = split(shuffled_seq, committees_per_epoch)
assert result.len() == committees_per_epoch # what split should do..
doAssert result.len() == committees_per_epoch # what split should do..
# https://github.com/ethereum/eth2.0-specs/blob/0.4.0/specs/core/0_beacon-chain.md#get_previous_epoch_committee_count
func get_previous_epoch_committee_count(state: BeaconState): uint64 =

View File

@ -335,7 +335,7 @@ func hash_tree_root*(x: enum): array[8, byte] =
## TODO - Warning ⚠️: not part of the spec
## as of https://github.com/ethereum/beacon_chain/pull/133/files
## This is a "stub" needed for BeaconBlock hashing
static: assert x.sizeof == 1 # Check that the enum fits in 1 byte
static: doAssert x.sizeof == 1 # Check that the enum fits in 1 byte
# TODO We've put enums where the spec uses `uint64` - maybe we should not be
# using enums?
hash_tree_root(uint64(x))

View File

@ -34,7 +34,7 @@ func toHeader(b: BeaconBlock): BeaconBlockHeader =
)
proc fromHeaderAndBody(b: var BeaconBlock, h: BeaconBlockHeader, body: BeaconBlockBody) =
assert(hash_tree_root_final(body) == h.body)
doAssert(hash_tree_root_final(body) == h.body)
b.slot = h.slot.Slot
b.parent_root = h.parent_root
b.state_root = h.state_root

View File

@ -27,7 +27,7 @@ proc obtainTrustedStateSnapshot*(db: BeaconChainDB): Future[BeaconState] {.async
#
# 5. Check that the state snapshot hash is correct and save it in the DB.
assert(false, "Not implemented")
doAssert(false, "Not implemented")
proc createStateSnapshot*(
validatorDir: string, numValidators, firstValidator, genesisOffset: int,

View File

@ -58,8 +58,8 @@ func genRandaoReveal*(k: ValidatorPrivKey, state: BeaconState, slot: Slot):
ValidatorSig =
# https://github.com/ethereum/eth2.0-specs/blob/v0.2.0/specs/core/0_beacon-chain.md#randao
# Off-by-one? I often get slot == state.slot but the check was "assert slot > state.slot" (Mamy)
assert slot >= state.slot, "input slot: " & $humaneSlotNum(slot) & " - beacon state slot: " & $humaneSlotNum(state.slot)
# Off-by-one? I often get slot == state.slot but the check was "doAssert slot > state.slot" (Mamy)
doAssert slot >= state.slot, "input slot: " & $humaneSlotNum(slot) & " - beacon state slot: " & $humaneSlotNum(state.slot)
bls_sign(k, hash_tree_root(slot_to_epoch(slot).uint64),
get_domain(state.fork, slot_to_epoch(slot), DOMAIN_RANDAO))

View File

@ -44,7 +44,7 @@ proc appendBigEndianInt(dst: var seq[byte], src: SomeNumber) =
elif size == 8: # int64
bigEndian64(dst, src)
else:
static: assert false, "src must be a int16, int32 or int64 or unsigned int of the same size"
static: doAssert false, "src must be a int16, int32 or int64 or unsigned int of the same size"
dst.setLen(dst.len + size)
bigEndian(dst[dst.len - size].addr, src.unsafeAddr)
@ -83,7 +83,7 @@ proc serializeETH[T](x: T): seq[byte] =
for chr in schema:
result.add byte(chr)
assert result.len == offset
doAssert result.len == offset
# Write raw data - this is similar to SimpleSerialize
for field in fields(x):
@ -98,7 +98,7 @@ proc serializeETH[T](x: T): seq[byte] =
else:
raise newException(ValueError, "Not implemented")
assert result.len == offset + sizeof(T)
doAssert result.len == offset + sizeof(T)
# Compute the hash
result[metadataStart ..< metadataStart + sizeof(Hash256)] = blake2_256.digest(result[offset ..< result.len]).data

View File

@ -13,7 +13,7 @@ func sumCommittees(v: openArray[seq[ValidatorIndex]], reqCommitteeLen: int): int
## This only holds when num_validators is divisible by
## SLOTS_PER_EPOCH * get_committee_count_per_slot(len(validators))
## as, in general, not all committees can be equally sized.
assert x.len == reqCommitteeLen
doAssert x.len == reqCommitteeLen
inc result, x.len
func checkPermutation(index: int, list_size: uint64,

View File

@ -108,7 +108,7 @@ proc addBlock*(
let block_ok = updateState(
state, previous_block_root, new_block, {skipValidation})
assert block_ok
doAssert block_ok
# Ok, we have the new state as it would look with the block applied - now we
# can set the state root in order to be able to create a valid signature
@ -127,7 +127,7 @@ proc addBlock*(
)
proposal_hash = signed_root(signed_data, "signature")
assert proposerPrivkey.pubKey() == proposer.pubkey,
doAssert proposerPrivkey.pubKey() == proposer.pubkey,
"signature key should be derived from private key! - wrong privkey?"
if skipValidation notin flags:
@ -136,7 +136,7 @@ proc addBlock*(
bls_sign(proposerPrivkey, proposal_hash,
get_domain(state.fork, slot_to_epoch(state.slot), DOMAIN_PROPOSAL))
assert bls_verify(
doAssert bls_verify(
proposer.pubkey,
proposal_hash, new_block.signature,
get_domain(state.fork, slot_to_epoch(state.slot), DOMAIN_PROPOSAL)),
@ -170,7 +170,7 @@ proc makeAttestation*(
sac_index = sac.committee.find(validator_index)
data = makeAttestationData(state, sac.shard, beacon_block_root)
assert sac_index != -1, "find_shard_committe should guarantee this"
doAssert sac_index != -1, "find_shard_committe should guarantee this"
var
aggregation_bitfield = repeat(0'u8, ceil_div8(sac.committee.len))