mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-30 20:57:10 +00:00
Electra: Remaining Consensus Data Structures (#5712)
* Attestation superstruct changes for EIP 7549 (#5644)
* update
* experiment
* superstruct changes
* revert
* superstruct changes
* fix tests
* indexed attestation
* indexed attestation superstruct
* updated TODOs
* `superstruct` the `AttesterSlashing` (#5636)
* `superstruct` Attester Fork Variants
* Push a little further
* Deal with Encode / Decode of AttesterSlashing
* not so sure about this..
* Stop Encode/Decode Bounds from Propagating Out
* Tons of Changes..
* More Conversions to AttestationRef
* Add AsReference trait (#15)
* Add AsReference trait
* Fix some snafus
* Got it Compiling! :D
* Got Tests Building
* Get beacon chain tests compiling
---------
Co-authored-by: Michael Sproul <micsproul@gmail.com>
* Merge remote-tracking branch 'upstream/unstable' into electra_attestation_changes
* Make EF Tests Fork-Agnostic (#5713)
* Finish EF Test Fork Agnostic (#5714)
* Superstruct `AggregateAndProof` (#5715)
* Upgrade `superstruct` to `0.8.0`
* superstruct `AggregateAndProof`
* Merge remote-tracking branch 'sigp/unstable' into electra_attestation_changes
* cargo fmt
* Merge pull request #5726 from realbigsean/electra_attestation_changes
Merge unstable into Electra attestation changes
* EIP7549 `get_attestation_indices` (#5657)
* get attesting indices electra impl
* fmt
* get tests to pass
* fmt
* fix some beacon chain tests
* fmt
* fix slasher test
* fmt got me again
* fix more tests
* fix tests
* Some small changes (#5739)
* cargo fmt (#5740)
* Sketch op pool changes
* fix get attesting indices (#5742)
* fix get attesting indices
* better errors
* fix compile
* only get committee index once
* Ef test fixes (#5753)
* attestation related ef test fixes
* delete commented out stuff
* Fix Aggregation Pool for Electra (#5754)
* Fix Aggregation Pool for Electra
* Remove Outdated Interface
* fix ssz (#5755)
* Get `electra_op_pool` up to date (#5756)
* fix get attesting indices (#5742)
* fix get attesting indices
* better errors
* fix compile
* only get committee index once
* Ef test fixes (#5753)
* attestation related ef test fixes
* delete commented out stuff
* Fix Aggregation Pool for Electra (#5754)
* Fix Aggregation Pool for Electra
* Remove Outdated Interface
* fix ssz (#5755)
---------
Co-authored-by: realbigsean <sean@sigmaprime.io>
* Revert "Get `electra_op_pool` up to date (#5756)" (#5757)
This reverts commit ab9e58aa3d.
* Merge branch 'electra_attestation_changes' of https://github.com/sigp/lighthouse into electra_op_pool
* Compute on chain aggregate impl (#5752)
* add compute_on_chain_agg impl to op pool changes
* fmt
* get op pool tests to pass
* update the naive agg pool interface (#5760)
* Fix bugs in cross-committee aggregation
* Add comment to max cover optimisation
* Fix assert
* Merge pull request #5749 from sigp/electra_op_pool
Optimise Electra op pool aggregation
* update committee offset
* Fix Electra Fork Choice Tests (#5764)
* Subscribe to the correct subnets for electra attestations (#5782)
* subscribe to the correct att subnets for electra
* subscribe to the correct att subnets for electra
* cargo fmt
* fix slashing handling
* Merge remote-tracking branch 'upstream/unstable'
* Send unagg attestation based on fork
* Publish all aggregates
* just one more check bro plz..
* Merge pull request #5832 from ethDreamer/electra_attestation_changes_merge_unstable
Merge `unstable` into `electra_attestation_changes`
* Merge pull request #5835 from realbigsean/fix-validator-logic
Fix validator logic
* Merge pull request #5816 from realbigsean/electra-attestation-slashing-handling
Electra slashing handling
* Electra attestation changes rm decode impl (#5856)
* Remove Crappy Decode impl for Attestation
* Remove Inefficient Attestation Decode impl
* Implement Schema Upgrade / Downgrade
* Update beacon_node/beacon_chain/src/schema_change/migration_schema_v20.rs
Co-authored-by: Michael Sproul <micsproul@gmail.com>
---------
Co-authored-by: Michael Sproul <micsproul@gmail.com>
* Fix failing attestation tests and misc electra attestation cleanup (#5810)
* - get attestation related beacon chain tests to pass
- observed attestations are now keyed off of data + committee index
- rename op pool attestationref to compactattestationref
- remove unwraps in agg pool and use options instead
- cherry pick some changes from ef-tests-electra
* cargo fmt
* fix failing test
* Revert dockerfile changes
* make committee_index return option
* function args shouldnt be a ref to attestation ref
* fmt
* fix dup imports
---------
Co-authored-by: realbigsean <seananderson33@GMAIL.com>
* fix some todos (#5817)
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into electra_attestation_changes
* add consolidations to merkle calc for inclusion proof
* Remove Duplicate KZG Commitment Merkle Proof Code (#5874)
* Remove Duplicate KZG Commitment Merkle Proof Code
* s/tree_lists/fields/
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into electra_attestation_changes
* fix compile
* Fix slasher tests (#5906)
* Fix electra tests
* Add electra attestations to double vote tests
* Update superstruct to 0.8
* Merge remote-tracking branch 'origin/unstable' into electra_attestation_changes
* Small cleanup in slasher tests
* Clean up Electra observed aggregates (#5929)
* Use consistent key in observed_attestations
* Remove unwraps from observed aggregates
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into electra_attestation_changes
* De-dup attestation constructor logic
* Remove unwraps in Attestation construction
* Dedup match_attestation_data
* Remove outdated TODO
* Use ForkName Ord in fork-choice tests
* Use ForkName Ord in BeaconBlockBody
* Make to_electra not fallible
* Remove TestRandom impl for IndexedAttestation
* Remove IndexedAttestation faulty Decode impl
* Drop TestRandom impl
* Add PendingAttestationInElectra
* Indexed att on disk (#35)
* indexed att on disk
* fix lints
* Update slasher/src/migrate.rs
Co-authored-by: ethDreamer <37123614+ethDreamer@users.noreply.github.com>
---------
Co-authored-by: Lion - dapplion <35266934+dapplion@users.noreply.github.com>
Co-authored-by: ethDreamer <37123614+ethDreamer@users.noreply.github.com>
* add electra fork enabled fn to ForkName impl (#36)
* add electra fork enabled fn to ForkName impl
* remove inadvertent file
* Update common/eth2/src/types.rs
Co-authored-by: ethDreamer <37123614+ethDreamer@users.noreply.github.com>
* Dedup attestation constructor logic in attester cache
* Use if let Ok for committee_bits
* Dedup Attestation constructor code
* Diff reduction in tests
* Fix beacon_chain tests
* Diff reduction
* Use Ord for ForkName in pubsub
* Resolve into_attestation_and_indices todo
* Remove stale TODO
* Fix beacon_chain tests
* Test spec invariant
* Use electra_enabled in pubsub
* Remove get_indexed_attestation_from_signed_aggregate
* Use ok_or instead of if let else
* committees are sorted
* remove dup method `get_indexed_attestation_from_committees`
* Merge pull request #5940 from dapplion/electra_attestation_changes_lionreview
Electra attestations #5712 review
* update default persisted op pool deserialization
* ensure aggregate and proof uses serde untagged on ref
* Fork aware ssz static attestation tests
* Electra attestation changes from Lions review (#5971)
* dedup/cleanup and remove unneeded hashset use
* remove irrelevant TODOs
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into electra_attestation_changes
* Electra attestation changes sean review (#5972)
* instantiate empty bitlist in unreachable code
* clean up error conversion
* fork enabled bool cleanup
* remove a couple todos
* return bools instead of options in `aggregate` and use the result
* delete commented out code
* use map macros in simple transformations
* remove signers_disjoint_from
* get ef tests compiling
* get ef tests compiling
* update intentionally excluded files
* Avoid changing slasher schema for Electra
* Delete slasher schema v4
* Fix clippy
* Fix compilation of beacon_chain tests
* Update database.rs
* Add electra lightclient types
* Update slasher/src/database.rs
* fix imports
* Merge pull request #5980 from dapplion/electra-lightclient
Add electra lightclient types
* Merge pull request #5975 from michaelsproul/electra-slasher-no-migration
Avoid changing slasher schema for Electra
* Update beacon_node/beacon_chain/src/attestation_verification.rs
* Update beacon_node/beacon_chain/src/attestation_verification.rs
This commit is contained in:
@@ -8,7 +8,9 @@ use beacon_chain::{metrics, StateSkipConfig, WhenSlotSkipped};
|
||||
use lazy_static::lazy_static;
|
||||
use std::sync::Arc;
|
||||
use tree_hash::TreeHash;
|
||||
use types::{AggregateSignature, EthSpec, Keypair, MainnetEthSpec, RelativeEpoch, Slot};
|
||||
use types::{
|
||||
AggregateSignature, Attestation, EthSpec, Keypair, MainnetEthSpec, RelativeEpoch, Slot,
|
||||
};
|
||||
|
||||
pub const VALIDATOR_COUNT: usize = 16;
|
||||
|
||||
@@ -188,20 +190,22 @@ async fn produces_attestations() {
|
||||
.produce_unaggregated_attestation(slot, index)
|
||||
.expect("should produce attestation");
|
||||
|
||||
let data = &attestation.data;
|
||||
let (aggregation_bits_len, aggregation_bits_zero) = match &attestation {
|
||||
Attestation::Base(att) => {
|
||||
(att.aggregation_bits.len(), att.aggregation_bits.is_zero())
|
||||
}
|
||||
Attestation::Electra(att) => {
|
||||
(att.aggregation_bits.len(), att.aggregation_bits.is_zero())
|
||||
}
|
||||
};
|
||||
assert_eq!(aggregation_bits_len, committee_len, "bad committee len");
|
||||
assert!(aggregation_bits_zero, "some committee bits are set");
|
||||
|
||||
let data = attestation.data();
|
||||
|
||||
assert_eq!(
|
||||
attestation.aggregation_bits.len(),
|
||||
committee_len,
|
||||
"bad committee len"
|
||||
);
|
||||
assert!(
|
||||
attestation.aggregation_bits.is_zero(),
|
||||
"some committee bits are set"
|
||||
);
|
||||
assert_eq!(
|
||||
attestation.signature,
|
||||
AggregateSignature::empty(),
|
||||
attestation.signature(),
|
||||
&AggregateSignature::infinity(),
|
||||
"bad signature"
|
||||
);
|
||||
assert_eq!(data.index, index, "bad index");
|
||||
@@ -329,10 +333,10 @@ async fn early_attester_cache_old_request() {
|
||||
.produce_unaggregated_attestation(attest_slot, 0)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(attestation.data.slot, attest_slot);
|
||||
assert_eq!(attestation.data().slot, attest_slot);
|
||||
let attested_block = harness
|
||||
.chain
|
||||
.get_blinded_block(&attestation.data.beacon_block_root)
|
||||
.get_blinded_block(&attestation.data().beacon_block_root)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(attested_block.slot(), attest_slot);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use beacon_chain::attestation_verification::{
|
||||
batch_verify_aggregated_attestations, batch_verify_unaggregated_attestations, Error,
|
||||
};
|
||||
use beacon_chain::observed_aggregates::ObservedAttestationKey;
|
||||
use beacon_chain::test_utils::{MakeAttestationOptions, HARNESS_GENESIS_TIME};
|
||||
use beacon_chain::{
|
||||
attestation_verification::Error as AttnError,
|
||||
@@ -14,14 +15,17 @@ use beacon_chain::{
|
||||
use genesis::{interop_genesis_state, DEFAULT_ETH1_BLOCK_HASH};
|
||||
use int_to_bytes::int_to_bytes32;
|
||||
use lazy_static::lazy_static;
|
||||
use ssz_types::BitVector;
|
||||
use state_processing::{
|
||||
per_block_processing::errors::AttestationValidationError, per_slot_processing,
|
||||
};
|
||||
use tree_hash::TreeHash;
|
||||
use types::{
|
||||
signed_aggregate_and_proof::SignedAggregateAndProofRefMut,
|
||||
test_utils::generate_deterministic_keypair, Address, AggregateSignature, Attestation,
|
||||
BeaconStateError, BitList, ChainSpec, Epoch, EthSpec, ForkName, Hash256, Keypair,
|
||||
MainnetEthSpec, SecretKey, SelectionProof, SignedAggregateAndProof, Slot, SubnetId, Unsigned,
|
||||
AttestationRef, AttestationRefMut, BeaconStateError, BitList, ChainSpec, Epoch, EthSpec,
|
||||
ForkName, Hash256, Keypair, MainnetEthSpec, SecretKey, SelectionProof, SignedAggregateAndProof,
|
||||
Slot, SubnetId, Unsigned,
|
||||
};
|
||||
|
||||
pub type E = MainnetEthSpec;
|
||||
@@ -125,7 +129,12 @@ fn get_valid_unaggregated_attestation<T: BeaconChainTypes>(
|
||||
let validator_committee_index = 0;
|
||||
let validator_index = *head
|
||||
.beacon_state
|
||||
.get_beacon_committee(current_slot, valid_attestation.data.index)
|
||||
.get_beacon_committee(
|
||||
current_slot,
|
||||
valid_attestation
|
||||
.committee_index()
|
||||
.expect("should get committee index"),
|
||||
)
|
||||
.expect("should get committees")
|
||||
.committee
|
||||
.get(validator_committee_index)
|
||||
@@ -143,8 +152,8 @@ fn get_valid_unaggregated_attestation<T: BeaconChainTypes>(
|
||||
)
|
||||
.expect("should sign attestation");
|
||||
|
||||
let subnet_id = SubnetId::compute_subnet_for_attestation_data::<E>(
|
||||
&valid_attestation.data,
|
||||
let subnet_id = SubnetId::compute_subnet_for_attestation::<T::EthSpec>(
|
||||
valid_attestation.to_ref(),
|
||||
head.beacon_state
|
||||
.get_committee_count_at_slot(current_slot)
|
||||
.expect("should get committee count"),
|
||||
@@ -170,7 +179,12 @@ fn get_valid_aggregated_attestation<T: BeaconChainTypes>(
|
||||
let current_slot = chain.slot().expect("should get slot");
|
||||
|
||||
let committee = state
|
||||
.get_beacon_committee(current_slot, aggregate.data.index)
|
||||
.get_beacon_committee(
|
||||
current_slot,
|
||||
aggregate
|
||||
.committee_index()
|
||||
.expect("should get committee index"),
|
||||
)
|
||||
.expect("should get committees");
|
||||
let committee_len = committee.committee.len();
|
||||
|
||||
@@ -181,7 +195,7 @@ fn get_valid_aggregated_attestation<T: BeaconChainTypes>(
|
||||
let aggregator_sk = generate_deterministic_keypair(val_index).sk;
|
||||
|
||||
let proof = SelectionProof::new::<T::EthSpec>(
|
||||
aggregate.data.slot,
|
||||
aggregate.data().slot,
|
||||
&aggregator_sk,
|
||||
&state.fork(),
|
||||
chain.genesis_validators_root,
|
||||
@@ -198,7 +212,7 @@ fn get_valid_aggregated_attestation<T: BeaconChainTypes>(
|
||||
|
||||
let signed_aggregate = SignedAggregateAndProof::from_aggregate(
|
||||
aggregator_index as u64,
|
||||
aggregate,
|
||||
aggregate.to_ref(),
|
||||
None,
|
||||
&aggregator_sk,
|
||||
&state.fork(),
|
||||
@@ -213,14 +227,19 @@ fn get_valid_aggregated_attestation<T: BeaconChainTypes>(
|
||||
/// attestation.
|
||||
fn get_non_aggregator<T: BeaconChainTypes>(
|
||||
chain: &BeaconChain<T>,
|
||||
aggregate: &Attestation<T::EthSpec>,
|
||||
aggregate: AttestationRef<T::EthSpec>,
|
||||
) -> (usize, SecretKey) {
|
||||
let head = chain.head_snapshot();
|
||||
let state = &head.beacon_state;
|
||||
let current_slot = chain.slot().expect("should get slot");
|
||||
|
||||
let committee = state
|
||||
.get_beacon_committee(current_slot, aggregate.data.index)
|
||||
.get_beacon_committee(
|
||||
current_slot,
|
||||
aggregate
|
||||
.committee_index()
|
||||
.expect("should get committee index"),
|
||||
)
|
||||
.expect("should get committees");
|
||||
let committee_len = committee.committee.len();
|
||||
|
||||
@@ -231,7 +250,7 @@ fn get_non_aggregator<T: BeaconChainTypes>(
|
||||
let aggregator_sk = generate_deterministic_keypair(val_index).sk;
|
||||
|
||||
let proof = SelectionProof::new::<T::EthSpec>(
|
||||
aggregate.data.slot,
|
||||
aggregate.data().slot,
|
||||
&aggregator_sk,
|
||||
&state.fork(),
|
||||
chain.genesis_validators_root,
|
||||
@@ -301,15 +320,19 @@ impl GossipTester {
|
||||
get_valid_aggregated_attestation(&harness.chain, valid_attestation.clone());
|
||||
|
||||
let mut invalid_attestation = valid_attestation.clone();
|
||||
invalid_attestation.data.beacon_block_root = Hash256::repeat_byte(13);
|
||||
invalid_attestation.data_mut().beacon_block_root = Hash256::repeat_byte(13);
|
||||
|
||||
let (mut invalid_aggregate, _, _) =
|
||||
get_valid_aggregated_attestation(&harness.chain, invalid_attestation.clone());
|
||||
invalid_aggregate.message.aggregator_index = invalid_aggregate
|
||||
.message
|
||||
.aggregator_index
|
||||
.checked_sub(1)
|
||||
.unwrap();
|
||||
|
||||
match invalid_aggregate.to_mut() {
|
||||
SignedAggregateAndProofRefMut::Base(att) => {
|
||||
att.message.aggregator_index = att.message.aggregator_index.checked_sub(1).unwrap();
|
||||
}
|
||||
SignedAggregateAndProofRefMut::Electra(att) => {
|
||||
att.message.aggregator_index = att.message.aggregator_index.checked_sub(1).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Self {
|
||||
harness,
|
||||
@@ -361,7 +384,10 @@ impl GossipTester {
|
||||
}
|
||||
|
||||
pub fn non_aggregator(&self) -> (usize, SecretKey) {
|
||||
get_non_aggregator(&self.harness.chain, &self.valid_aggregate.message.aggregate)
|
||||
get_non_aggregator(
|
||||
&self.harness.chain,
|
||||
self.valid_aggregate.message().aggregate(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn import_valid_aggregate(self) -> Self {
|
||||
@@ -418,6 +444,7 @@ impl GossipTester {
|
||||
vec![&self.invalid_aggregate, &aggregate].into_iter(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(results.len(), 2);
|
||||
let batch_err = results.pop().unwrap().err().expect(&format!(
|
||||
"{} should error during batch_verify_aggregated_attestations_for_gossip",
|
||||
@@ -490,7 +517,14 @@ async fn aggregated_gossip_verification() {
|
||||
*/
|
||||
.inspect_aggregate_err(
|
||||
"aggregate from future slot",
|
||||
|tester, a| a.message.aggregate.data.slot = tester.slot() + 1,
|
||||
|tester, a| match a.to_mut() {
|
||||
SignedAggregateAndProofRefMut::Base(att) => {
|
||||
att.message.aggregate.data.slot = tester.slot() + 1
|
||||
}
|
||||
SignedAggregateAndProofRefMut::Electra(att) => {
|
||||
att.message.aggregate.data.slot = tester.slot() + 1
|
||||
}
|
||||
},
|
||||
|tester, err| {
|
||||
assert!(matches!(
|
||||
err,
|
||||
@@ -504,8 +538,18 @@ async fn aggregated_gossip_verification() {
|
||||
"aggregate from past slot",
|
||||
|tester, a| {
|
||||
let too_early_slot = tester.earliest_valid_attestation_slot() - 1;
|
||||
a.message.aggregate.data.slot = too_early_slot;
|
||||
a.message.aggregate.data.target.epoch = too_early_slot.epoch(E::slots_per_epoch());
|
||||
match a.to_mut() {
|
||||
SignedAggregateAndProofRefMut::Base(att) => {
|
||||
att.message.aggregate.data.slot = too_early_slot;
|
||||
att.message.aggregate.data.target.epoch =
|
||||
too_early_slot.epoch(E::slots_per_epoch());
|
||||
}
|
||||
SignedAggregateAndProofRefMut::Electra(att) => {
|
||||
att.message.aggregate.data.slot = too_early_slot;
|
||||
att.message.aggregate.data.target.epoch =
|
||||
too_early_slot.epoch(E::slots_per_epoch());
|
||||
}
|
||||
}
|
||||
},
|
||||
|tester, err| {
|
||||
let valid_early_slot = tester.earliest_valid_attestation_slot();
|
||||
@@ -529,7 +573,14 @@ async fn aggregated_gossip_verification() {
|
||||
*/
|
||||
.inspect_aggregate_err(
|
||||
"attestation with invalid target epoch",
|
||||
|_, a| a.message.aggregate.data.target.epoch += 1,
|
||||
|_, a| match a.to_mut() {
|
||||
SignedAggregateAndProofRefMut::Base(att) => {
|
||||
att.message.aggregate.data.target.epoch += 1
|
||||
}
|
||||
SignedAggregateAndProofRefMut::Electra(att) => {
|
||||
att.message.aggregate.data.target.epoch += 1
|
||||
}
|
||||
},
|
||||
|_, err| assert!(matches!(err, AttnError::InvalidTargetEpoch { .. })),
|
||||
)
|
||||
/*
|
||||
@@ -538,7 +589,14 @@ async fn aggregated_gossip_verification() {
|
||||
*/
|
||||
.inspect_aggregate_err(
|
||||
"attestation with invalid target root",
|
||||
|_, a| a.message.aggregate.data.target.root = Hash256::repeat_byte(42),
|
||||
|_, a| match a.to_mut() {
|
||||
SignedAggregateAndProofRefMut::Base(att) => {
|
||||
att.message.aggregate.data.target.root = Hash256::repeat_byte(42)
|
||||
}
|
||||
SignedAggregateAndProofRefMut::Electra(att) => {
|
||||
att.message.aggregate.data.target.root = Hash256::repeat_byte(42)
|
||||
}
|
||||
},
|
||||
|_, err| assert!(matches!(err, AttnError::InvalidTargetRoot { .. })),
|
||||
)
|
||||
/*
|
||||
@@ -548,7 +606,14 @@ async fn aggregated_gossip_verification() {
|
||||
*/
|
||||
.inspect_aggregate_err(
|
||||
"aggregate with unknown head block",
|
||||
|_, a| a.message.aggregate.data.beacon_block_root = Hash256::repeat_byte(42),
|
||||
|_, a| match a.to_mut() {
|
||||
SignedAggregateAndProofRefMut::Base(att) => {
|
||||
att.message.aggregate.data.beacon_block_root = Hash256::repeat_byte(42)
|
||||
}
|
||||
SignedAggregateAndProofRefMut::Electra(att) => {
|
||||
att.message.aggregate.data.beacon_block_root = Hash256::repeat_byte(42)
|
||||
}
|
||||
},
|
||||
|_, err| {
|
||||
assert!(matches!(
|
||||
err,
|
||||
@@ -566,11 +631,19 @@ async fn aggregated_gossip_verification() {
|
||||
*/
|
||||
.inspect_aggregate_err(
|
||||
"aggregate with no participants",
|
||||
|_, a| {
|
||||
let aggregation_bits = &mut a.message.aggregate.aggregation_bits;
|
||||
aggregation_bits.difference_inplace(&aggregation_bits.clone());
|
||||
assert!(aggregation_bits.is_zero());
|
||||
a.message.aggregate.signature = AggregateSignature::infinity();
|
||||
|_, a| match a.to_mut() {
|
||||
SignedAggregateAndProofRefMut::Base(att) => {
|
||||
let aggregation_bits = &mut att.message.aggregate.aggregation_bits;
|
||||
aggregation_bits.difference_inplace(&aggregation_bits.clone());
|
||||
assert!(aggregation_bits.is_zero());
|
||||
att.message.aggregate.signature = AggregateSignature::infinity()
|
||||
}
|
||||
SignedAggregateAndProofRefMut::Electra(att) => {
|
||||
let aggregation_bits = &mut att.message.aggregate.aggregation_bits;
|
||||
aggregation_bits.difference_inplace(&aggregation_bits.clone());
|
||||
assert!(aggregation_bits.is_zero());
|
||||
att.message.aggregate.signature = AggregateSignature::infinity()
|
||||
}
|
||||
},
|
||||
|_, err| assert!(matches!(err, AttnError::EmptyAggregationBitfield)),
|
||||
)
|
||||
@@ -581,7 +654,14 @@ async fn aggregated_gossip_verification() {
|
||||
*/
|
||||
.inspect_aggregate_err(
|
||||
"aggregate with bad signature",
|
||||
|tester, a| a.signature = tester.aggregator_sk.sign(Hash256::repeat_byte(42)),
|
||||
|tester, a| match a.to_mut() {
|
||||
SignedAggregateAndProofRefMut::Base(att) => {
|
||||
att.signature = tester.aggregator_sk.sign(Hash256::repeat_byte(42))
|
||||
}
|
||||
SignedAggregateAndProofRefMut::Electra(att) => {
|
||||
att.signature = tester.aggregator_sk.sign(Hash256::repeat_byte(42))
|
||||
}
|
||||
},
|
||||
|_, err| assert!(matches!(err, AttnError::InvalidSignature)),
|
||||
)
|
||||
/*
|
||||
@@ -598,7 +678,7 @@ async fn aggregated_gossip_verification() {
|
||||
.chain
|
||||
.head_snapshot()
|
||||
.beacon_state
|
||||
.get_beacon_committee(tester.slot(), a.message.aggregate.data.index)
|
||||
.get_beacon_committee(tester.slot(), a.message().aggregate().committee_index().expect("should get committee index"))
|
||||
.expect("should get committees")
|
||||
.committee
|
||||
.len();
|
||||
@@ -608,19 +688,38 @@ async fn aggregated_gossip_verification() {
|
||||
//
|
||||
// Could run for ever, but that seems _really_ improbable.
|
||||
let mut i: u64 = 0;
|
||||
a.message.selection_proof = loop {
|
||||
i += 1;
|
||||
let proof: SelectionProof = tester
|
||||
.aggregator_sk
|
||||
.sign(Hash256::from_slice(&int_to_bytes32(i)))
|
||||
.into();
|
||||
if proof
|
||||
.is_aggregator(committee_len, &tester.harness.chain.spec)
|
||||
.unwrap()
|
||||
{
|
||||
break proof.into();
|
||||
match a.to_mut() {
|
||||
SignedAggregateAndProofRefMut::Base(att) => {
|
||||
att.message.selection_proof = loop {
|
||||
i += 1;
|
||||
let proof: SelectionProof = tester
|
||||
.aggregator_sk
|
||||
.sign(Hash256::from_slice(&int_to_bytes32(i)))
|
||||
.into();
|
||||
if proof
|
||||
.is_aggregator(committee_len, &tester.harness.chain.spec)
|
||||
.unwrap()
|
||||
{
|
||||
break proof.into();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
SignedAggregateAndProofRefMut::Electra(att) => {
|
||||
att.message.selection_proof = loop {
|
||||
i += 1;
|
||||
let proof: SelectionProof = tester
|
||||
.aggregator_sk
|
||||
.sign(Hash256::from_slice(&int_to_bytes32(i)))
|
||||
.into();
|
||||
if proof
|
||||
.is_aggregator(committee_len, &tester.harness.chain.spec)
|
||||
.unwrap()
|
||||
{
|
||||
break proof.into();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
|_, err| assert!(matches!(err, AttnError::InvalidSignature)),
|
||||
)
|
||||
@@ -634,7 +733,14 @@ async fn aggregated_gossip_verification() {
|
||||
|tester, a| {
|
||||
let mut agg_sig = AggregateSignature::infinity();
|
||||
agg_sig.add_assign(&tester.aggregator_sk.sign(Hash256::repeat_byte(42)));
|
||||
a.message.aggregate.signature = agg_sig;
|
||||
match a.to_mut() {
|
||||
SignedAggregateAndProofRefMut::Base(att) => {
|
||||
att.message.aggregate.signature = agg_sig;
|
||||
}
|
||||
SignedAggregateAndProofRefMut::Electra(att) => {
|
||||
att.message.aggregate.signature = agg_sig;
|
||||
}
|
||||
}
|
||||
},
|
||||
|_, err| assert!(matches!(err, AttnError::InvalidSignature)),
|
||||
)
|
||||
@@ -643,8 +749,15 @@ async fn aggregated_gossip_verification() {
|
||||
*/
|
||||
.inspect_aggregate_err(
|
||||
"aggregate with too-high aggregator index",
|
||||
|_, a| {
|
||||
a.message.aggregator_index = <E as EthSpec>::ValidatorRegistryLimit::to_u64() + 1
|
||||
|_, a| match a.to_mut() {
|
||||
SignedAggregateAndProofRefMut::Base(att) => {
|
||||
att.message.aggregator_index =
|
||||
<E as EthSpec>::ValidatorRegistryLimit::to_u64() + 1
|
||||
}
|
||||
SignedAggregateAndProofRefMut::Electra(att) => {
|
||||
att.message.aggregator_index =
|
||||
<E as EthSpec>::ValidatorRegistryLimit::to_u64() + 1
|
||||
}
|
||||
},
|
||||
|_, err| {
|
||||
assert!(matches!(
|
||||
@@ -663,7 +776,14 @@ async fn aggregated_gossip_verification() {
|
||||
*/
|
||||
.inspect_aggregate_err(
|
||||
"aggregate with unknown aggregator index",
|
||||
|_, a| a.message.aggregator_index = VALIDATOR_COUNT as u64,
|
||||
|_, a| match a.to_mut() {
|
||||
SignedAggregateAndProofRefMut::Base(att) => {
|
||||
att.message.aggregator_index = VALIDATOR_COUNT as u64
|
||||
}
|
||||
SignedAggregateAndProofRefMut::Electra(att) => {
|
||||
att.message.aggregator_index = VALIDATOR_COUNT as u64
|
||||
}
|
||||
},
|
||||
|_, err| {
|
||||
assert!(matches!(
|
||||
err,
|
||||
@@ -671,7 +791,7 @@ async fn aggregated_gossip_verification() {
|
||||
//
|
||||
// AttnError::AggregatorPubkeyUnknown(unknown_validator)
|
||||
//
|
||||
// However the following error is triggered first:
|
||||
// However, the following error is triggered first:
|
||||
AttnError::AggregatorNotInCommittee {
|
||||
aggregator_index
|
||||
}
|
||||
@@ -683,7 +803,7 @@ async fn aggregated_gossip_verification() {
|
||||
* The following test ensures:
|
||||
*
|
||||
* aggregate_and_proof.selection_proof selects the validator as an aggregator for the slot --
|
||||
* i.e. is_aggregator(state, aggregate.data.slot, aggregate.data.index,
|
||||
* i.e. is_aggregator(state, aggregate.data.slot, aggregate.committee_index(),
|
||||
* aggregate_and_proof.selection_proof) returns True.
|
||||
*/
|
||||
.inspect_aggregate_err(
|
||||
@@ -693,7 +813,7 @@ async fn aggregated_gossip_verification() {
|
||||
let (index, sk) = tester.non_aggregator();
|
||||
*a = SignedAggregateAndProof::from_aggregate(
|
||||
index as u64,
|
||||
tester.valid_aggregate.message.aggregate.clone(),
|
||||
tester.valid_aggregate.message().aggregate().clone(),
|
||||
None,
|
||||
&sk,
|
||||
&chain.canonical_head.cached_head().head_fork(),
|
||||
@@ -703,6 +823,7 @@ async fn aggregated_gossip_verification() {
|
||||
},
|
||||
|tester, err| {
|
||||
let (val_index, _) = tester.non_aggregator();
|
||||
|
||||
assert!(matches!(
|
||||
err,
|
||||
AttnError::InvalidSelectionProof {
|
||||
@@ -729,7 +850,12 @@ async fn aggregated_gossip_verification() {
|
||||
assert!(matches!(
|
||||
err,
|
||||
AttnError::AttestationSupersetKnown(hash)
|
||||
if hash == tester.valid_aggregate.message.aggregate.data.tree_hash_root()
|
||||
if hash == ObservedAttestationKey {
|
||||
committee_index: tester.valid_aggregate.message().aggregate()
|
||||
.committee_index()
|
||||
.expect("should get committee index"),
|
||||
attestation_data: tester.valid_aggregate.message().aggregate().data().clone(),
|
||||
}.tree_hash_root()
|
||||
))
|
||||
},
|
||||
)
|
||||
@@ -741,7 +867,14 @@ async fn aggregated_gossip_verification() {
|
||||
*/
|
||||
.inspect_aggregate_err(
|
||||
"aggregate from aggregator that has already been seen",
|
||||
|_, a| a.message.aggregate.data.beacon_block_root = Hash256::repeat_byte(42),
|
||||
|_, a| match a.to_mut() {
|
||||
SignedAggregateAndProofRefMut::Base(att) => {
|
||||
att.message.aggregate.data.beacon_block_root = Hash256::repeat_byte(42)
|
||||
}
|
||||
SignedAggregateAndProofRefMut::Electra(att) => {
|
||||
att.message.aggregate.data.beacon_block_root = Hash256::repeat_byte(42)
|
||||
}
|
||||
},
|
||||
|tester, err| {
|
||||
assert!(matches!(
|
||||
err,
|
||||
@@ -766,13 +899,29 @@ async fn unaggregated_gossip_verification() {
|
||||
.inspect_unaggregate_err(
|
||||
"attestation with invalid committee index",
|
||||
|tester, a, _| {
|
||||
a.data.index = tester
|
||||
.harness
|
||||
.chain
|
||||
.head_snapshot()
|
||||
.beacon_state
|
||||
.get_committee_count_at_slot(a.data.slot)
|
||||
.unwrap()
|
||||
match a.to_mut() {
|
||||
AttestationRefMut::Base(attn) => {
|
||||
attn.data.index = tester
|
||||
.harness
|
||||
.chain
|
||||
.head_snapshot()
|
||||
.beacon_state
|
||||
.get_committee_count_at_slot(attn.data.slot)
|
||||
.unwrap();
|
||||
}
|
||||
AttestationRefMut::Electra(attn) => {
|
||||
let committee_index = tester
|
||||
.harness
|
||||
.chain
|
||||
.head_snapshot()
|
||||
.beacon_state
|
||||
.get_committee_count_at_slot(attn.data.slot)
|
||||
.unwrap();
|
||||
// overwrite the existing committee bits before setting
|
||||
attn.committee_bits = BitVector::default();
|
||||
attn.committee_bits.set(committee_index as usize, true).unwrap();
|
||||
}
|
||||
}
|
||||
},
|
||||
|_, err| assert!(matches!(err, AttnError::NoCommitteeForSlotAndIndex { .. })),
|
||||
)
|
||||
@@ -806,7 +955,7 @@ async fn unaggregated_gossip_verification() {
|
||||
*/
|
||||
.inspect_unaggregate_err(
|
||||
"attestation from future slot",
|
||||
|tester, a, _| a.data.slot = tester.slot() + 1,
|
||||
|tester, a, _| a.data_mut().slot = tester.slot() + 1,
|
||||
|tester, err| {
|
||||
assert!(matches!(
|
||||
err,
|
||||
@@ -822,8 +971,8 @@ async fn unaggregated_gossip_verification() {
|
||||
"attestation from past slot",
|
||||
|tester, a, _| {
|
||||
let too_early_slot = tester.earliest_valid_attestation_slot() - 1;
|
||||
a.data.slot = too_early_slot;
|
||||
a.data.target.epoch = too_early_slot.epoch(E::slots_per_epoch());
|
||||
a.data_mut().slot = too_early_slot;
|
||||
a.data_mut().target.epoch = too_early_slot.epoch(E::slots_per_epoch());
|
||||
},
|
||||
|tester, err| {
|
||||
let valid_early_slot = tester.earliest_valid_attestation_slot();
|
||||
@@ -847,7 +996,7 @@ async fn unaggregated_gossip_verification() {
|
||||
*/
|
||||
.inspect_unaggregate_err(
|
||||
"attestation with invalid target epoch",
|
||||
|_, a, _| a.data.target.epoch += 1,
|
||||
|_, a, _| a.data_mut().target.epoch += 1,
|
||||
|_, err| {
|
||||
assert!(matches!(
|
||||
err,
|
||||
@@ -863,15 +1012,29 @@ async fn unaggregated_gossip_verification() {
|
||||
*/
|
||||
.inspect_unaggregate_err(
|
||||
"attestation without any aggregation bits set",
|
||||
|tester, a, _| {
|
||||
a.aggregation_bits
|
||||
.set(tester.attester_committee_index, false)
|
||||
.expect("should unset aggregation bit");
|
||||
assert_eq!(
|
||||
a.aggregation_bits.num_set_bits(),
|
||||
0,
|
||||
"test requires no set bits"
|
||||
);
|
||||
|tester, mut a, _| {
|
||||
match &mut a {
|
||||
Attestation::Base(ref mut att) => {
|
||||
att.aggregation_bits
|
||||
.set(tester.attester_committee_index, false)
|
||||
.expect("should unset aggregation bit");
|
||||
assert_eq!(
|
||||
att.aggregation_bits.num_set_bits(),
|
||||
0,
|
||||
"test requires no set bits"
|
||||
);
|
||||
}
|
||||
Attestation::Electra(ref mut att) => {
|
||||
att.aggregation_bits
|
||||
.set(tester.attester_committee_index, false)
|
||||
.expect("should unset aggregation bit");
|
||||
assert_eq!(
|
||||
att.aggregation_bits.num_set_bits(),
|
||||
0,
|
||||
"test requires no set bits"
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|_, err| {
|
||||
assert!(matches!(
|
||||
@@ -882,10 +1045,19 @@ async fn unaggregated_gossip_verification() {
|
||||
)
|
||||
.inspect_unaggregate_err(
|
||||
"attestation with two aggregation bits set",
|
||||
|tester, a, _| {
|
||||
a.aggregation_bits
|
||||
.set(tester.attester_committee_index + 1, true)
|
||||
.expect("should set second aggregation bit");
|
||||
|tester, mut a, _| {
|
||||
match &mut a {
|
||||
Attestation::Base(ref mut att) => {
|
||||
att.aggregation_bits
|
||||
.set(tester.attester_committee_index + 1, true)
|
||||
.expect("should set second aggregation bit");
|
||||
}
|
||||
Attestation::Electra(ref mut att) => {
|
||||
att.aggregation_bits
|
||||
.set(tester.attester_committee_index + 1, true)
|
||||
.expect("should set second aggregation bit");
|
||||
}
|
||||
}
|
||||
},
|
||||
|_, err| {
|
||||
assert!(matches!(
|
||||
@@ -903,11 +1075,22 @@ async fn unaggregated_gossip_verification() {
|
||||
*/
|
||||
.inspect_unaggregate_err(
|
||||
"attestation with invalid bitfield",
|
||||
|_, a, _| {
|
||||
let bits = a.aggregation_bits.iter().collect::<Vec<_>>();
|
||||
a.aggregation_bits = BitList::with_capacity(bits.len() + 1).unwrap();
|
||||
for (i, bit) in bits.into_iter().enumerate() {
|
||||
a.aggregation_bits.set(i, bit).unwrap();
|
||||
|_, mut a, _| {
|
||||
match &mut a {
|
||||
Attestation::Base(ref mut att) => {
|
||||
let bits = att.aggregation_bits.iter().collect::<Vec<_>>();
|
||||
att.aggregation_bits = BitList::with_capacity(bits.len() + 1).unwrap();
|
||||
for (i, bit) in bits.into_iter().enumerate() {
|
||||
att.aggregation_bits.set(i, bit).unwrap();
|
||||
}
|
||||
}
|
||||
Attestation::Electra(ref mut att) => {
|
||||
let bits = att.aggregation_bits.iter().collect::<Vec<_>>();
|
||||
att.aggregation_bits = BitList::with_capacity(bits.len() + 1).unwrap();
|
||||
for (i, bit) in bits.into_iter().enumerate() {
|
||||
att.aggregation_bits.set(i, bit).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|_, err| {
|
||||
@@ -927,7 +1110,7 @@ async fn unaggregated_gossip_verification() {
|
||||
.inspect_unaggregate_err(
|
||||
"attestation with unknown head block",
|
||||
|_, a, _| {
|
||||
a.data.beacon_block_root = Hash256::repeat_byte(42);
|
||||
a.data_mut().beacon_block_root = Hash256::repeat_byte(42);
|
||||
},
|
||||
|_, err| {
|
||||
assert!(matches!(
|
||||
@@ -949,7 +1132,7 @@ async fn unaggregated_gossip_verification() {
|
||||
.inspect_unaggregate_err(
|
||||
"attestation with invalid target root",
|
||||
|_, a, _| {
|
||||
a.data.target.root = Hash256::repeat_byte(42);
|
||||
a.data_mut().target.root = Hash256::repeat_byte(42);
|
||||
},
|
||||
|_, err| {
|
||||
assert!(matches!(
|
||||
@@ -968,7 +1151,7 @@ async fn unaggregated_gossip_verification() {
|
||||
|tester, a, _| {
|
||||
let mut agg_sig = AggregateSignature::infinity();
|
||||
agg_sig.add_assign(&tester.attester_sk.sign(Hash256::repeat_byte(42)));
|
||||
a.signature = agg_sig;
|
||||
*a.signature_mut() = agg_sig;
|
||||
},
|
||||
|_, err| {
|
||||
assert!(matches!(
|
||||
@@ -1055,7 +1238,7 @@ async fn attestation_that_skips_epochs() {
|
||||
.cloned()
|
||||
.expect("should have at least one attestation in committee");
|
||||
|
||||
let block_root = attestation.data.beacon_block_root;
|
||||
let block_root = attestation.data().beacon_block_root;
|
||||
let block_slot = harness
|
||||
.chain
|
||||
.store
|
||||
@@ -1066,7 +1249,7 @@ async fn attestation_that_skips_epochs() {
|
||||
.slot();
|
||||
|
||||
assert!(
|
||||
attestation.data.slot - block_slot > E::slots_per_epoch() * 2,
|
||||
attestation.data().slot - block_slot > E::slots_per_epoch() * 2,
|
||||
"the attestation must skip more than two epochs"
|
||||
);
|
||||
|
||||
@@ -1228,7 +1411,7 @@ async fn attestation_to_finalized_block() {
|
||||
.first()
|
||||
.cloned()
|
||||
.expect("should have at least one attestation in committee");
|
||||
assert_eq!(attestation.data.beacon_block_root, earlier_block_root);
|
||||
assert_eq!(attestation.data().beacon_block_root, earlier_block_root);
|
||||
|
||||
// Attestation should be rejected for attesting to a pre-finalization block.
|
||||
let res = harness
|
||||
@@ -1281,8 +1464,8 @@ async fn verify_aggregate_for_gossip_doppelganger_detection() {
|
||||
.verify_aggregated_attestation_for_gossip(&valid_aggregate)
|
||||
.expect("should verify aggregate attestation");
|
||||
|
||||
let epoch = valid_aggregate.message.aggregate.data.target.epoch;
|
||||
let index = valid_aggregate.message.aggregator_index as usize;
|
||||
let epoch = valid_aggregate.message().aggregate().data().target.epoch;
|
||||
let index = valid_aggregate.message().aggregator_index() as usize;
|
||||
assert!(harness.chain.validator_seen_at_epoch(index, epoch));
|
||||
|
||||
// Check the correct beacon cache is populated
|
||||
@@ -1338,7 +1521,7 @@ async fn verify_attestation_for_gossip_doppelganger_detection() {
|
||||
.verify_unaggregated_attestation_for_gossip(&valid_attestation, Some(subnet_id))
|
||||
.expect("should verify attestation");
|
||||
|
||||
let epoch = valid_attestation.data.target.epoch;
|
||||
let epoch = valid_attestation.data().target.epoch;
|
||||
assert!(harness.chain.validator_seen_at_epoch(index, epoch));
|
||||
|
||||
// Check the correct beacon cache is populated
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
use beacon_chain::block_verification_types::{AsBlock, ExecutedBlock, RpcBlock};
|
||||
use beacon_chain::{
|
||||
test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType},
|
||||
test_utils::{
|
||||
test_spec, AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType,
|
||||
},
|
||||
AvailabilityProcessingStatus, BeaconChain, BeaconChainTypes, ExecutionPendingBlock,
|
||||
};
|
||||
use beacon_chain::{
|
||||
@@ -13,7 +15,7 @@ use lazy_static::lazy_static;
|
||||
use logging::test_logger;
|
||||
use slasher::{Config as SlasherConfig, Slasher};
|
||||
use state_processing::{
|
||||
common::get_indexed_attestation,
|
||||
common::{attesting_indices_base, attesting_indices_electra},
|
||||
per_block_processing::{per_block_processing, BlockSignatureStrategy},
|
||||
per_slot_processing, BlockProcessingError, ConsensusContext, VerifyBlockRoot,
|
||||
};
|
||||
@@ -666,37 +668,95 @@ async fn invalid_signature_attester_slashing() {
|
||||
for &block_index in BLOCK_INDICES {
|
||||
let harness = get_invalid_sigs_harness(&chain_segment).await;
|
||||
let mut snapshots = chain_segment.clone();
|
||||
let indexed_attestation = IndexedAttestation {
|
||||
attesting_indices: vec![0].into(),
|
||||
data: AttestationData {
|
||||
slot: Slot::new(0),
|
||||
index: 0,
|
||||
beacon_block_root: Hash256::zero(),
|
||||
source: Checkpoint {
|
||||
epoch: Epoch::new(0),
|
||||
root: Hash256::zero(),
|
||||
let fork_name = harness.chain.spec.fork_name_at_slot::<E>(Slot::new(0));
|
||||
|
||||
let attester_slashing = if fork_name.electra_enabled() {
|
||||
let indexed_attestation = IndexedAttestationElectra {
|
||||
attesting_indices: vec![0].into(),
|
||||
data: AttestationData {
|
||||
slot: Slot::new(0),
|
||||
index: 0,
|
||||
beacon_block_root: Hash256::zero(),
|
||||
source: Checkpoint {
|
||||
epoch: Epoch::new(0),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
target: Checkpoint {
|
||||
epoch: Epoch::new(0),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
},
|
||||
target: Checkpoint {
|
||||
epoch: Epoch::new(0),
|
||||
root: Hash256::zero(),
|
||||
signature: junk_aggregate_signature(),
|
||||
};
|
||||
let attester_slashing = AttesterSlashingElectra {
|
||||
attestation_1: indexed_attestation.clone(),
|
||||
attestation_2: indexed_attestation,
|
||||
};
|
||||
|
||||
AttesterSlashing::Electra(attester_slashing)
|
||||
} else {
|
||||
let indexed_attestation = IndexedAttestationBase {
|
||||
attesting_indices: vec![0].into(),
|
||||
data: AttestationData {
|
||||
slot: Slot::new(0),
|
||||
index: 0,
|
||||
beacon_block_root: Hash256::zero(),
|
||||
source: Checkpoint {
|
||||
epoch: Epoch::new(0),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
target: Checkpoint {
|
||||
epoch: Epoch::new(0),
|
||||
root: Hash256::zero(),
|
||||
},
|
||||
},
|
||||
},
|
||||
signature: junk_aggregate_signature(),
|
||||
};
|
||||
let attester_slashing = AttesterSlashing {
|
||||
attestation_1: indexed_attestation.clone(),
|
||||
attestation_2: indexed_attestation,
|
||||
signature: junk_aggregate_signature(),
|
||||
};
|
||||
let attester_slashing = AttesterSlashingBase {
|
||||
attestation_1: indexed_attestation.clone(),
|
||||
attestation_2: indexed_attestation,
|
||||
};
|
||||
|
||||
AttesterSlashing::Base(attester_slashing)
|
||||
};
|
||||
|
||||
let (mut block, signature) = snapshots[block_index]
|
||||
.beacon_block
|
||||
.as_ref()
|
||||
.clone()
|
||||
.deconstruct();
|
||||
block
|
||||
.body_mut()
|
||||
.attester_slashings_mut()
|
||||
.push(attester_slashing)
|
||||
.expect("should update attester slashing");
|
||||
match &mut block.body_mut() {
|
||||
BeaconBlockBodyRefMut::Base(ref mut blk) => {
|
||||
blk.attester_slashings
|
||||
.push(attester_slashing.as_base().unwrap().clone())
|
||||
.expect("should update attester slashing");
|
||||
}
|
||||
BeaconBlockBodyRefMut::Altair(ref mut blk) => {
|
||||
blk.attester_slashings
|
||||
.push(attester_slashing.as_base().unwrap().clone())
|
||||
.expect("should update attester slashing");
|
||||
}
|
||||
BeaconBlockBodyRefMut::Bellatrix(ref mut blk) => {
|
||||
blk.attester_slashings
|
||||
.push(attester_slashing.as_base().unwrap().clone())
|
||||
.expect("should update attester slashing");
|
||||
}
|
||||
BeaconBlockBodyRefMut::Capella(ref mut blk) => {
|
||||
blk.attester_slashings
|
||||
.push(attester_slashing.as_base().unwrap().clone())
|
||||
.expect("should update attester slashing");
|
||||
}
|
||||
BeaconBlockBodyRefMut::Deneb(ref mut blk) => {
|
||||
blk.attester_slashings
|
||||
.push(attester_slashing.as_base().unwrap().clone())
|
||||
.expect("should update attester slashing");
|
||||
}
|
||||
BeaconBlockBodyRefMut::Electra(ref mut blk) => {
|
||||
blk.attester_slashings
|
||||
.push(attester_slashing.as_electra().unwrap().clone())
|
||||
.expect("should update attester slashing");
|
||||
}
|
||||
}
|
||||
snapshots[block_index].beacon_block =
|
||||
Arc::new(SignedBeaconBlock::from_block(block, signature));
|
||||
update_parent_roots(&mut snapshots, &mut chain_segment_blobs);
|
||||
@@ -726,8 +786,34 @@ async fn invalid_signature_attestation() {
|
||||
.as_ref()
|
||||
.clone()
|
||||
.deconstruct();
|
||||
if let Some(attestation) = block.body_mut().attestations_mut().get_mut(0) {
|
||||
attestation.signature = junk_aggregate_signature();
|
||||
match &mut block.body_mut() {
|
||||
BeaconBlockBodyRefMut::Base(ref mut blk) => blk
|
||||
.attestations
|
||||
.get_mut(0)
|
||||
.map(|att| att.signature = junk_aggregate_signature()),
|
||||
BeaconBlockBodyRefMut::Altair(ref mut blk) => blk
|
||||
.attestations
|
||||
.get_mut(0)
|
||||
.map(|att| att.signature = junk_aggregate_signature()),
|
||||
BeaconBlockBodyRefMut::Bellatrix(ref mut blk) => blk
|
||||
.attestations
|
||||
.get_mut(0)
|
||||
.map(|att| att.signature = junk_aggregate_signature()),
|
||||
BeaconBlockBodyRefMut::Capella(ref mut blk) => blk
|
||||
.attestations
|
||||
.get_mut(0)
|
||||
.map(|att| att.signature = junk_aggregate_signature()),
|
||||
BeaconBlockBodyRefMut::Deneb(ref mut blk) => blk
|
||||
.attestations
|
||||
.get_mut(0)
|
||||
.map(|att| att.signature = junk_aggregate_signature()),
|
||||
BeaconBlockBodyRefMut::Electra(ref mut blk) => blk
|
||||
.attestations
|
||||
.get_mut(0)
|
||||
.map(|att| att.signature = junk_aggregate_signature()),
|
||||
};
|
||||
|
||||
if block.body().attestations_len() > 0 {
|
||||
snapshots[block_index].beacon_block =
|
||||
Arc::new(SignedBeaconBlock::from_block(block, signature));
|
||||
update_parent_roots(&mut snapshots, &mut chain_segment_blobs);
|
||||
@@ -1126,8 +1212,14 @@ async fn block_gossip_verification() {
|
||||
#[tokio::test]
|
||||
async fn verify_block_for_gossip_slashing_detection() {
|
||||
let slasher_dir = tempdir().unwrap();
|
||||
let spec = Arc::new(test_spec::<E>());
|
||||
let slasher = Arc::new(
|
||||
Slasher::open(SlasherConfig::new(slasher_dir.path().into()), test_logger()).unwrap(),
|
||||
Slasher::open(
|
||||
SlasherConfig::new(slasher_dir.path().into()),
|
||||
spec,
|
||||
test_logger(),
|
||||
)
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
let inner_slasher = slasher.clone();
|
||||
@@ -1191,9 +1283,13 @@ async fn verify_block_for_gossip_doppelganger_detection() {
|
||||
|
||||
let state = harness.get_current_state();
|
||||
let ((block, _), _) = harness.make_block(state.clone(), Slot::new(1)).await;
|
||||
|
||||
let attestations = block
|
||||
.message()
|
||||
.body()
|
||||
.attestations()
|
||||
.map(|att| att.clone_as_attestation())
|
||||
.collect::<Vec<_>>();
|
||||
let verified_block = harness.chain.verify_block_for_gossip(block).await.unwrap();
|
||||
let attestations = verified_block.block.message().body().attestations().clone();
|
||||
harness
|
||||
.chain
|
||||
.process_block(
|
||||
@@ -1207,13 +1303,23 @@ async fn verify_block_for_gossip_doppelganger_detection() {
|
||||
.unwrap();
|
||||
|
||||
for att in attestations.iter() {
|
||||
let epoch = att.data.target.epoch;
|
||||
let committee = state
|
||||
.get_beacon_committee(att.data.slot, att.data.index)
|
||||
.unwrap();
|
||||
let indexed_attestation = get_indexed_attestation(committee.committee, att).unwrap();
|
||||
let epoch = att.data().target.epoch;
|
||||
let indexed_attestation = match att {
|
||||
Attestation::Base(att) => {
|
||||
let committee = state
|
||||
.get_beacon_committee(att.data.slot, att.data.index)
|
||||
.unwrap();
|
||||
attesting_indices_base::get_indexed_attestation(committee.committee, att).unwrap()
|
||||
}
|
||||
Attestation::Electra(att) => {
|
||||
attesting_indices_electra::get_indexed_attestation_from_state(&state, att).unwrap()
|
||||
}
|
||||
};
|
||||
|
||||
for &index in &indexed_attestation.attesting_indices {
|
||||
for index in match indexed_attestation {
|
||||
IndexedAttestation::Base(att) => att.attesting_indices.into_iter(),
|
||||
IndexedAttestation::Electra(att) => att.attesting_indices.into_iter(),
|
||||
} {
|
||||
let index = index as usize;
|
||||
|
||||
assert!(harness.chain.validator_seen_at_epoch(index, epoch));
|
||||
|
||||
@@ -25,7 +25,6 @@ use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use task_executor::ShutdownReason;
|
||||
use tree_hash::TreeHash;
|
||||
use types::*;
|
||||
|
||||
const VALIDATOR_COUNT: usize = 32;
|
||||
@@ -1193,15 +1192,23 @@ async fn attesting_to_optimistic_head() {
|
||||
.produce_unaggregated_attestation(Slot::new(0), 0)
|
||||
.unwrap();
|
||||
|
||||
attestation.aggregation_bits.set(0, true).unwrap();
|
||||
attestation.data.slot = slot;
|
||||
attestation.data.beacon_block_root = root;
|
||||
match &mut attestation {
|
||||
Attestation::Base(ref mut att) => {
|
||||
att.aggregation_bits.set(0, true).unwrap();
|
||||
}
|
||||
Attestation::Electra(ref mut att) => {
|
||||
att.aggregation_bits.set(0, true).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
attestation.data_mut().slot = slot;
|
||||
attestation.data_mut().beacon_block_root = root;
|
||||
|
||||
rig.harness
|
||||
.chain
|
||||
.naive_aggregation_pool
|
||||
.write()
|
||||
.insert(&attestation)
|
||||
.insert(attestation.to_ref())
|
||||
.unwrap();
|
||||
|
||||
attestation
|
||||
@@ -1216,16 +1223,13 @@ async fn attesting_to_optimistic_head() {
|
||||
let get_aggregated = || {
|
||||
rig.harness
|
||||
.chain
|
||||
.get_aggregated_attestation(&attestation.data)
|
||||
.get_aggregated_attestation(attestation.to_ref())
|
||||
};
|
||||
|
||||
let get_aggregated_by_slot_and_root = || {
|
||||
rig.harness
|
||||
.chain
|
||||
.get_aggregated_attestation_by_slot_and_root(
|
||||
attestation.data.slot,
|
||||
&attestation.data.tree_hash_root(),
|
||||
)
|
||||
.get_aggregated_attestation(attestation.to_ref())
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -606,7 +606,7 @@ async fn epoch_boundary_state_attestation_processing() {
|
||||
|
||||
for (attestation, subnet_id) in late_attestations.into_iter().flatten() {
|
||||
// load_epoch_boundary_state is idempotent!
|
||||
let block_root = attestation.data.beacon_block_root;
|
||||
let block_root = attestation.data().beacon_block_root;
|
||||
let block = store
|
||||
.get_blinded_block(&block_root)
|
||||
.unwrap()
|
||||
@@ -629,7 +629,7 @@ async fn epoch_boundary_state_attestation_processing() {
|
||||
.verify_unaggregated_attestation_for_gossip(&attestation, Some(subnet_id));
|
||||
|
||||
let current_slot = harness.chain.slot().expect("should get slot");
|
||||
let expected_attestation_slot = attestation.data.slot;
|
||||
let expected_attestation_slot = attestation.data().slot;
|
||||
// Extra -1 to handle gossip clock disparity.
|
||||
let expected_earliest_permissible_slot = current_slot - E::slots_per_epoch() - 1;
|
||||
|
||||
@@ -1014,6 +1014,7 @@ async fn multiple_attestations_per_block() {
|
||||
.await;
|
||||
|
||||
let head = harness.chain.head_snapshot();
|
||||
|
||||
let committees_per_slot = head
|
||||
.beacon_state
|
||||
.get_committee_count_at_slot(head.beacon_state.slot())
|
||||
@@ -1022,16 +1023,29 @@ async fn multiple_attestations_per_block() {
|
||||
|
||||
for snapshot in harness.chain.chain_dump().unwrap() {
|
||||
let slot = snapshot.beacon_block.slot();
|
||||
assert_eq!(
|
||||
snapshot
|
||||
.beacon_block
|
||||
.as_ref()
|
||||
.message()
|
||||
.body()
|
||||
.attestations()
|
||||
.len() as u64,
|
||||
if slot <= 1 { 0 } else { committees_per_slot }
|
||||
);
|
||||
let fork_name = harness.chain.spec.fork_name_at_slot::<E>(slot);
|
||||
|
||||
if fork_name.electra_enabled() {
|
||||
assert_eq!(
|
||||
snapshot
|
||||
.beacon_block
|
||||
.as_ref()
|
||||
.message()
|
||||
.body()
|
||||
.attestations_len() as u64,
|
||||
if slot <= 1 { 0 } else { 1 }
|
||||
);
|
||||
} else {
|
||||
assert_eq!(
|
||||
snapshot
|
||||
.beacon_block
|
||||
.as_ref()
|
||||
.message()
|
||||
.body()
|
||||
.attestations_len() as u64,
|
||||
if slot <= 1 { 0 } else { committees_per_slot }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -318,7 +318,6 @@ async fn aggregated_gossip_verification() {
|
||||
* The contribution_and_proof.selection_proof is a valid signature of the `SyncAggregatorSelectionData`
|
||||
* derived from the contribution by the validator with index `contribution_and_proof.aggregator_index`.
|
||||
*/
|
||||
|
||||
assert_invalid!(
|
||||
"aggregate with bad selection proof signature",
|
||||
{
|
||||
@@ -354,7 +353,6 @@ async fn aggregated_gossip_verification() {
|
||||
* derived from the participation info in `aggregation_bits` for the subcommittee specified by
|
||||
* the `contribution.subcommittee_index`.
|
||||
*/
|
||||
|
||||
assert_invalid!(
|
||||
"aggregate with bad aggregate signature",
|
||||
{
|
||||
@@ -450,6 +448,7 @@ async fn aggregated_gossip_verification() {
|
||||
root: contribution.beacon_block_root,
|
||||
subcommittee_index: contribution.subcommittee_index,
|
||||
};
|
||||
|
||||
assert_invalid!(
|
||||
"aggregate that has already been seen",
|
||||
valid_aggregate.clone(),
|
||||
|
||||
@@ -574,7 +574,7 @@ async fn attestations_with_increasing_slots() {
|
||||
.verify_unaggregated_attestation_for_gossip(&attestation, Some(subnet_id));
|
||||
|
||||
let current_slot = harness.chain.slot().expect("should get slot");
|
||||
let expected_attestation_slot = attestation.data.slot;
|
||||
let expected_attestation_slot = attestation.data().slot;
|
||||
let expected_earliest_permissible_slot =
|
||||
current_slot - MinimalEthSpec::slots_per_epoch() - 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user