mirror of
https://github.com/sigp/lighthouse.git
synced 2026-07-04 05:14:33 +00:00
Update payload verif tests with correct prev_randao
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
|
use std::assert_matches;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use bls::{Keypair, PublicKeyBytes, Signature};
|
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<SignedExecutionPayloadBid<E>> {
|
||||||
|
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 {
|
fn insert_non_canonical_block(&self) -> Hash256 {
|
||||||
let shuffling_id = AttestationShufflingId {
|
let shuffling_id = AttestationShufflingId {
|
||||||
shuffling_epoch: Epoch::new(0),
|
shuffling_epoch: Epoch::new(0),
|
||||||
@@ -244,6 +274,7 @@ fn make_signed_bid(
|
|||||||
gas_limit: u64,
|
gas_limit: u64,
|
||||||
value: u64,
|
value: u64,
|
||||||
parent_block_root: Hash256,
|
parent_block_root: Hash256,
|
||||||
|
prev_randao: Hash256,
|
||||||
) -> Arc<SignedExecutionPayloadBid<E>> {
|
) -> Arc<SignedExecutionPayloadBid<E>> {
|
||||||
Arc::new(SignedExecutionPayloadBid {
|
Arc::new(SignedExecutionPayloadBid {
|
||||||
message: ExecutionPayloadBid {
|
message: ExecutionPayloadBid {
|
||||||
@@ -253,6 +284,7 @@ fn make_signed_bid(
|
|||||||
gas_limit,
|
gas_limit,
|
||||||
value,
|
value,
|
||||||
parent_block_root,
|
parent_block_root,
|
||||||
|
prev_randao,
|
||||||
..ExecutionPayloadBid::default()
|
..ExecutionPayloadBid::default()
|
||||||
},
|
},
|
||||||
signature: Signature::empty(),
|
signature: Signature::empty(),
|
||||||
@@ -291,7 +323,7 @@ fn no_proposer_preferences_for_slot() {
|
|||||||
}
|
}
|
||||||
let ctx = TestContext::new();
|
let ctx = TestContext::new();
|
||||||
let gossip = ctx.gossip_ctx();
|
let gossip = ctx.gossip_ctx();
|
||||||
let bid = make_signed_bid(
|
let bid = ctx.make_signed_bid(
|
||||||
Slot::new(0),
|
Slot::new(0),
|
||||||
0,
|
0,
|
||||||
Address::ZERO,
|
Address::ZERO,
|
||||||
@@ -317,7 +349,7 @@ fn builder_already_seen_for_slot() {
|
|||||||
let slot = Slot::new(1);
|
let slot = Slot::new(1);
|
||||||
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
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 {
|
let verified = GossipVerifiedPayloadBid {
|
||||||
signed_bid: bid.clone(),
|
signed_bid: bid.clone(),
|
||||||
};
|
};
|
||||||
@@ -344,11 +376,11 @@ fn bid_value_below_cached() {
|
|||||||
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
||||||
|
|
||||||
let high_bid = GossipVerifiedPayloadBid {
|
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);
|
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);
|
let result = GossipVerifiedPayloadBid::new(low_bid, &gossip);
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
result,
|
result,
|
||||||
@@ -366,7 +398,7 @@ fn invalid_bid_slot() {
|
|||||||
let slot = Slot::new(5);
|
let slot = Slot::new(5);
|
||||||
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
||||||
|
|
||||||
let bid = make_signed_bid(
|
let bid = ctx.make_signed_bid(
|
||||||
slot,
|
slot,
|
||||||
0,
|
0,
|
||||||
Address::ZERO,
|
Address::ZERO,
|
||||||
@@ -375,10 +407,7 @@ fn invalid_bid_slot() {
|
|||||||
ctx.genesis_block_root,
|
ctx.genesis_block_root,
|
||||||
);
|
);
|
||||||
let result = GossipVerifiedPayloadBid::new(bid, &gossip);
|
let result = GossipVerifiedPayloadBid::new(bid, &gossip);
|
||||||
assert!(matches!(
|
assert_matches!(result, Err(PayloadBidError::InvalidBidSlot { .. }));
|
||||||
result,
|
|
||||||
Err(PayloadBidError::InvalidBidSlot { .. })
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -391,7 +420,7 @@ fn fee_recipient_mismatch() {
|
|||||||
let slot = Slot::new(1);
|
let slot = Slot::new(1);
|
||||||
seed_preferences(&ctx, slot, Address::repeat_byte(0xaa), 30_000_000);
|
seed_preferences(&ctx, slot, Address::repeat_byte(0xaa), 30_000_000);
|
||||||
|
|
||||||
let bid = make_signed_bid(
|
let bid = ctx.make_signed_bid(
|
||||||
slot,
|
slot,
|
||||||
0,
|
0,
|
||||||
Address::ZERO,
|
Address::ZERO,
|
||||||
@@ -413,7 +442,7 @@ fn gas_limit_mismatch() {
|
|||||||
let slot = Slot::new(1);
|
let slot = Slot::new(1);
|
||||||
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
||||||
|
|
||||||
let bid = make_signed_bid(
|
let bid = ctx.make_signed_bid(
|
||||||
slot,
|
slot,
|
||||||
0,
|
0,
|
||||||
Address::ZERO,
|
Address::ZERO,
|
||||||
@@ -441,6 +470,7 @@ fn execution_payment_nonzero() {
|
|||||||
gas_limit: 30_000_000,
|
gas_limit: 30_000_000,
|
||||||
execution_payment: 42,
|
execution_payment: 42,
|
||||||
parent_block_root: ctx.genesis_block_root,
|
parent_block_root: ctx.genesis_block_root,
|
||||||
|
prev_randao: ctx.expected_prev_randao(),
|
||||||
..ExecutionPayloadBid::default()
|
..ExecutionPayloadBid::default()
|
||||||
},
|
},
|
||||||
signature: Signature::empty(),
|
signature: Signature::empty(),
|
||||||
@@ -463,7 +493,7 @@ fn unknown_builder_index() {
|
|||||||
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
||||||
|
|
||||||
// Use a builder_index that doesn't exist in the registry.
|
// Use a builder_index that doesn't exist in the registry.
|
||||||
let bid = make_signed_bid(
|
let bid = ctx.make_signed_bid(
|
||||||
slot,
|
slot,
|
||||||
9999,
|
9999,
|
||||||
Address::ZERO,
|
Address::ZERO,
|
||||||
@@ -490,7 +520,7 @@ fn inactive_builder() {
|
|||||||
let slot = Slot::new(1);
|
let slot = Slot::new(1);
|
||||||
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
||||||
|
|
||||||
let bid = make_signed_bid(
|
let bid = ctx.make_signed_bid(
|
||||||
slot,
|
slot,
|
||||||
ctx.inactive_builder_index,
|
ctx.inactive_builder_index,
|
||||||
Address::ZERO,
|
Address::ZERO,
|
||||||
@@ -516,7 +546,7 @@ fn builder_cant_cover_bid() {
|
|||||||
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
||||||
|
|
||||||
// Builder index 0 exists but bid value far exceeds their balance.
|
// Builder index 0 exists but bid value far exceeds their balance.
|
||||||
let bid = make_signed_bid(
|
let bid = ctx.make_signed_bid(
|
||||||
slot,
|
slot,
|
||||||
0,
|
0,
|
||||||
Address::ZERO,
|
Address::ZERO,
|
||||||
@@ -543,7 +573,7 @@ fn parent_block_root_unknown() {
|
|||||||
|
|
||||||
// Parent block root not in fork choice.
|
// Parent block root not in fork choice.
|
||||||
let unknown_root = Hash256::repeat_byte(0xff);
|
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);
|
let result = GossipVerifiedPayloadBid::new(bid, &gossip);
|
||||||
assert!(result.is_err(), "expected error, got Ok");
|
assert!(result.is_err(), "expected error, got Ok");
|
||||||
let err = result.unwrap_err();
|
let err = result.unwrap_err();
|
||||||
@@ -566,7 +596,7 @@ fn parent_block_root_not_canonical() {
|
|||||||
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
||||||
|
|
||||||
let fork_root = ctx.insert_non_canonical_block();
|
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);
|
let result = GossipVerifiedPayloadBid::new(bid, &gossip);
|
||||||
assert!(result.is_err(), "expected error, got Ok");
|
assert!(result.is_err(), "expected error, got Ok");
|
||||||
let err = result.unwrap_err();
|
let err = result.unwrap_err();
|
||||||
@@ -588,7 +618,7 @@ fn bid_slot_not_after_parent() {
|
|||||||
let slot = Slot::new(0);
|
let slot = Slot::new(0);
|
||||||
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
||||||
|
|
||||||
let bid = make_signed_bid(
|
let bid = ctx.make_signed_bid(
|
||||||
slot,
|
slot,
|
||||||
0,
|
0,
|
||||||
Address::ZERO,
|
Address::ZERO,
|
||||||
@@ -631,6 +661,7 @@ fn invalid_blob_kzg_commitments() {
|
|||||||
gas_limit: 30_000_000,
|
gas_limit: 30_000_000,
|
||||||
value: 0,
|
value: 0,
|
||||||
parent_block_root: ctx.genesis_block_root,
|
parent_block_root: ctx.genesis_block_root,
|
||||||
|
prev_randao: ctx.expected_prev_randao(),
|
||||||
blob_kzg_commitments: VariableList::new(commitments).unwrap(),
|
blob_kzg_commitments: VariableList::new(commitments).unwrap(),
|
||||||
..ExecutionPayloadBid::default()
|
..ExecutionPayloadBid::default()
|
||||||
},
|
},
|
||||||
@@ -654,7 +685,7 @@ fn bad_signature() {
|
|||||||
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
seed_preferences(&ctx, slot, Address::ZERO, 30_000_000);
|
||||||
|
|
||||||
// All checks pass but signature is empty/invalid.
|
// All checks pass but signature is empty/invalid.
|
||||||
let bid = make_signed_bid(
|
let bid = ctx.make_signed_bid(
|
||||||
slot,
|
slot,
|
||||||
0,
|
0,
|
||||||
Address::ZERO,
|
Address::ZERO,
|
||||||
@@ -689,6 +720,7 @@ fn valid_bid() {
|
|||||||
gas_limit: 30_000_000,
|
gas_limit: 30_000_000,
|
||||||
value: 0,
|
value: 0,
|
||||||
parent_block_root: ctx.genesis_block_root,
|
parent_block_root: ctx.genesis_block_root,
|
||||||
|
prev_randao: ctx.expected_prev_randao(),
|
||||||
..ExecutionPayloadBid::default()
|
..ExecutionPayloadBid::default()
|
||||||
});
|
});
|
||||||
let result = GossipVerifiedPayloadBid::new(bid, &gossip);
|
let result = GossipVerifiedPayloadBid::new(bid, &gossip);
|
||||||
@@ -716,6 +748,7 @@ fn two_builders_coexist_in_cache() {
|
|||||||
gas_limit: 30_000_000,
|
gas_limit: 30_000_000,
|
||||||
value: 0,
|
value: 0,
|
||||||
parent_block_root: ctx.genesis_block_root,
|
parent_block_root: ctx.genesis_block_root,
|
||||||
|
prev_randao: ctx.expected_prev_randao(),
|
||||||
..ExecutionPayloadBid::default()
|
..ExecutionPayloadBid::default()
|
||||||
});
|
});
|
||||||
let result_0 = GossipVerifiedPayloadBid::new(bid_0, &gossip);
|
let result_0 = GossipVerifiedPayloadBid::new(bid_0, &gossip);
|
||||||
@@ -733,6 +766,7 @@ fn two_builders_coexist_in_cache() {
|
|||||||
gas_limit: 30_000_000,
|
gas_limit: 30_000_000,
|
||||||
value: 1,
|
value: 1,
|
||||||
parent_block_root: ctx.genesis_block_root,
|
parent_block_root: ctx.genesis_block_root,
|
||||||
|
prev_randao: ctx.expected_prev_randao(),
|
||||||
..ExecutionPayloadBid::default()
|
..ExecutionPayloadBid::default()
|
||||||
});
|
});
|
||||||
let result_1 = GossipVerifiedPayloadBid::new(bid_1, &gossip);
|
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.
|
// Seed a cached bid with value 100.
|
||||||
let high_bid = GossipVerifiedPayloadBid {
|
let high_bid = GossipVerifiedPayloadBid {
|
||||||
signed_bid: make_signed_bid(
|
signed_bid: ctx.make_signed_bid(
|
||||||
slot,
|
slot,
|
||||||
99,
|
99,
|
||||||
Address::ZERO,
|
Address::ZERO,
|
||||||
@@ -778,7 +812,7 @@ fn bid_equal_to_cached_value_rejected() {
|
|||||||
ctx.bid_cache.insert_highest_bid(high_bid);
|
ctx.bid_cache.insert_highest_bid(high_bid);
|
||||||
|
|
||||||
// Submit a bid with exactly the same value — should be rejected.
|
// 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,
|
slot,
|
||||||
1,
|
1,
|
||||||
Address::ZERO,
|
Address::ZERO,
|
||||||
|
|||||||
Reference in New Issue
Block a user