use of tech.pegasys.teku.spec.config.SpecConfigAltair in project teku by ConsenSys.
the class SpecVersionTest method shouldCreateAltairSpec.
@Test
void shouldCreateAltairSpec() {
final SpecConfigAltair altairSpecConfig = SpecConfigAltair.required(minimalConfig);
final SpecVersion expectedVersion = SpecVersion.createAltair(altairSpecConfig);
final Optional<SpecVersion> actualVersion = SpecVersion.create(SpecMilestone.ALTAIR, minimalConfig);
assertThat(actualVersion).isPresent();
assertThat(actualVersion.get().getMilestone()).isEqualTo(SpecMilestone.ALTAIR);
assertThat(actualVersion.get().getSchemaDefinitions()).hasSameClassAs(expectedVersion.getSchemaDefinitions());
}
use of tech.pegasys.teku.spec.config.SpecConfigAltair in project teku by ConsenSys.
the class SignedContributionAndProofValidator method validateWithState.
private SafeFuture<InternalValidationResult> validateWithState(final SignedContributionAndProof proof, final ContributionAndProof contributionAndProof, final SyncCommitteeContribution contribution, final SyncCommitteeUtil syncCommitteeUtil, final UniquenessKey uniquenessKey, final BeaconStateAltair state) {
final BeaconStateAccessors beaconStateAccessors = spec.atSlot(contribution.getSlot()).beaconStateAccessors();
final Optional<BLSPublicKey> aggregatorPublicKey = beaconStateAccessors.getValidatorPubKey(state, contributionAndProof.getAggregatorIndex());
if (aggregatorPublicKey.isEmpty()) {
return futureFailureResult("Rejecting proof because aggregator index %s is an unknown validator", contributionAndProof.getAggregatorIndex());
}
final UInt64 contributionEpoch = syncCommitteeUtil.getEpochForDutiesAtSlot(contribution.getSlot());
// state.current_sync_committee.pubkeys.
if (!isInSyncSubcommittee(syncCommitteeUtil, contribution, state, contributionEpoch, contributionAndProof.getAggregatorIndex())) {
return futureFailureResult("Rejecting proof because aggregator index %s is not in the current sync subcommittee", contributionAndProof.getAggregatorIndex());
}
// contribution.slot, contribution_and_proof.selection_proof) returns True.
if (!syncCommitteeUtil.isSyncCommitteeAggregator(contributionAndProof.getSelectionProof())) {
return futureFailureResult("Rejecting proof because selection proof %s is not an aggregator", contributionAndProof.getSelectionProof());
}
final AsyncBatchBLSSignatureVerifier signatureVerifier = new AsyncBatchBLSSignatureVerifier(this.signatureVerifier);
// [REJECT] The contribution_and_proof.selection_proof is a valid signature of the
// contribution.slot by the validator with index
// contribution_and_proof.aggregator_index.
final Bytes signingRoot = syncCommitteeUtil.getSyncAggregatorSelectionDataSigningRoot(syncCommitteeUtil.createSyncAggregatorSelectionData(contribution.getSlot(), contribution.getSubcommitteeIndex()), state.getForkInfo());
if (!signatureVerifier.verify(aggregatorPublicKey.get(), signingRoot, contributionAndProof.getSelectionProof())) {
return futureFailureResult("Rejecting proof at slot %s for subcommittee index %s because selection proof is invalid", contribution.getSlot(), contribution.getSubcommitteeIndex());
}
// valid.
if (!signatureVerifier.verify(aggregatorPublicKey.get(), syncCommitteeUtil.getContributionAndProofSigningRoot(state, contributionAndProof), proof.getSignature())) {
return futureFailureResult("Rejecting proof %s because aggregator signature is invalid", proof.getSignature());
}
final SpecConfigAltair config = SpecConfigAltair.required(spec.getSpecConfig(contributionEpoch));
final SyncCommittee syncCommittee = syncCommitteeUtil.getSyncCommittee(state, contributionEpoch);
final int subcommitteeSize = config.getSyncCommitteeSize() / SYNC_COMMITTEE_SUBNET_COUNT;
// [REJECT] The aggregate signature is valid for the message beacon_block_root and
// aggregate pubkey derived from the participation info in aggregation_bits for the
// subcommittee specified by the subcommittee_index.
final List<BLSPublicKey> contributorPublicKeys = contribution.getAggregationBits().streamAllSetBits().mapToObj(participantIndex -> getParticipantPublicKey(state, syncCommittee, contribution, subcommitteeSize, participantIndex)).collect(Collectors.toList());
if (!signatureVerifier.verify(contributorPublicKeys, syncCommitteeUtil.getSyncCommitteeMessageSigningRoot(contribution.getBeaconBlockRoot(), contributionEpoch, state.getForkInfo()), contribution.getSignature())) {
return futureFailureResult("Rejecting proof because aggregate signature %s is invalid", contribution.getSignature());
}
return signatureVerifier.batchVerify().thenApply(signatureValid -> {
if (!signatureValid) {
return failureResult("Rejecting proof with signature %s because batch signature check failed", contribution.getSignature());
}
if (!seenIndices.add(uniquenessKey)) {
// Got added by another thread while we were validating it
return IGNORE;
}
return ACCEPT;
});
}
use of tech.pegasys.teku.spec.config.SpecConfigAltair in project teku by ConsenSys.
the class SyncCommitteeScheduler method onSlot.
@Override
public void onSlot(final UInt64 slot) {
final Optional<SyncCommitteeUtil> maybeUtils = spec.getSyncCommitteeUtil(slot);
if (maybeUtils.isEmpty()) {
return;
}
final SyncCommitteeUtil syncCommitteeUtil = maybeUtils.get();
final UInt64 dutiesEpoch = syncCommitteeUtil.getEpochForDutiesAtSlot(slot);
final SpecConfigAltair specConfig = SpecConfigAltair.required(spec.getSpecConfig(dutiesEpoch));
if (currentSyncCommitteePeriod.isEmpty()) {
final SyncCommitteePeriod committeePeriod = createSyncCommitteePeriod(syncCommitteeUtil, syncCommitteeUtil.computeFirstEpochOfCurrentSyncCommitteePeriod(dutiesEpoch), 0);
committeePeriod.calculateDuties();
currentSyncCommitteePeriod = Optional.of(committeePeriod);
}
if (nextSyncCommitteePeriod.isEmpty()) {
final UInt64 firstEpochOfNextSyncCommitteePeriod = syncCommitteeUtil.computeFirstEpochOfNextSyncCommitteePeriod(dutiesEpoch);
final int subscribeEpochsPriorToNextSyncPeriod = earlySubscribeRandomSource.randomEpochCount(specConfig.getEpochsPerSyncCommitteePeriod());
nextSyncCommitteePeriod = Optional.of(createSyncCommitteePeriod(syncCommitteeUtil, firstEpochOfNextSyncCommitteePeriod, subscribeEpochsPriorToNextSyncPeriod));
}
final SyncCommitteePeriod nextSyncCommitteePeriod = this.nextSyncCommitteePeriod.get();
if (dutiesEpoch.isGreaterThanOrEqualTo(nextSyncCommitteePeriod.subscribeEpoch)) {
nextSyncCommitteePeriod.calculateDuties();
}
if (dutiesEpoch.isGreaterThanOrEqualTo(nextSyncCommitteePeriod.periodStartEpoch)) {
this.currentSyncCommitteePeriod = this.nextSyncCommitteePeriod;
this.nextSyncCommitteePeriod = Optional.empty();
}
}
Aggregations