Beispiel #1
0
def test_success_one_in_queue(spec, state):
    prepare_withdrawals_queue(spec, state, 1)

    next_slot(spec, state)
    execution_payload = build_empty_execution_payload(spec, state)

    yield from run_withdrawals_processing(spec, state, execution_payload)
Beispiel #2
0
def test_success_max_per_slot_in_queue(spec, state):
    prepare_withdrawals_queue(spec, state, spec.MAX_WITHDRAWALS_PER_PAYLOAD)

    next_slot(spec, state)
    execution_payload = build_empty_execution_payload(spec, state)

    yield from run_withdrawals_processing(spec, state, execution_payload)
Beispiel #3
0
def test_success_empty_queue(spec, state):
    assert len(state.withdrawals_queue) == 0

    next_slot(spec, state)
    execution_payload = build_empty_execution_payload(spec, state)

    yield from run_withdrawals_processing(spec, state, execution_payload)
Beispiel #4
0
def test_parent_from_same_slot(spec, state):
    yield 'pre', state

    parent_block = build_empty_block_for_next_slot(spec, state)
    signed_parent_block = state_transition_and_sign_block(
        spec, state, parent_block)

    child_block = parent_block.copy()
    child_block.parent_root = state.latest_block_header.hash_tree_root()

    if is_post_merge(spec):
        child_block.body.execution_payload = build_empty_execution_payload(
            spec, state)

    # Show that normal path through transition fails
    failed_state = state.copy()
    expect_assertion_error(lambda: spec.state_transition(
        failed_state,
        spec.SignedBeaconBlock(message=child_block),
        validate_result=False))

    # Artificially bypass the restriction in the state transition to transition and sign block for test vectors
    signed_child_block = process_and_sign_block_without_header_validations(
        spec, state, child_block)

    yield 'blocks', [signed_parent_block, signed_child_block]
    yield 'post', None
Beispiel #5
0
def build_empty_block(spec, state, slot=None):
    """
    Build empty block for ``slot``, built upon the latest block header seen by ``state``.
    Slot must be greater than or equal to the current slot in ``state``.
    """
    if slot is None:
        slot = state.slot
    if slot < state.slot:
        raise Exception("build_empty_block cannot build blocks for past slots")
    if state.slot < slot:
        # transition forward in copied state to grab relevant data from state
        state = state.copy()
        spec.process_slots(state, slot)

    state, parent_block_root = get_state_and_beacon_parent_root_at_slot(
        spec, state, slot)
    empty_block = spec.BeaconBlock()
    empty_block.slot = slot
    empty_block.proposer_index = spec.get_beacon_proposer_index(state)
    empty_block.body.eth1_data.deposit_count = state.eth1_deposit_index
    empty_block.parent_root = parent_block_root

    if is_post_altair(spec):
        empty_block.body.sync_aggregate.sync_committee_signature = spec.G2_POINT_AT_INFINITY

    if is_post_merge(spec):
        empty_block.body.execution_payload = build_empty_execution_payload(
            spec, state)

    apply_randao_reveal(spec, state, empty_block)
    return empty_block
def test_success_regular_payload(spec, state):
    # pre-state
    state = build_state_with_complete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)

    yield from run_execution_payload_processing(spec, state, execution_payload)
Beispiel #7
0
def test_bad_random_regular_payload(spec, state):
    # pre-state
    state = build_state_with_complete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.random = b'\x04' * 32

    yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)
Beispiel #8
0
def test_gasused_gaslimit_plus_regular_payload(spec, state):
    # pre-state
    state = build_state_with_complete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.gas_used = execution_payload.gas_limit + uint64(1)

    yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)
Beispiel #9
0
def test_bad_parent_hash_regular_payload(spec, state):
    # pre-state
    state = build_state_with_complete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.parent_hash = spec.Hash32()

    yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)
Beispiel #10
0
def test_bad_timestamp_regular_payload(spec, state):
    # pre-state
    state = build_state_with_complete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.timestamp = execution_payload.timestamp + 1

    yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)
Beispiel #11
0
def test_gaslimit_max_first_payload(spec, state):
    # pre-state
    state = build_state_with_incomplete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.gas_limit = uint64(2**64 - 1)

    yield from run_execution_payload_processing(spec, state, execution_payload)
Beispiel #12
0
def test_gaslimit_minimum_minus_regular_payload(spec, state):
    # pre-state
    state = build_state_with_complete_transition(spec, state)
    next_slot(spec, state)
    state.latest_execution_payload_header.gas_limit = spec.MIN_GAS_LIMIT

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.gas_limit = execution_payload.gas_limit - uint64(1)

    yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)
Beispiel #13
0
def test_fail_max_per_slot_in_queue_one_less_in_withdrawals(spec, state):
    prepare_withdrawals_queue(spec, state, spec.MAX_WITHDRAWALS_PER_PAYLOAD)

    next_slot(spec, state)
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.withdrawals = execution_payload.withdrawals[:-1]

    yield from run_withdrawals_processing(spec,
                                          state,
                                          execution_payload,
                                          valid=False)
