Search in sources :

Example 1 with AggregateAndProof

use of tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof in project teku by ConsenSys.

the class SlashingProtectedSignerTest method signAggregateAndProof_shouldAlwaysSign.

@Test
void signAggregateAndProof_shouldAlwaysSign() {
    final AggregateAndProof aggregateAndProof = dataStructureUtil.randomAggregateAndProof();
    when(delegate.signAggregateAndProof(aggregateAndProof, forkInfo)).thenReturn(signatureFuture);
    assertThatSafeFuture(signer.signAggregateAndProof(aggregateAndProof, forkInfo)).isCompletedWithValue(signature);
}
Also used : AggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof) Test(org.junit.jupiter.api.Test)

Example 2 with AggregateAndProof

use of tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof in project teku by ConsenSys.

the class ExternalSignerIntegrationTest method shouldSignAggregateAndProof.

@Test
public void shouldSignAggregateAndProof() throws Exception {
    final AggregateAndProof aggregateAndProof = dataStructureUtil.randomAggregateAndProof();
    final BLSSignature expectedSignature = BLSSignature.fromBytesCompressed(Bytes.fromBase64String("kHbIuvFcS/kDppbCj0ILOU27ZjSU1P2wPsOKBBwGaz1uvXQxtUXQAdbybN1zotZqCs6pstChIIxDS/WgAZH2z4yX2cM/cM/iKayT2rZZJuu31V2uxP1AYVcyHLEMtF07"));
    client.when(request()).respond(response().withBody(expectedSignature.toString()));
    final BLSSignature response = externalSigner.signAggregateAndProof(aggregateAndProof, fork).join();
    assertThat(response).isEqualTo(expectedSignature);
    final SigningRequestBody signingRequestBody = new SigningRequestBody(signingRootUtil.signingRootForSignAggregateAndProof(aggregateAndProof, fork), SignType.AGGREGATE_AND_PROOF, Map.of("fork_info", createForkInfo(fork), "aggregate_and_proof", new tech.pegasys.teku.api.schema.AggregateAndProof(aggregateAndProof)));
    verifySignRequest(client, KEYPAIR.getPublicKey().toString(), signingRequestBody);
    validateMetrics(metricsSystem, 1, 0, 0);
}
Also used : AggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof) BLSSignature(tech.pegasys.teku.bls.BLSSignature) Test(org.junit.jupiter.api.Test)

Example 3 with AggregateAndProof

use of tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof in project teku by ConsenSys.

the class AggregationDutyTest method shouldProduceAggregateAndProofForMultipleCommittees.

@SuppressWarnings("unchecked")
@Test
public void shouldProduceAggregateAndProofForMultipleCommittees() {
    final int validator1Index = 1;
    final int validator1CommitteeIndex = 2;
    final BLSSignature validator1Proof = dataStructureUtil.randomSignature();
    final int validator2Index = 6;
    final int validator2CommitteeIndex = 0;
    final BLSSignature validator2Proof = dataStructureUtil.randomSignature();
    final AttestationData committee1AttestationData = dataStructureUtil.randomAttestationData();
    final AttestationData committee2AttestationData = dataStructureUtil.randomAttestationData();
    final Attestation committee1Aggregate = dataStructureUtil.randomAttestation();
    final Attestation committee2Aggregate = dataStructureUtil.randomAttestation();
    duty.addValidator(validator1, validator1Index, validator1Proof, validator1CommitteeIndex, completedFuture(Optional.of(committee1AttestationData)));
    duty.addValidator(validator2, validator2Index, validator2Proof, validator2CommitteeIndex, completedFuture(Optional.of(committee2AttestationData)));
    when(validatorApiChannel.createAggregate(SLOT, committee1AttestationData.hashTreeRoot())).thenReturn(completedFuture(Optional.of(committee1Aggregate)));
    when(validatorApiChannel.createAggregate(SLOT, committee2AttestationData.hashTreeRoot())).thenReturn(completedFuture(Optional.of(committee2Aggregate)));
    final AggregateAndProof aggregateAndProof1 = aggregateAndProofSchema.create(UInt64.valueOf(validator1Index), committee1Aggregate, validator1Proof);
    final AggregateAndProof aggregateAndProof2 = aggregateAndProofSchema.create(UInt64.valueOf(validator2Index), committee2Aggregate, validator2Proof);
    final BLSSignature aggregateSignature1 = dataStructureUtil.randomSignature();
    final BLSSignature aggregateSignature2 = dataStructureUtil.randomSignature();
    when(signer1.signAggregateAndProof(aggregateAndProof1, forkInfo)).thenReturn(SafeFuture.completedFuture(aggregateSignature1));
    when(signer2.signAggregateAndProof(aggregateAndProof2, forkInfo)).thenReturn(SafeFuture.completedFuture(aggregateSignature2));
    assertThat(duty.performDuty()).isCompleted();
    ArgumentCaptor<List<SignedAggregateAndProof>> argumentCaptor = ArgumentCaptor.forClass(List.class);
    verify(validatorApiChannel).sendAggregateAndProofs(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue()).containsExactlyInAnyOrder(signedAggregateAndProofSchema.create(aggregateAndProof1, aggregateSignature1), signedAggregateAndProofSchema.create(aggregateAndProof2, aggregateSignature2));
}
Also used : AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) BLSSignature(tech.pegasys.teku.bls.BLSSignature) AggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) Test(org.junit.jupiter.api.Test)

