Skip to content

Commit

Permalink
Avoid second getSingleTrueBit call
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Nov 29, 2024
1 parent 9d17239 commit 71652ea
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/beacon-node/src/chain/validation/attestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ async function validateAttestationNoSignatureCheck(
}

let aggregationBits: BitArray | null = null;
let committeeValidatorIndex: number | null = null;
if (!isForkPostElectra(fork)) {
// [REJECT] The attestation is unaggregated -- that is, it has exactly one participating validator
// (len([bit for bit in attestation.aggregation_bits if bit]) == 1, i.e. exactly 1 bit is set).
Expand All @@ -345,6 +346,7 @@ async function validateAttestationNoSignatureCheck(
code: AttestationErrorCode.NOT_EXACTLY_ONE_AGGREGATION_BIT_SET,
});
}
committeeValidatorIndex = bitIndex;
}

let committeeValidatorIndices: Uint32Array;
Expand Down Expand Up @@ -399,16 +401,13 @@ async function validateAttestationNoSignatureCheck(
}

let validatorIndex: number;
let committeeValidatorIndex: number;

if (!isForkPostElectra(fork)) {
// The validity of aggregation bits are already checked above
assert.notNull(aggregationBits);
const bitIndex = aggregationBits.getSingleTrueBit();
assert.notNull(bitIndex);
assert.notNull(committeeValidatorIndex);

validatorIndex = committeeValidatorIndices[bitIndex];
committeeValidatorIndex = bitIndex;
validatorIndex = committeeValidatorIndices[committeeValidatorIndex];
// [REJECT] The number of aggregation bits matches the committee size
// -- i.e. len(attestation.aggregation_bits) == len(get_beacon_committee(state, data.slot, data.index)).
// > TODO: Is this necessary? Lighthouse does not do this check.
Expand Down

0 comments on commit 71652ea

Please sign in to comment.