|
| 1 | +import random |
| 2 | +from eth2spec.test.helpers.state import next_epoch |
| 3 | + |
| 4 | +from eth2spec.test.helpers.attestations import get_valid_attestation |
| 5 | + |
1 | 6 | from eth2spec.test.context import ( |
2 | 7 | always_bls, |
3 | 8 | spec_state_test, |
|
9 | 14 | set_builder_withdrawal_credential, |
10 | 15 | set_builder_withdrawal_credential_with_balance, |
11 | 16 | ) |
| 17 | +from eth2spec.test.helpers.execution_payload import build_empty_execution_payload |
12 | 18 |
|
13 | 19 |
|
14 | 20 | def run_execution_payload_bid_processing(spec, state, block, valid=True): |
@@ -348,6 +354,45 @@ def test_process_execution_payload_bid_slashed_builder(spec, state): |
348 | 354 |
|
349 | 355 | yield from run_execution_payload_bid_processing(spec, state, block, valid=False) |
350 | 356 |
|
| 357 | +@with_gloas_and_later |
| 358 | +@spec_state_test |
| 359 | +def test_process_block_then_slash_non_timely_builder(spec, state): |
| 360 | + """ |
| 361 | + Empty-case payment path: |
| 362 | + - A builder posts a successful bid in a block, but the payload is not revealed in time. |
| 363 | + - Builder is slashed |
| 364 | + - Proposer unconditional payment is enforced by moving the bid amount into |
| 365 | + """ |
| 366 | + |
| 367 | + # Get past genesis |
| 368 | + next_epoch(spec, state) |
| 369 | + next_epoch(spec, state) |
| 370 | + |
| 371 | + block, builder_index = prepare_block_with_non_proposer_builder(spec, state) |
| 372 | + |
| 373 | + value = spec.Gwei(1_000_000) |
| 374 | + state.balances[builder_index] = value + spec.MIN_ACTIVATION_BALANCE |
| 375 | + |
| 376 | + # Create a bid with value amount |
| 377 | + signed_bid = prepare_signed_execution_payload_bid( |
| 378 | + spec, |
| 379 | + state, |
| 380 | + builder_index=builder_index, |
| 381 | + value=value, |
| 382 | + slot=block.slot, |
| 383 | + parent_block_root=block.parent_root, |
| 384 | + ) |
| 385 | + |
| 386 | + block.body.signed_execution_payload_bid = signed_bid |
| 387 | + spec.process_block(state, block) |
| 388 | + # Slash validator |
| 389 | + spec.slash_validator(state, builder_index) |
| 390 | + |
| 391 | + payment_slot = spec.SLOTS_PER_EPOCH + (block.slot % spec.SLOTS_PER_EPOCH) |
| 392 | + payment = state.builder_pending_payments[payment_slot] |
| 393 | + assert payment.withdrawal.amount == value |
| 394 | + assert payment.withdrawal.builder_index == builder_index |
| 395 | + |
351 | 396 |
|
352 | 397 | @with_gloas_and_later |
353 | 398 | @spec_state_test |
|
0 commit comments