Search in sources :

Example 1 with ContributionAndProof

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);
}
Also used : ContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof) Test(org.junit.jupiter.api.Test)

Example 2 with ContributionAndProof

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());
    });
}
Also used : SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) SyncCommitteeContribution(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution) ContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof)

Example 3 with ContributionAndProof

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);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) URL(java.net.URL) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StubMetricsSystem(tech.pegasys.teku.infrastructure.metrics.StubMetricsSystem) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) Bytes(org.apache.tuweni.bytes.Bytes) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Function(java.util.function.Function) ContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof) HttpRequest.request(org.mockserver.model.HttpRequest.request) ExternalSignerTestUtil.verifySignRequest(tech.pegasys.teku.validator.client.signer.ExternalSignerTestUtil.verifySignRequest) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Duration(java.time.Duration) Map(java.util.Map) SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) Spec(tech.pegasys.teku.spec.Spec) Bytes32(org.apache.tuweni.bytes.Bytes32) SyncCommitteeContribution(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution) BLS(tech.pegasys.teku.bls.BLS) BLSSignature(tech.pegasys.teku.bls.BLSSignature) MalformedURLException(java.net.MalformedURLException) SigningRootUtil(tech.pegasys.teku.core.signatures.SigningRootUtil) SyncAggregatorSelectionData(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData) ExternalSignerTestUtil.createForkInfo(tech.pegasys.teku.validator.client.signer.ExternalSignerTestUtil.createForkInfo) HttpClientExternalSignerFactory(tech.pegasys.teku.validator.client.loader.HttpClientExternalSignerFactory) ExternalSignerTestUtil.validateMetrics(tech.pegasys.teku.validator.client.signer.ExternalSignerTestUtil.validateMetrics) ThrottlingTaskQueue(tech.pegasys.teku.infrastructure.async.ThrottlingTaskQueue) ClientAndServer(org.mockserver.integration.ClientAndServer) ValidatorConfig(tech.pegasys.teku.validator.api.ValidatorConfig) Test(org.junit.jupiter.api.Test) MockServerExtension(org.mockserver.junit.jupiter.MockServerExtension) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TekuMetricCategory(tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) BLSTestUtil(tech.pegasys.teku.bls.BLSTestUtil) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) HttpResponse.response(org.mockserver.model.HttpResponse.response) Bytes(org.apache.tuweni.bytes.Bytes) ContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Test(org.junit.jupiter.api.Test)

Example 4 with ContributionAndProof

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());
}
Also used : SyncCommitteeContribution(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution) ContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof) SignedContributionAndProof(tech.pegasys.teku.api.schema.altair.SignedContributionAndProof) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) IntIterable(it.unimi.dsi.fastutil.ints.IntIterable)

Example 5 with ContributionAndProof

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);
}
Also used : SyncCommitteeContribution(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution) ContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof) SignedContributionAndProof(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof) BLSSignature(tech.pegasys.teku.bls.BLSSignature)

Aggregations

ContributionAndProof (tech.pegasys.teku.spec.datastructures.operations.versions.altair.ContributionAndProof)7 SyncCommitteeContribution (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution)5 Test (org.junit.jupiter.api.Test)3 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)3 SignedContributionAndProof (tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof)3 SyncCommitteeUtil (tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil)3 List (java.util.List)2 Bytes (org.apache.tuweni.bytes.Bytes)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)2 Spec (tech.pegasys.teku.spec.Spec)2 FormatMethod (com.google.errorprone.annotations.FormatMethod)1 IntIterable (it.unimi.dsi.fastutil.ints.IntIterable)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Duration (java.time.Duration)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1