Skip to content

Commit e4c9805

Browse files
authored
Reject attestations to blocks prior to the split (#7084)
1 parent ed1b768 commit e4c9805

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

beacon_node/beacon_chain/src/attestation_verification.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,12 @@ fn verify_head_block_is_known<T: BeaconChainTypes>(
11281128
}
11291129
}
11301130

1131+
if !verify_attestation_is_finalized_checkpoint_or_descendant(attestation.data(), chain) {
1132+
return Err(Error::HeadBlockFinalized {
1133+
beacon_block_root: attestation.data().beacon_block_root,
1134+
});
1135+
}
1136+
11311137
Ok(block)
11321138
} else if chain.is_pre_finalization_block(attestation.data().beacon_block_root)? {
11331139
Err(Error::HeadBlockFinalized {
@@ -1361,6 +1367,29 @@ pub fn verify_committee_index<E: EthSpec>(attestation: AttestationRef<E>) -> Res
13611367
Ok(())
13621368
}
13631369

1370+
fn verify_attestation_is_finalized_checkpoint_or_descendant<T: BeaconChainTypes>(
1371+
attestation_data: &AttestationData,
1372+
chain: &BeaconChain<T>,
1373+
) -> bool {
1374+
// If we have a split block newer than finalization then we also ban attestations which are not
1375+
// descended from that split block. It's important not to try checking `is_descendant` if
1376+
// finality is ahead of the split and the split block has been pruned, as `is_descendant` will
1377+
// return `false` in this case.
1378+
let fork_choice = chain.canonical_head.fork_choice_read_lock();
1379+
let attestation_block_root = attestation_data.beacon_block_root;
1380+
let finalized_slot = fork_choice
1381+
.finalized_checkpoint()
1382+
.epoch
1383+
.start_slot(T::EthSpec::slots_per_epoch());
1384+
let split = chain.store.get_split_info();
1385+
let is_descendant_from_split_block = split.slot == 0
1386+
|| split.slot <= finalized_slot
1387+
|| fork_choice.is_descendant(split.block_root, attestation_block_root);
1388+
1389+
fork_choice.is_finalized_checkpoint_or_descendant(attestation_block_root)
1390+
&& is_descendant_from_split_block
1391+
}
1392+
13641393
/// Assists in readability.
13651394
type CommitteesPerSlot = u64;
13661395

0 commit comments

Comments
 (0)