Example 4 with AggregateAndProof

use of tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof in project teku by ConsenSys.

the class AggregationDutyTest method shouldProduceSingleAggregateAndProofWhenMultipleValidatorsAggregateSameCommittee.

@Test
public void shouldProduceSingleAggregateAndProofWhenMultipleValidatorsAggregateSameCommittee() {
    final int committeeIndex = 2;
    final int validator1Index = 1;
    final BLSSignature validator1Proof = dataStructureUtil.randomSignature();
    final int validator2Index = 6;
    final BLSSignature validator2Proof = dataStructureUtil.randomSignature();
    final AttestationData attestationData = dataStructureUtil.randomAttestationData();
    final Attestation aggregate = dataStructureUtil.randomAttestation();
    duty.addValidator(validator1, validator1Index, validator1Proof, committeeIndex, completedFuture(Optional.of(attestationData)));
    duty.addValidator(validator2, validator2Index, validator2Proof, committeeIndex, completedFuture(Optional.of(attestationData)));
    when(validatorApiChannel.createAggregate(SLOT, attestationData.hashTreeRoot())).thenReturn(completedFuture(Optional.of(aggregate)));
    when(validatorApiChannel.sendAggregateAndProofs(anyList())).thenReturn(SafeFuture.completedFuture(Collections.emptyList()));
    final AggregateAndProof aggregateAndProof = aggregateAndProofSchema.create(UInt64.valueOf(validator1Index), aggregate, validator1Proof);
    final BLSSignature aggregateSignature1 = dataStructureUtil.randomSignature();
    when(signer1.signAggregateAndProof(aggregateAndProof, forkInfo)).thenReturn(SafeFuture.completedFuture(aggregateSignature1));
    performAndReportDuty();
    verify(validatorApiChannel).sendAggregateAndProofs(List.of(signedAggregateAndProofSchema.create(aggregateAndProof, aggregateSignature1)));
    // Only one proof should be sent.
    verify(validatorApiChannel, times(1)).sendAggregateAndProofs(anyList());
    verify(validatorLogger).dutyCompleted(TYPE, SLOT, 1, Set.of(aggregate.getData().getBeacon_block_root()));
    verifyNoMoreInteractions(validatorLogger);
}
Also used : AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) BLSSignature(tech.pegasys.teku.bls.BLSSignature) AggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) Test(org.junit.jupiter.api.Test)

Example 5 with AggregateAndProof

use of tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof in project teku by ConsenSys.

the class AggregationDutyTest method shouldProduceAggregateAndProof.

@Test
public void shouldProduceAggregateAndProof() {
    final int validatorIndex = 1;
    final int attestationCommitteeIndex = 2;
    final BLSSignature proof = dataStructureUtil.randomSignature();
    final AttestationData attestationData = dataStructureUtil.randomAttestationData();
    final Attestation aggregate = dataStructureUtil.randomAttestation();
    duty.addValidator(validator1, validatorIndex, proof, attestationCommitteeIndex, completedFuture(Optional.of(attestationData)));
    when(validatorApiChannel.createAggregate(SLOT, attestationData.hashTreeRoot())).thenReturn(completedFuture(Optional.of(aggregate)));
    final AggregateAndProof expectedAggregateAndProof = aggregateAndProofSchema.create(UInt64.valueOf(validatorIndex), aggregate, proof);
    final BLSSignature aggregateSignature = dataStructureUtil.randomSignature();
    when(signer1.signAggregateAndProof(expectedAggregateAndProof, forkInfo)).thenReturn(SafeFuture.completedFuture(aggregateSignature));
    assertThat(duty.performDuty()).isCompleted();
    verify(validatorApiChannel).sendAggregateAndProofs(List.of(signedAggregateAndProofSchema.create(expectedAggregateAndProof, aggregateSignature)));
}
Also used : AttestationData(tech.pegasys.teku.spec.datastructures.operations.AttestationData) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) BLSSignature(tech.pegasys.teku.bls.BLSSignature) AggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) Test(org.junit.jupiter.api.Test)

Aggregations

AggregateAndProof (tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof)12 Test (org.junit.jupiter.api.Test)9 BLSSignature (tech.pegasys.teku.bls.BLSSignature)8 SignedAggregateAndProof (tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof)7 Attestation (tech.pegasys.teku.spec.datastructures.operations.Attestation)5 AttestationData (tech.pegasys.teku.spec.datastructures.operations.AttestationData)4 IntList (it.unimi.dsi.fastutil.ints.IntList)2 List (java.util.List)2 Optional (java.util.Optional)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 Bytes (org.apache.tuweni.bytes.Bytes)2 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 Spec (tech.pegasys.teku.spec.Spec)2 MoreObjects (com.google.common.base.MoreObjects)1 Math.toIntExact (java.lang.Math.toIntExact)1 Collections.emptyList (java.util.Collections.emptyList)1 Objects (java.util.Objects)1