Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions packages/beacon-node/src/chain/validation/aggregateAndProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,25 @@ export async function validateGossipAggregateAndProof(
// -- i.e. get_ancestor(store, aggregate.data.beacon_block_root, compute_start_slot_at_epoch(store.finalized_checkpoint.epoch)) == store.finalized_checkpoint.root
// > Altready check in `chain.forkChoice.hasBlock(attestation.data.beaconBlockRoot)`

const attHeadState = await chain.regen
.getState(attHeadBlock.stateRoot, RegenCaller.validateGossipAggregateAndProof)
.catch((e: Error) => {
throw new AttestationError(GossipAction.REJECT, {
code: AttestationErrorCode.MISSING_ATTESTATION_HEAD_STATE,
error: e as Error,
});
});
// TODO: Must be a state in the same chain as attHeadBlock, but dialed to target.epoch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we verify elsewhere that attHead is a descendant of the target

const attHeadState =
computeEpochAtSlot(attHeadBlock.slot) < attEpoch
? await chain.regen
.getCheckpointState(attTarget, RegenCaller.validateGossipAggregateAndProof)
.catch((e: Error) => {
throw new AttestationError(GossipAction.REJECT, {
code: AttestationErrorCode.MISSING_ATTESTATION_HEAD_STATE,
error: e as Error,
});
})
: await chain.regen
.getState(attHeadBlock.stateRoot, RegenCaller.validateGossipAggregateAndProof)
.catch((e: Error) => {
throw new AttestationError(GossipAction.REJECT, {
code: AttestationErrorCode.MISSING_ATTESTATION_HEAD_STATE,
error: e as Error,
});
});

const committeeIndices: number[] = getCommitteeIndices(attHeadState, attSlot, attIndex);

Expand Down
23 changes: 15 additions & 8 deletions packages/beacon-node/src/chain/validation/attestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,21 @@ export async function validateGossipAttestation(
// --i.e. get_ancestor(store, attestation.data.beacon_block_root, compute_start_slot_at_epoch(attestation.data.target.epoch)) == attestation.data.target.root
// > Altready check in `verifyHeadBlockAndTargetRoot()`

const attHeadState = await chain.regen
.getState(attHeadBlock.stateRoot, RegenCaller.validateGossipAttestation)
.catch((e: Error) => {
throw new AttestationError(GossipAction.REJECT, {
code: AttestationErrorCode.MISSING_ATTESTATION_HEAD_STATE,
error: e as Error,
});
});
// TODO: Must be a state in the same chain as attHeadBlock, but dialed to target.epoch
const attHeadState =
computeEpochAtSlot(attHeadBlock.slot) < attEpoch
? await chain.regen.getCheckpointState(attTarget, RegenCaller.validateGossipAttestation).catch((e: Error) => {
throw new AttestationError(GossipAction.REJECT, {
code: AttestationErrorCode.MISSING_ATTESTATION_HEAD_STATE,
error: e as Error,
});
})
: await chain.regen.getState(attHeadBlock.stateRoot, RegenCaller.validateGossipAttestation).catch((e: Error) => {
throw new AttestationError(GossipAction.REJECT, {
code: AttestationErrorCode.MISSING_ATTESTATION_HEAD_STATE,
error: e as Error,
});
});

// [REJECT] The committee index is within the expected range
// -- i.e. data.index < get_committee_count_per_slot(state, data.target.epoch)
Expand Down