Fix lint
This commit is contained in:
parent
d58d7627b7
commit
d30f11a781
2
Makefile
2
Makefile
|
@ -101,7 +101,7 @@ codespell:
|
|||
|
||||
lint: pyspec
|
||||
. venv/bin/activate; cd $(PY_SPEC_DIR); \
|
||||
flake8 --ignore=E252,W504,W503 --max-line-length=120 ./eth2spec \
|
||||
flake8 --ignore=E252,W504,W503,E128 --max-line-length=120 ./eth2spec \
|
||||
&& cd ./eth2spec && mypy --follow-imports=silent --warn-unused-ignores --ignore-missing-imports --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs -p phase0 \
|
||||
&& mypy --follow-imports=silent --warn-unused-ignores --ignore-missing-imports --check-untyped-defs --disallow-incomplete-defs --disallow-untyped-defs -p phase1;
|
||||
|
||||
|
|
|
@ -978,7 +978,8 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None:
|
|||
exit_epoch=FAR_FUTURE_EPOCH,
|
||||
withdrawable_epoch=FAR_FUTURE_EPOCH,
|
||||
effective_balance=min(amount - amount % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE),
|
||||
next_custody_secret_to_reveal=get_custody_period_for_validator(ValidatorIndex(len(state.validators)), get_current_epoch(state)),
|
||||
next_custody_secret_to_reveal=get_custody_period_for_validator(ValidatorIndex(len(state.validators)),
|
||||
get_current_epoch(state)),
|
||||
all_custody_secrets_revealed_epoch=FAR_FUTURE_EPOCH,
|
||||
))
|
||||
state.balances.append(amount)
|
||||
|
|
|
@ -102,7 +102,8 @@ The following types are defined, mapping into `DomainType` (little endian):
|
|||
```python
|
||||
def replace_empty_or_append(list: List, new_element: Any) -> int:
|
||||
for i in range(len(list)):
|
||||
if list[i] == empty(typeof(new_element)):
|
||||
if list[i] == type(new_element)():
|
||||
assert False
|
||||
list[i] = new_element
|
||||
return i
|
||||
list.append(new_element)
|
||||
|
@ -236,11 +237,12 @@ def process_chunk_challenge(state: BeaconState, challenge: CustodyChunkChallenge
|
|||
# Verify the challenge is not a duplicate
|
||||
for record in state.custody_chunk_challenge_records:
|
||||
assert (
|
||||
record.data_root != challenge.attestation.data.crosslink.data_root or
|
||||
record.data_root != data_root or
|
||||
record.chunk_index != challenge.chunk_index
|
||||
)
|
||||
# Verify depth
|
||||
transition_chunks = (challenge.shard_transition.shard_block_lengths[challenge.data_index] + BYTES_PER_CUSTODY_CHUNK - 1) // BYTES_PER_CUSTODY_CHUNK
|
||||
transition_chunks = (challenge.shard_transition.shard_block_lengths[challenge.data_index]
|
||||
+ BYTES_PER_CUSTODY_CHUNK - 1) // BYTES_PER_CUSTODY_CHUNK
|
||||
assert challenge.chunk_index < transition_chunks
|
||||
# Add new chunk challenge record
|
||||
new_record = CustodyChunkChallengeRecord(
|
||||
|
@ -264,7 +266,8 @@ def process_chunk_challenge(state: BeaconState, challenge: CustodyChunkChallenge
|
|||
def process_chunk_challenge_response(state: BeaconState,
|
||||
response: CustodyChunkResponse) -> None:
|
||||
|
||||
challenge = next((record for record in state.custody_chunk_challenge_records if record.challenge_index == response.challenge_index), None)
|
||||
challenge = next((record for record in state.custody_chunk_challenge_records if
|
||||
record.challenge_index == response.challenge_index), None)
|
||||
assert(challenge is not None)
|
||||
|
||||
# Verify chunk index
|
||||
|
@ -417,7 +420,8 @@ def process_custody_slashing(state: BeaconState, signed_custody_slashing: Signed
|
|||
shard_transition = custody_slashing.shard_transition
|
||||
assert hash_tree_root(shard_transition) == attestation.data.shard_transition_root
|
||||
# Verify that the provided data matches the shard-transition
|
||||
assert custody_slashing.data.get_backing().get_left().merkle_root() == shard_transition.shard_data_roots[custody_slashing.data_index]
|
||||
assert custody_slashing.data.get_backing().get_left().merkle_root() \
|
||||
== shard_transition.shard_data_roots[custody_slashing.data_index]
|
||||
assert len(custody_slashing.data) == shard_transition.shard_block_lengths[custody_slashing.data_index]
|
||||
|
||||
# Verify existence and participation of claimed malefactor
|
||||
|
@ -467,7 +471,8 @@ Run `process_reveal_deadlines(state)` after `process_registry_updates(state)`:
|
|||
def process_reveal_deadlines(state: BeaconState) -> None:
|
||||
epoch = get_current_epoch(state)
|
||||
for index, validator in enumerate(state.validators):
|
||||
if get_custody_period_for_validator(ValidatorIndex(index), epoch) > validator.next_custody_secret_to_reveal + (CUSTODY_RESPONSE_DEADLINE // EPOCHS_PER_CUSTODY_PERIOD):
|
||||
if get_custody_period_for_validator(ValidatorIndex(index), epoch) > validator.next_custody_secret_to_reveal \
|
||||
+ (CUSTODY_RESPONSE_DEADLINE // EPOCHS_PER_CUSTODY_PERIOD):
|
||||
slash_validator(state, ValidatorIndex(index))
|
||||
```
|
||||
|
||||
|
|
|
@ -78,7 +78,8 @@ def build_attestation_data(spec, state, slot, index, shard_transition_root=None)
|
|||
)
|
||||
|
||||
|
||||
def convert_to_valid_on_time_attestation(spec, state, attestation, signed=False, shard_transition=None, valid_custody_bits=None):
|
||||
def convert_to_valid_on_time_attestation(spec, state, attestation, signed=False, shard_transition=None,
|
||||
valid_custody_bits=None):
|
||||
shard = spec.get_shard(state, attestation)
|
||||
offset_slots = spec.compute_offset_slots(spec.get_latest_slot_for_shard(state, shard), state.slot + 1)
|
||||
|
||||
|
@ -88,20 +89,14 @@ def convert_to_valid_on_time_attestation(spec, state, attestation, signed=False,
|
|||
attestation.data.slot,
|
||||
attestation.data.index,
|
||||
)
|
||||
current_epoch = spec.get_current_epoch(state)
|
||||
custody_secrets = [None for i in beacon_committee]
|
||||
for i in range(len(beacon_committee)):
|
||||
validator = state.validators[beacon_committee[i]]
|
||||
|
||||
period = spec.get_custody_period_for_validator(beacon_committee[i], attestation.data.target.epoch)
|
||||
|
||||
epoch_to_sign = spec.get_randao_epoch_for_custody_period(period, beacon_committee[i])
|
||||
|
||||
domain = spec.get_domain(state, spec.DOMAIN_RANDAO, epoch_to_sign)
|
||||
signing_root = spec.compute_signing_root(spec.Epoch(epoch_to_sign), domain)
|
||||
custody_secrets[i] = bls.Sign(privkeys[beacon_committee[i]], signing_root)
|
||||
|
||||
|
||||
for i, offset_slot in enumerate(offset_slots):
|
||||
attestation.custody_bits_blocks.append(
|
||||
Bitlist[spec.MAX_VALIDATORS_PER_COMMITTEE]([0 for _ in attestation.aggregation_bits])
|
||||
|
@ -110,7 +105,8 @@ def convert_to_valid_on_time_attestation(spec, state, attestation, signed=False,
|
|||
test_vector = get_custody_test_vector(shard_transition.shard_block_lengths[i])
|
||||
for j in range(len(attestation.custody_bits_blocks[i])):
|
||||
if attestation.aggregation_bits[j]:
|
||||
attestation.custody_bits_blocks[i][j] = spec.compute_custody_bit(custody_secrets[j], test_vector) ^ (not valid_custody_bits)
|
||||
attestation.custody_bits_blocks[i][j] = \
|
||||
spec.compute_custody_bit(custody_secrets[j], test_vector) ^ (not valid_custody_bits)
|
||||
|
||||
if signed:
|
||||
sign_attestation(spec, state, attestation)
|
||||
|
@ -118,7 +114,8 @@ def convert_to_valid_on_time_attestation(spec, state, attestation, signed=False,
|
|||
return attestation
|
||||
|
||||
|
||||
def get_valid_on_time_attestation(spec, state, slot=None, index=None, signed=False, shard_transition=None, valid_custody_bits=None):
|
||||
def get_valid_on_time_attestation(spec, state, slot=None, index=None, signed=False,
|
||||
shard_transition=None, valid_custody_bits=None):
|
||||
'''
|
||||
Construct on-time attestation for next slot
|
||||
'''
|
||||
|
@ -127,7 +124,9 @@ def get_valid_on_time_attestation(spec, state, slot=None, index=None, signed=Fal
|
|||
if index is None:
|
||||
index = 0
|
||||
|
||||
return get_valid_attestation(spec, state, slot=slot, index=index, signed=signed, on_time=True, shard_transition=shard_transition, valid_custody_bits=valid_custody_bits)
|
||||
return get_valid_attestation(spec, state, slot=slot, index=index,
|
||||
signed=signed, on_time=True, shard_transition=shard_transition,
|
||||
valid_custody_bits=valid_custody_bits)
|
||||
|
||||
|
||||
def get_valid_late_attestation(spec, state, slot=None, index=None, signed=False, shard_transition=None):
|
||||
|
@ -139,16 +138,19 @@ def get_valid_late_attestation(spec, state, slot=None, index=None, signed=False,
|
|||
if index is None:
|
||||
index = 0
|
||||
|
||||
return get_valid_attestation(spec, state, slot=slot, index=index, signed=signed, on_time=False, shard_transition=shard_transition)
|
||||
return get_valid_attestation(spec, state, slot=slot, index=index,
|
||||
signed=signed, on_time=False, shard_transition=shard_transition)
|
||||
|
||||
|
||||
def get_valid_attestation(spec, state, slot=None, index=None, empty=False, signed=False, on_time=True, shard_transition=None, valid_custody_bits=None):
|
||||
def get_valid_attestation(spec, state, slot=None, index=None, empty=False, signed=False, on_time=True,
|
||||
shard_transition=None, valid_custody_bits=None):
|
||||
if slot is None:
|
||||
slot = state.slot
|
||||
if index is None:
|
||||
index = 0
|
||||
|
||||
attestation_data = build_attestation_data(spec, state, slot, index, shard_transition_root=hash_tree_root(shard_transition) if shard_transition else spec.Root())
|
||||
attestation_data = build_attestation_data(spec, state, slot, index,
|
||||
shard_transition_root=hash_tree_root(shard_transition) if shard_transition else spec.Root())
|
||||
|
||||
beacon_committee = spec.get_beacon_committee(
|
||||
state,
|
||||
|
@ -168,7 +170,9 @@ def get_valid_attestation(spec, state, slot=None, index=None, empty=False, signe
|
|||
sign_attestation(spec, state, attestation)
|
||||
|
||||
if spec.fork == 'phase1' and on_time:
|
||||
attestation = convert_to_valid_on_time_attestation(spec, state, attestation, signed, shard_transition=shard_transition, valid_custody_bits=valid_custody_bits)
|
||||
attestation = convert_to_valid_on_time_attestation(spec, state, attestation, signed,
|
||||
shard_transition=shard_transition,
|
||||
valid_custody_bits=valid_custody_bits)
|
||||
|
||||
return attestation
|
||||
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
from eth2spec.test.helpers.keys import privkeys
|
||||
from eth2spec.utils import bls
|
||||
from eth2spec.utils.ssz.ssz_typing import Bitlist, ByteVector, Bitvector, ByteList, uint64
|
||||
from eth2spec.utils.ssz.ssz_impl import hash_tree_root
|
||||
from eth2spec.utils.merkle_minimal import get_merkle_root, get_merkle_tree, get_merkle_proof
|
||||
from remerkleable.core import pack_bits_to_chunks
|
||||
from remerkleable.tree import subtree_fill_to_contents, get_depth, Node, Gindex, gindex_bit_iter, Root
|
||||
from eth2spec.utils.ssz.ssz_typing import Bitlist, ByteVector, ByteList
|
||||
from remerkleable.tree import gindex_bit_iter
|
||||
|
||||
BYTES_PER_CHUNK = 32
|
||||
|
||||
|
@ -79,9 +76,8 @@ def get_valid_custody_slashing(spec, state, attestation, shard_transition, inval
|
|||
signing_root = spec.compute_signing_root(spec.Epoch(epoch), domain)
|
||||
malefactor_key = bls.Sign(privkeys[malefactor_index], signing_root)
|
||||
data_index = 0
|
||||
data=ByteList[spec.MAX_SHARD_BLOCK_SIZE](get_custody_test_vector(shard_transition.shard_block_lengths[data_index]))
|
||||
print(hash_tree_root(data))
|
||||
print(data.get_backing().get_left().merkle_root())
|
||||
data = ByteList[spec.MAX_SHARD_BLOCK_SIZE](
|
||||
get_custody_test_vector(shard_transition.shard_block_lengths[data_index]))
|
||||
|
||||
slashing = spec.CustodySlashing(
|
||||
data_index=data_index,
|
||||
|
@ -93,7 +89,7 @@ def get_valid_custody_slashing(spec, state, attestation, shard_transition, inval
|
|||
data=data,
|
||||
)
|
||||
slashing_domain = spec.get_domain(state, spec.DOMAIN_CUSTODY_BIT_SLASHING)
|
||||
slashing_root = spec.compute_signing_root(slashing, domain)
|
||||
slashing_root = spec.compute_signing_root(slashing, slashing_domain)
|
||||
|
||||
signed_slashing = spec.SignedCustodySlashing(
|
||||
message=slashing,
|
||||
|
@ -103,22 +99,23 @@ def get_valid_custody_slashing(spec, state, attestation, shard_transition, inval
|
|||
return signed_slashing
|
||||
|
||||
|
||||
def get_valid_chunk_challenge(spec, state, attestation, shard_transition):
|
||||
shard = spec.compute_shard_from_committee_index(state, attestation.data.index, attestation.data.slot)
|
||||
def get_valid_chunk_challenge(spec, state, attestation, shard_transition, data_index=None, chunk_index=None):
|
||||
crosslink_committee = spec.get_beacon_committee(
|
||||
state,
|
||||
attestation.data.slot,
|
||||
attestation.data.index
|
||||
)
|
||||
responder_index = crosslink_committee[0]
|
||||
data_index = len(shard_transition.shard_block_lengths) - 1
|
||||
data_index = len(shard_transition.shard_block_lengths) - 1 if not data_index else data_index
|
||||
|
||||
chunk_count = (shard_transition.shard_block_lengths[data_index] + spec.BYTES_PER_CUSTODY_CHUNK - 1) // spec.BYTES_PER_CUSTODY_CHUNK
|
||||
chunk_count = (shard_transition.shard_block_lengths[data_index]
|
||||
+ spec.BYTES_PER_CUSTODY_CHUNK - 1) // spec.BYTES_PER_CUSTODY_CHUNK
|
||||
chunk_index = chunk_count - 1 if not chunk_index else chunk_index
|
||||
|
||||
return spec.CustodyChunkChallenge(
|
||||
responder_index=responder_index,
|
||||
attestation=attestation,
|
||||
chunk_index=chunk_count - 1,
|
||||
chunk_index=chunk_index,
|
||||
data_index=data_index,
|
||||
shard_transition=shard_transition,
|
||||
)
|
||||
|
@ -174,7 +171,8 @@ def get_custody_test_vector(bytelength):
|
|||
|
||||
|
||||
def get_shard_transition(spec, start_slot, block_lengths):
|
||||
b = [ByteList[spec.MAX_SHARD_BLOCK_SIZE](get_custody_test_vector(x)).get_backing().get_left().merkle_root() for x in block_lengths]
|
||||
b = [ByteList[spec.MAX_SHARD_BLOCK_SIZE](get_custody_test_vector(x))
|
||||
.get_backing().get_left().merkle_root() for x in block_lengths]
|
||||
shard_transition = spec.ShardTransition(
|
||||
start_slot=start_slot,
|
||||
shard_block_lengths=block_lengths,
|
||||
|
@ -183,7 +181,3 @@ def get_shard_transition(spec, start_slot, block_lengths):
|
|||
proposer_signature_aggregate=spec.BLSSignature(),
|
||||
)
|
||||
return shard_transition
|
||||
|
||||
|
||||
def get_custody_merkle_root(data):
|
||||
return None # get_merkle_tree(chunkify(data))[-1][0]
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# TODO: What is this file for??? It seems to be broken!
|
||||
# The phase0 attestations file already adds the custody bit blocks
|
||||
from eth2spec.utils.ssz.ssz_typing import Bitlist
|
||||
from eth2spec.utils import bls
|
||||
|
||||
|
@ -12,16 +14,14 @@ def get_valid_on_time_attestation(spec, state, index=None, signed=False, shard_t
|
|||
if index is None:
|
||||
index = 0
|
||||
|
||||
attestation = phase0_attestations.get_valid_attestation(spec, state, state.slot, index, False, shard_transition_root=shard_transition_root)
|
||||
attestation = phase0_attestations.get_valid_attestation(spec, state, state.slot, index, False)
|
||||
shard = spec.get_shard(state, attestation)
|
||||
offset_slots = spec.compute_offset_slots(spec.get_latest_slot_for_shard(state, shard), state.slot + 1)
|
||||
print(offset_slots)
|
||||
|
||||
for _ in offset_slots:
|
||||
attestation.custody_bits_blocks.append(
|
||||
Bitlist[spec.MAX_VALIDATORS_PER_COMMITTEE]([0 for _ in attestation.aggregation_bits])
|
||||
)
|
||||
print(len(attestation.custody_bits_blocks))
|
||||
|
||||
if signed:
|
||||
sign_attestation(spec, state, attestation)
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
from eth2spec.test.helpers.custody import (
|
||||
get_valid_chunk_challenge,
|
||||
get_valid_custody_chunk_response,
|
||||
get_custody_test_vector,
|
||||
get_custody_merkle_root,
|
||||
get_shard_transition,
|
||||
)
|
||||
from eth2spec.test.helpers.attestations import (
|
||||
get_valid_on_time_attestation,
|
||||
)
|
||||
from eth2spec.test.helpers.state import transition_to
|
||||
from eth2spec.utils.ssz.ssz_impl import hash_tree_root
|
||||
from eth2spec.test.context import (
|
||||
with_all_phases_except,
|
||||
spec_state_test,
|
||||
|
@ -30,7 +27,7 @@ def run_chunk_challenge_processing(spec, state, custody_chunk_challenge, valid=T
|
|||
yield 'custody_chunk_challenge', custody_chunk_challenge
|
||||
|
||||
if not valid:
|
||||
expect_assertion_error(lambda: spec.custody_chunk_challenge(state, custody_chunk_challenge))
|
||||
expect_assertion_error(lambda: spec.process_chunk_challenge(state, custody_chunk_challenge))
|
||||
yield 'post', None
|
||||
return
|
||||
|
||||
|
@ -74,12 +71,8 @@ def test_challenge_appended(spec, state):
|
|||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
data_index = 0
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, shard_transition=shard_transition)
|
||||
|
||||
transition_chunks = (shard_transition.shard_block_lengths[data_index] + spec.BYTES_PER_CUSTODY_CHUNK - 1) // spec.BYTES_PER_CUSTODY_CHUNK
|
||||
test_vector = get_custody_test_vector(shard_transition.shard_block_lengths[data_index])
|
||||
shard_root = get_custody_merkle_root(test_vector)
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
|
||||
|
||||
|
@ -92,6 +85,54 @@ def test_challenge_appended(spec, state):
|
|||
yield from run_chunk_challenge_processing(spec, state, challenge)
|
||||
|
||||
|
||||
@with_all_phases_except(['phase0'])
|
||||
@spec_state_test
|
||||
def test_duplicate_challenge(spec, state):
|
||||
transition_to(spec, state, state.slot + 1)
|
||||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
|
||||
|
||||
_, _, _ = run_attestation_processing(spec, state, attestation)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH * spec.EPOCHS_PER_CUSTODY_PERIOD)
|
||||
|
||||
challenge = get_valid_chunk_challenge(spec, state, attestation, shard_transition)
|
||||
|
||||
_, _, _ = run_chunk_challenge_processing(spec, state, challenge)
|
||||
|
||||
yield from run_chunk_challenge_processing(spec, state, challenge, valid=False)
|
||||
|
||||
|
||||
@with_all_phases_except(['phase0'])
|
||||
@spec_state_test
|
||||
def test_second_challenge(spec, state):
|
||||
transition_to(spec, state, state.slot + 1)
|
||||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
|
||||
|
||||
_, _, _ = run_attestation_processing(spec, state, attestation)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH * spec.EPOCHS_PER_CUSTODY_PERIOD)
|
||||
|
||||
challenge0 = get_valid_chunk_challenge(spec, state, attestation, shard_transition, chunk_index=0)
|
||||
|
||||
_, _, _ = run_chunk_challenge_processing(spec, state, challenge0)
|
||||
|
||||
challenge1 = get_valid_chunk_challenge(spec, state, attestation, shard_transition, chunk_index=1)
|
||||
|
||||
yield from run_chunk_challenge_processing(spec, state, challenge1)
|
||||
|
||||
|
||||
@with_all_phases_except(['phase0'])
|
||||
@spec_state_test
|
||||
def test_multiple_epochs_custody(spec, state):
|
||||
|
@ -100,8 +141,8 @@ def test_multiple_epochs_custody(spec, state):
|
|||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
data_index = 0
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, shard_transition=shard_transition)
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
|
||||
|
||||
|
@ -122,8 +163,8 @@ def test_many_epochs_custody(spec, state):
|
|||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
data_index = 0
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, shard_transition=shard_transition)
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
|
||||
|
||||
|
@ -144,8 +185,8 @@ def test_off_chain_attestation(spec, state):
|
|||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
data_index = 0
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, shard_transition=shard_transition)
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH * (spec.EPOCHS_PER_CUSTODY_PERIOD - 1))
|
||||
|
||||
|
@ -162,8 +203,8 @@ def test_custody_response(spec, state):
|
|||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
data_index = 0
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, shard_transition=shard_transition)
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
|
||||
|
||||
|
@ -190,8 +231,8 @@ def test_custody_response_multiple_epochs(spec, state):
|
|||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
data_index = 0
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, shard_transition=shard_transition)
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
|
||||
|
||||
|
@ -218,8 +259,8 @@ def test_custody_response_many_epochs(spec, state):
|
|||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
data_index = 0
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, shard_transition=shard_transition)
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
|
||||
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
from eth2spec.test.helpers.custody import (
|
||||
get_valid_custody_slashing,
|
||||
get_custody_test_vector,
|
||||
get_custody_merkle_root,
|
||||
get_shard_transition,
|
||||
)
|
||||
from eth2spec.test.helpers.attestations import (
|
||||
get_valid_on_time_attestation,
|
||||
)
|
||||
from eth2spec.utils.ssz.ssz_impl import hash_tree_root
|
||||
from eth2spec.utils.ssz.ssz_typing import ByteList
|
||||
from eth2spec.test.helpers.state import next_epoch, get_balance, transition_to
|
||||
from eth2spec.test.helpers.block import apply_empty_block
|
||||
from eth2spec.test.helpers.state import get_balance, transition_to
|
||||
from eth2spec.test.context import (
|
||||
with_all_phases_except,
|
||||
spec_state_test,
|
||||
|
@ -63,8 +59,8 @@ def test_custody_slashing(spec, state):
|
|||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
data_index = 0
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, shard_transition=shard_transition, valid_custody_bits=False)
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition, valid_custody_bits=False)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
|
||||
|
||||
|
@ -72,8 +68,6 @@ def test_custody_slashing(spec, state):
|
|||
|
||||
transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH * (spec.EPOCHS_PER_CUSTODY_PERIOD - 1))
|
||||
|
||||
data_index = 0
|
||||
|
||||
slashing = get_valid_custody_slashing(spec, state, attestation, shard_transition)
|
||||
|
||||
yield from run_custody_slashing_processing(spec, state, slashing, correct=True)
|
||||
|
@ -86,8 +80,8 @@ def test_incorrect_custody_slashing(spec, state):
|
|||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
data_index = 0
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, shard_transition=shard_transition, valid_custody_bits=True)
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition, valid_custody_bits=True)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
|
||||
|
||||
|
@ -95,8 +89,6 @@ def test_incorrect_custody_slashing(spec, state):
|
|||
|
||||
transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH * (spec.EPOCHS_PER_CUSTODY_PERIOD - 1))
|
||||
|
||||
data_index = 0
|
||||
|
||||
slashing = get_valid_custody_slashing(spec, state, attestation, shard_transition)
|
||||
|
||||
yield from run_custody_slashing_processing(spec, state, slashing, correct=False)
|
||||
|
@ -109,8 +101,8 @@ def test_multiple_epochs_custody(spec, state):
|
|||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
data_index = 0
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, shard_transition=shard_transition, valid_custody_bits=False)
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition, valid_custody_bits=False)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
|
||||
|
||||
|
@ -118,8 +110,6 @@ def test_multiple_epochs_custody(spec, state):
|
|||
|
||||
transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH * (spec.EPOCHS_PER_CUSTODY_PERIOD - 1))
|
||||
|
||||
data_index = 0
|
||||
|
||||
slashing = get_valid_custody_slashing(spec, state, attestation, shard_transition)
|
||||
|
||||
yield from run_custody_slashing_processing(spec, state, slashing, correct=True)
|
||||
|
@ -128,12 +118,12 @@ def test_multiple_epochs_custody(spec, state):
|
|||
@with_all_phases_except(['phase0'])
|
||||
@spec_state_test
|
||||
def test_many_epochs_custody(spec, state):
|
||||
transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH* 100)
|
||||
transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH * 100)
|
||||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
data_index = 0
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, shard_transition=shard_transition, valid_custody_bits=False)
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition, valid_custody_bits=False)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
|
||||
|
||||
|
@ -141,8 +131,6 @@ def test_many_epochs_custody(spec, state):
|
|||
|
||||
transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH * (spec.EPOCHS_PER_CUSTODY_PERIOD - 1))
|
||||
|
||||
data_index = 0
|
||||
|
||||
slashing = get_valid_custody_slashing(spec, state, attestation, shard_transition)
|
||||
|
||||
yield from run_custody_slashing_processing(spec, state, slashing, correct=True)
|
||||
|
@ -155,13 +143,11 @@ def test_off_chain_attestation(spec, state):
|
|||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
data_index = 0
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, shard_transition=shard_transition, valid_custody_bits=False)
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition, valid_custody_bits=False)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH * (spec.EPOCHS_PER_CUSTODY_PERIOD - 1))
|
||||
|
||||
data_index = 0
|
||||
|
||||
slashing = get_valid_custody_slashing(spec, state, attestation, shard_transition)
|
||||
|
||||
yield from run_custody_slashing_processing(spec, state, slashing, correct=True)
|
||||
|
@ -174,8 +160,8 @@ def test_invalid_custody_slashing(spec, state):
|
|||
shard = 0
|
||||
offset_slots = spec.get_offset_slots(state, shard)
|
||||
shard_transition = get_shard_transition(spec, state.slot, [2**15 // 3] * len(offset_slots))
|
||||
data_index = 0
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True, shard_transition=shard_transition, valid_custody_bits=False)
|
||||
attestation = get_valid_on_time_attestation(spec, state, index=shard, signed=True,
|
||||
shard_transition=shard_transition, valid_custody_bits=False)
|
||||
|
||||
transition_to(spec, state, state.slot + spec.MIN_ATTESTATION_INCLUSION_DELAY)
|
||||
|
||||
|
@ -183,8 +169,6 @@ def test_invalid_custody_slashing(spec, state):
|
|||
|
||||
transition_to(spec, state, state.slot + spec.SLOTS_PER_EPOCH * (spec.EPOCHS_PER_CUSTODY_PERIOD - 1))
|
||||
|
||||
data_index = 0
|
||||
|
||||
slashing = get_valid_custody_slashing(spec, state, attestation, shard_transition)
|
||||
|
||||
slashing.message.data = ByteList[spec.MAX_SHARD_BLOCK_SIZE]()
|
||||
|
|
Loading…
Reference in New Issue