Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import random
from eth2spec.test.helpers.state import next_epoch

from eth2spec.test.helpers.attestations import get_valid_attestation

from eth2spec.test.context import (
always_bls,
spec_state_test,
Expand All @@ -9,6 +14,7 @@
set_builder_withdrawal_credential,
set_builder_withdrawal_credential_with_balance,
)
from eth2spec.test.helpers.execution_payload import build_empty_execution_payload


def run_execution_payload_bid_processing(spec, state, block, valid=True):
Expand Down Expand Up @@ -348,6 +354,48 @@ def test_process_execution_payload_bid_slashed_builder(spec, state):

yield from run_execution_payload_bid_processing(spec, state, block, valid=False)

@with_gloas_and_later
@spec_state_test
def test_process_block_then_slash_non_timely_builder(spec, state):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good if you yield so it would create a test vector

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perphas one of the operations formats here: tests/formats/operations/README.md

"""
Empty-case payment path:
- A builder posts a successful bid in a block, but the payload is not revealed in time.
- Builder is slashed
- Proposer unconditional payment is enforced by moving the bid amount into
"""

# Get past genesis
next_epoch(spec, state)
next_epoch(spec, state)

block, builder_index = prepare_block_with_non_proposer_builder(spec, state)

value = spec.Gwei(1_000_000)
state.balances[builder_index] = value + spec.MIN_ACTIVATION_BALANCE

# Create a bid with value amount
signed_bid = prepare_signed_execution_payload_bid(
spec,
state,
builder_index=builder_index,
value=value,
slot=block.slot,
parent_block_root=block.parent_root,
)

block.body.signed_execution_payload_bid = signed_bid
yield "pre", state
yield "block", block
spec.process_block(state, block)
# Slash validator
spec.slash_validator(state, builder_index)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This state change would have to be after the post, but I think it is better to use another format that sorrounds the slashing

yield "post", state

payment_slot = spec.SLOTS_PER_EPOCH + (block.slot % spec.SLOTS_PER_EPOCH)
payment = state.builder_pending_payments[payment_slot]
assert payment.withdrawal.amount == value
assert payment.withdrawal.builder_index == builder_index


@with_gloas_and_later
@spec_state_test
Expand Down