Beispiel #14
0
def test_bad_execution_regular_payload(spec, state):
    # completely valid payload, but execution itself fails (e.g. block exceeds gas limit)

    # pre-state
    state = build_state_with_complete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)

    yield from run_execution_payload_processing(spec, state, execution_payload, valid=False, execution_valid=False)
Beispiel #15
0
def test_fail_incorrect_dequeue_amount(spec, state):
    prepare_withdrawals_queue(spec, state, 1)

    next_slot(spec, state)
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.withdrawals[0].amount += 1

    yield from run_withdrawals_processing(spec,
                                          state,
                                          execution_payload,
                                          valid=False)
Beispiel #16
0
def test_fail_one_in_queue_none_in_withdrawals(spec, state):
    prepare_withdrawals_queue(spec, state, 1)

    next_slot(spec, state)
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.withdrawals = []

    yield from run_withdrawals_processing(spec,
                                          state,
                                          execution_payload,
                                          valid=False)
def test_non_empty_extra_data_regular_payload(spec, state):
    # pre-state
    state = build_state_with_complete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.extra_data = b'\x45' * 12

    yield from run_execution_payload_processing(spec, state, execution_payload)

    assert state.latest_execution_payload_header.extra_data == execution_payload.extra_data
def test_bad_random_first_payload(spec, state):
    # pre-state
    state = build_state_with_incomplete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.prev_randao = b'\x42' * 32

    yield from run_execution_payload_processing(spec,
                                                state,
                                                execution_payload,
                                                valid=False)
Beispiel #19
0
def test_gaslimit_lower_regular_payload(spec, state):
    # pre-state
    state = build_state_with_complete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.gas_limit = (
        execution_payload.gas_limit -
        execution_payload.gas_limit // spec.GAS_LIMIT_DENOMINATOR + uint64(1)
    )

    yield from run_execution_payload_processing(spec, state, execution_payload)
Beispiel #20
0
def test_gaslimit_upper_plus_regular_payload(spec, state):
    # pre-state
    state = build_state_with_complete_transition(spec, state)
    next_slot(spec, state)

    # execution payload
    execution_payload = build_empty_execution_payload(spec, state)
    execution_payload.gas_limit = (
        execution_payload.gas_limit +
        execution_payload.gas_limit // spec.GAS_LIMIT_DENOMINATOR
    )

    yield from run_execution_payload_processing(spec, state, execution_payload, valid=False)
Beispiel #21
0
def test_is_merge_block_and_is_execution_enabled(spec, state):
    for result in expected_results:
        (with_complete_transition, with_execution_payload, is_merge_block,
         is_execution_enabled) = result
        if with_complete_transition:
            state = build_state_with_complete_transition(spec, state)
        else:
            state = build_state_with_incomplete_transition(spec, state)

        body = spec.BeaconBlockBody()
        if with_execution_payload:
            body.execution_payload = build_empty_execution_payload(spec, state)

        assert spec.is_merge_block(state, body) == is_merge_block
        assert spec.is_execution_enabled(state, body) == is_execution_enabled
Beispiel #22
0
def test_fail_empty_queue_non_empty_withdrawals(spec, state):
    assert len(state.withdrawals_queue) == 0

    next_slot(spec, state)
    execution_payload = build_empty_execution_payload(spec, state)
    withdrawal = spec.Withdrawal(
        index=0,
        address=b'\x30' * 20,
        amount=420,
    )
    execution_payload.withdrawals.append(withdrawal)

    yield from run_withdrawals_processing(spec,
                                          state,
                                          execution_payload,
                                          valid=False)
Beispiel #23
0
def test_fail_many_dequeued_incorrectly(spec, state):
    prepare_withdrawals_queue(spec, state,
                              spec.MAX_WITHDRAWALS_PER_PAYLOAD * 4)

    next_slot(spec, state)
    execution_payload = build_empty_execution_payload(spec, state)
    for i, withdrawal in enumerate(execution_payload.withdrawals):
        if i % 3 == 0:
            withdrawal.index += 1
        elif i % 3 == 1:
            withdrawal.address = (i).to_bytes(20, 'big')
        else:
            withdrawal.amount += 1

    yield from run_withdrawals_processing(spec,
                                          state,
                                          execution_payload,
                                          valid=False)
Beispiel #24
0
def test_fail_one_of_many_dequeued_incorrectly(spec, state):
    prepare_withdrawals_queue(spec, state,
                              spec.MAX_WITHDRAWALS_PER_PAYLOAD * 4)

    next_slot(spec, state)
    execution_payload = build_empty_execution_payload(spec, state)
    num_withdrawals = len(execution_payload.withdrawals)

    # Pick withdrawal in middle of list and mutate
    withdrawal = execution_payload.withdrawals[num_withdrawals // 2]
    withdrawal.index += 1
    withdrawal.address = b'\x99' * 20
    withdrawal.amount += 4000000

    yield from run_withdrawals_processing(spec,
                                          state,
                                          execution_payload,
                                          valid=False)