use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof in project teku by ConsenSys.
the class DeletableSignerTest method signContributionAndProof_shouldNotSignWhenDisabled.
@Test
void signContributionAndProof_shouldNotSignWhenDisabled() {
final ContributionAndProof contributionAndProof = dataStructureUtil.randomSignedContributionAndProof(6L).getMessage();
when(delegate.signContributionAndProof(contributionAndProof, forkInfo)).thenReturn(signatureFuture);
assertThatSafeFuture(signer.signContributionAndProof(contributionAndProof, forkInfo)).isCompletedWithValue(signature);
}
use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof in project teku by ConsenSys.
the class SignedContributionAndProofValidator method validate.
public SafeFuture<InternalValidationResult> validate(final SignedContributionAndProof proof) {
final ContributionAndProof contributionAndProof = proof.getMessage();
final SyncCommitteeContribution contribution = contributionAndProof.getContribution();
// [IGNORE] The sync committee contribution is the first valid contribution received for the
// aggregator with index contribution_and_proof.aggregator_index for the slot contribution.slot.
// (this requires maintaining a cache of size `SYNC_COMMITTEE_SIZE` for this topic that can be
// flushed after each slot).
final UniquenessKey uniquenessKey = getUniquenessKey(contributionAndProof, contribution);
if (seenIndices.contains(uniquenessKey)) {
return SafeFuture.completedFuture(IGNORE);
}
final Optional<SyncCommitteeUtil> maybeSyncCommitteeUtil = spec.getSyncCommitteeUtil(contribution.getSlot());
if (maybeSyncCommitteeUtil.isEmpty()) {
return futureFailureResult("Rejecting proof because the fork active at slot %s does not support sync committees", contribution.getSlot());
}
final SyncCommitteeUtil syncCommitteeUtil = maybeSyncCommitteeUtil.get();
if (proof.getMessage().getContribution().getAggregationBits().getBitCount() == 0) {
return SafeFuture.completedFuture(failureResult("Rejecting proof because participant set is empty"));
}
// `MAXIMUM_GOSSIP_CLOCK_DISPARITY` allowance), i.e. `contribution.slot == current_slot`.
if (!slotUtil.isForCurrentSlot(contribution.getSlot())) {
LOG.trace("Ignoring proof because it is not from the current slot");
return SafeFuture.completedFuture(IGNORE);
}
// i.e. contribution.subcommittee_index < SYNC_COMMITTEE_SUBNET_COUNT.
if (contribution.getSubcommitteeIndex().isGreaterThanOrEqualTo(SYNC_COMMITTEE_SUBNET_COUNT)) {
return futureFailureResult("Rejecting proof because subcommittee index %s is too big", contribution.getSubcommitteeIndex());
}
return syncCommitteeStateUtils.getStateForSyncCommittee(contribution.getSlot()).thenCompose(maybeState -> {
if (maybeState.isEmpty()) {
LOG.trace("Ignoring proof because state is not available or not from Altair fork");
return SafeFuture.completedFuture(IGNORE);
}
return validateWithState(proof, contributionAndProof, contribution, syncCommitteeUtil, uniquenessKey, maybeState.get());
});
}
use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof in project teku by ConsenSys.
the class ExternalSignerAltairIntegrationTest method shouldSignContributionAndProof.
@Test
public void shouldSignContributionAndProof() throws Exception {
final Bytes expectedSigningRoot = signingRootFromSyncCommitteeUtils(slot, utils -> utils.getContributionAndProofSigningRoot(contributionAndProof, forkInfo)).get();
final BLSSignature expectedSignature = BLS.sign(KEYPAIR.getSecretKey(), expectedSigningRoot);
client.when(request()).respond(response().withBody(expectedSignature.toString()));
final BLSSignature response = externalSigner.signContributionAndProof(contributionAndProof, forkInfo).join();
assertThat(response).isEqualTo(expectedSignature);
final SigningRequestBody signingRequestBody = new SigningRequestBody(expectedSigningRoot, SignType.SYNC_COMMITTEE_CONTRIBUTION_AND_PROOF, Map.of("fork_info", createForkInfo(forkInfo), "contribution_and_proof", new tech.pegasys.teku.api.schema.altair.ContributionAndProof(contributionAndProof)));
verifySignRequest(client, KEYPAIR.getPublicKey().toString(), signingRequestBody);
validateMetrics(metricsSystem, 1, 0, 0);
}
use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof in project teku by ConsenSys.
the class ValidatorDataProvider method asInternalContributionAndProofs.
private tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof asInternalContributionAndProofs(final SignedContributionAndProof signedContributionAndProof) {
final UInt64 slot = signedContributionAndProof.message.contribution.slot;
final Bytes32 root = signedContributionAndProof.message.contribution.beaconBlockRoot;
final UInt64 subcommitteeIndex = signedContributionAndProof.message.contribution.subcommitteeIndex;
final IntIterable indices = getAggregationBits(signedContributionAndProof.message.contribution.aggregationBits, slot);
final tech.pegasys.teku.bls.BLSSignature signature = signedContributionAndProof.message.contribution.signature.asInternalBLSSignature();
final SyncCommitteeContribution contribution = spec.getSyncCommitteeUtilRequired(slot).createSyncCommitteeContribution(slot, root, subcommitteeIndex, indices, signature);
final ContributionAndProof message = spec.getSyncCommitteeUtilRequired(slot).createContributionAndProof(signedContributionAndProof.message.aggregatorIndex, contribution, signedContributionAndProof.message.selectionProof.asInternalBLSSignature());
return spec.getSyncCommitteeUtilRequired(slot).createSignedContributionAndProof(message, signedContributionAndProof.signature.asInternalBLSSignature());
}
use of tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof in project teku by ConsenSys.
the class SignedContributionAndProofTestBuilder method build.
public SignedContributionAndProof build() {
final BLSSignature aggregateSignature = syncSignatures.isEmpty() ? BLSSignature.infinity() : BLS.aggregate(syncSignatures);
final SyncCommitteeContribution syncCommitteeContribution = syncCommitteeUtil.createSyncCommitteeContribution(slot, beaconBlockRoot, UInt64.valueOf(subcommitteeIndex), subcommitteeParticipationIndices, aggregateSignature);
final ContributionAndProof contributionAndProof = syncCommitteeUtil.createContributionAndProof(aggregatorIndex, syncCommitteeContribution, selectionProof);
final BLSSignature signature = signedContributionAndProofSignature.orElseGet(() -> aggregatorSigner.signContributionAndProof(contributionAndProof, state.getForkInfo()).join());
return syncCommitteeUtil.createSignedContributionAndProof(contributionAndProof, signature);
}
Aggregations