From 84407b30333ed6e51ce50fe4af3bba808c08b3ad Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 23 Jun 2026 12:17:46 +1000 Subject: [PATCH] Update payload verif tests with correct prev_randao --- .../src/payload_bid_verification/tests.rs | 76 ++++++++++++++----- 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/beacon_node/beacon_chain/src/payload_bid_verification/tests.rs b/beacon_node/beacon_chain/src/payload_bid_verification/tests.rs index a11d466db3..feeb361319 100644 --- a/beacon_node/beacon_chain/src/payload_bid_verification/tests.rs +++ b/beacon_node/beacon_chain/src/payload_bid_verification/tests.rs @@ -1,5 +1,5 @@ +use std::assert_matches; use std::sync::Arc; - use std::time::Duration; use bls::{Keypair, PublicKeyBytes, Signature}; @@ -195,6 +195,36 @@ impl TestContext { } } + fn expected_prev_randao(&self) -> Hash256 { + let current_slot = self.slot_clock.now().expect("should read slot clock"); + let head = self.canonical_head.cached_head(); + *head + .snapshot + .beacon_state + .get_randao_mix(current_slot.epoch(E::slots_per_epoch())) + .expect("should read current epoch randao mix") + } + + fn make_signed_bid( + &self, + slot: Slot, + builder_index: u64, + fee_recipient: Address, + gas_limit: u64, + value: u64, + parent_block_root: Hash256, + ) -> Arc> { + make_signed_bid( + slot, + builder_index, + fee_recipient, + gas_limit, + value, + parent_block_root, + self.expected_prev_randao(), + ) + } + fn insert_non_canonical_block(&self) -> Hash256 { let shuffling_id = AttestationShufflingId { shuffling_epoch: Epoch::new(0), @@ -244,6 +274,7 @@ fn make_signed_bid( gas_limit: u64, value: u64, parent_block_root: Hash256, + prev_randao: Hash256, ) -> Arc> { Arc::new(SignedExecutionPayloadBid { message: ExecutionPayloadBid { @@ -253,6 +284,7 @@ fn make_signed_bid( gas_limit, value, parent_block_root, + prev_randao, ..ExecutionPayloadBid::default() }, signature: Signature::empty(), @@ -291,7 +323,7 @@ fn no_proposer_preferences_for_slot() { } let ctx = TestContext::new(); let gossip = ctx.gossip_ctx(); - let bid = make_signed_bid( + let bid = ctx.make_signed_bid( Slot::new(0), 0, Address::ZERO, @@ -317,7 +349,7 @@ fn builder_already_seen_for_slot() { let slot = Slot::new(1); seed_preferences(&ctx, slot, Address::ZERO, 30_000_000); - let bid = make_signed_bid(slot, 42, Address::ZERO, 30_000_000, 100, Hash256::ZERO); + let bid = ctx.make_signed_bid(slot, 42, Address::ZERO, 30_000_000, 100, Hash256::ZERO); let verified = GossipVerifiedPayloadBid { signed_bid: bid.clone(), }; @@ -344,11 +376,11 @@ fn bid_value_below_cached() { seed_preferences(&ctx, slot, Address::ZERO, 30_000_000); let high_bid = GossipVerifiedPayloadBid { - signed_bid: make_signed_bid(slot, 99, Address::ZERO, 30_000_000, 500, Hash256::ZERO), + signed_bid: ctx.make_signed_bid(slot, 99, Address::ZERO, 30_000_000, 500, Hash256::ZERO), }; ctx.bid_cache.insert_highest_bid(high_bid); - let low_bid = make_signed_bid(slot, 1, Address::ZERO, 30_000_000, 100, Hash256::ZERO); + let low_bid = ctx.make_signed_bid(slot, 1, Address::ZERO, 30_000_000, 100, Hash256::ZERO); let result = GossipVerifiedPayloadBid::new(low_bid, &gossip); assert!(matches!( result, @@ -366,7 +398,7 @@ fn invalid_bid_slot() { let slot = Slot::new(5); seed_preferences(&ctx, slot, Address::ZERO, 30_000_000); - let bid = make_signed_bid( + let bid = ctx.make_signed_bid( slot, 0, Address::ZERO, @@ -375,10 +407,7 @@ fn invalid_bid_slot() { ctx.genesis_block_root, ); let result = GossipVerifiedPayloadBid::new(bid, &gossip); - assert!(matches!( - result, - Err(PayloadBidError::InvalidBidSlot { .. }) - )); + assert_matches!(result, Err(PayloadBidError::InvalidBidSlot { .. })); } #[test] @@ -391,7 +420,7 @@ fn fee_recipient_mismatch() { let slot = Slot::new(1); seed_preferences(&ctx, slot, Address::repeat_byte(0xaa), 30_000_000); - let bid = make_signed_bid( + let bid = ctx.make_signed_bid( slot, 0, Address::ZERO, @@ -413,7 +442,7 @@ fn gas_limit_mismatch() { let slot = Slot::new(1); seed_preferences(&ctx, slot, Address::ZERO, 30_000_000); - let bid = make_signed_bid( + let bid = ctx.make_signed_bid( slot, 0, Address::ZERO, @@ -441,6 +470,7 @@ fn execution_payment_nonzero() { gas_limit: 30_000_000, execution_payment: 42, parent_block_root: ctx.genesis_block_root, + prev_randao: ctx.expected_prev_randao(), ..ExecutionPayloadBid::default() }, signature: Signature::empty(), @@ -463,7 +493,7 @@ fn unknown_builder_index() { seed_preferences(&ctx, slot, Address::ZERO, 30_000_000); // Use a builder_index that doesn't exist in the registry. - let bid = make_signed_bid( + let bid = ctx.make_signed_bid( slot, 9999, Address::ZERO, @@ -490,7 +520,7 @@ fn inactive_builder() { let slot = Slot::new(1); seed_preferences(&ctx, slot, Address::ZERO, 30_000_000); - let bid = make_signed_bid( + let bid = ctx.make_signed_bid( slot, ctx.inactive_builder_index, Address::ZERO, @@ -516,7 +546,7 @@ fn builder_cant_cover_bid() { seed_preferences(&ctx, slot, Address::ZERO, 30_000_000); // Builder index 0 exists but bid value far exceeds their balance. - let bid = make_signed_bid( + let bid = ctx.make_signed_bid( slot, 0, Address::ZERO, @@ -543,7 +573,7 @@ fn parent_block_root_unknown() { // Parent block root not in fork choice. let unknown_root = Hash256::repeat_byte(0xff); - let bid = make_signed_bid(slot, 0, Address::ZERO, 30_000_000, 0, unknown_root); + let bid = ctx.make_signed_bid(slot, 0, Address::ZERO, 30_000_000, 0, unknown_root); let result = GossipVerifiedPayloadBid::new(bid, &gossip); assert!(result.is_err(), "expected error, got Ok"); let err = result.unwrap_err(); @@ -566,7 +596,7 @@ fn parent_block_root_not_canonical() { seed_preferences(&ctx, slot, Address::ZERO, 30_000_000); let fork_root = ctx.insert_non_canonical_block(); - let bid = make_signed_bid(slot, 0, Address::ZERO, 30_000_000, 0, fork_root); + let bid = ctx.make_signed_bid(slot, 0, Address::ZERO, 30_000_000, 0, fork_root); let result = GossipVerifiedPayloadBid::new(bid, &gossip); assert!(result.is_err(), "expected error, got Ok"); let err = result.unwrap_err(); @@ -588,7 +618,7 @@ fn bid_slot_not_after_parent() { let slot = Slot::new(0); seed_preferences(&ctx, slot, Address::ZERO, 30_000_000); - let bid = make_signed_bid( + let bid = ctx.make_signed_bid( slot, 0, Address::ZERO, @@ -631,6 +661,7 @@ fn invalid_blob_kzg_commitments() { gas_limit: 30_000_000, value: 0, parent_block_root: ctx.genesis_block_root, + prev_randao: ctx.expected_prev_randao(), blob_kzg_commitments: VariableList::new(commitments).unwrap(), ..ExecutionPayloadBid::default() }, @@ -654,7 +685,7 @@ fn bad_signature() { seed_preferences(&ctx, slot, Address::ZERO, 30_000_000); // All checks pass but signature is empty/invalid. - let bid = make_signed_bid( + let bid = ctx.make_signed_bid( slot, 0, Address::ZERO, @@ -689,6 +720,7 @@ fn valid_bid() { gas_limit: 30_000_000, value: 0, parent_block_root: ctx.genesis_block_root, + prev_randao: ctx.expected_prev_randao(), ..ExecutionPayloadBid::default() }); let result = GossipVerifiedPayloadBid::new(bid, &gossip); @@ -716,6 +748,7 @@ fn two_builders_coexist_in_cache() { gas_limit: 30_000_000, value: 0, parent_block_root: ctx.genesis_block_root, + prev_randao: ctx.expected_prev_randao(), ..ExecutionPayloadBid::default() }); let result_0 = GossipVerifiedPayloadBid::new(bid_0, &gossip); @@ -733,6 +766,7 @@ fn two_builders_coexist_in_cache() { gas_limit: 30_000_000, value: 1, parent_block_root: ctx.genesis_block_root, + prev_randao: ctx.expected_prev_randao(), ..ExecutionPayloadBid::default() }); let result_1 = GossipVerifiedPayloadBid::new(bid_1, &gossip); @@ -766,7 +800,7 @@ fn bid_equal_to_cached_value_rejected() { // Seed a cached bid with value 100. let high_bid = GossipVerifiedPayloadBid { - signed_bid: make_signed_bid( + signed_bid: ctx.make_signed_bid( slot, 99, Address::ZERO, @@ -778,7 +812,7 @@ fn bid_equal_to_cached_value_rejected() { ctx.bid_cache.insert_highest_bid(high_bid); // Submit a bid with exactly the same value — should be rejected. - let equal_bid = make_signed_bid( + let equal_bid = ctx.make_signed_bid( slot, 1, Address::ZERO,