Search in sources :

Example 6 with Signer

use of tech.pegasys.teku.core.signatures.Signer in project teku by ConsenSys.

the class ChainBuilder method createValidSignedContributionAndProofBuilder.

public SignedContributionAndProofTestBuilder createValidSignedContributionAndProofBuilder(final UInt64 slot, final Bytes32 beaconBlockRoot) {
    final SyncCommitteeUtil syncCommitteeUtil = spec.getSyncCommitteeUtilRequired(slot);
    final SignedBlockAndState latestBlockAndState = getLatestBlockAndState();
    final UInt64 epoch = syncCommitteeUtil.getEpochForDutiesAtSlot(slot);
    final Map<UInt64, SyncSubcommitteeAssignments> subcommitteeAssignments = syncCommitteeUtil.getSyncSubcommittees(latestBlockAndState.getState(), epoch);
    for (Map.Entry<UInt64, SyncSubcommitteeAssignments> entry : subcommitteeAssignments.entrySet()) {
        final UInt64 validatorIndex = entry.getKey();
        final Signer signer = getSigner(validatorIndex.intValue());
        final SyncSubcommitteeAssignments assignments = entry.getValue();
        for (int subcommitteeIndex : assignments.getAssignedSubcommittees()) {
            final SyncAggregatorSelectionData syncAggregatorSelectionData = syncCommitteeUtil.createSyncAggregatorSelectionData(slot, UInt64.valueOf(subcommitteeIndex));
            final BLSSignature proof = signer.signSyncCommitteeSelectionProof(syncAggregatorSelectionData, latestBlockAndState.getState().getForkInfo()).join();
            if (syncCommitteeUtil.isSyncCommitteeAggregator(proof)) {
                return new SignedContributionAndProofTestBuilder().signerProvider(this::getSigner).syncCommitteeUtil(syncCommitteeUtil).spec(spec).state(latestBlockAndState.getState()).subcommitteeIndex(subcommitteeIndex).slot(slot).selectionProof(proof).beaconBlockRoot(beaconBlockRoot).aggregator(validatorIndex, signer);
            }
        }
    }
    throw new IllegalStateException("No valid sync subcommittee aggregators found");
}
Also used : SyncCommitteeUtil(tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil) SyncAggregatorSelectionData(tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncAggregatorSelectionData) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) SignedContributionAndProofTestBuilder(tech.pegasys.teku.core.synccomittee.SignedContributionAndProofTestBuilder) Signer(tech.pegasys.teku.core.signatures.Signer) LocalSigner(tech.pegasys.teku.core.signatures.LocalSigner) SyncSubcommitteeAssignments(tech.pegasys.teku.spec.datastructures.util.SyncSubcommitteeAssignments) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Map(java.util.Map) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) BLSSignature(tech.pegasys.teku.bls.BLSSignature)

Example 7 with Signer

use of tech.pegasys.teku.core.signatures.Signer in project teku by ConsenSys.

the class BlockImporterTest method importBlock_parentBlockFromSameSlot.

@Test
public void importBlock_parentBlockFromSameSlot() throws Exception {
    // First import a valid block at slot 1
    final SignedBeaconBlock block = otherChain.createAndImportBlockAtSlot(UInt64.ONE);
    localChain.setSlot(block.getSlot());
    assertSuccessfulResult(blockImporter.importBlock(block).get());
    // Now create an alternate block 1 with the real block one as the parent block
    final BeaconBlock invalidAncestryUnsignedBlock = new BeaconBlock(spec.getGenesisSchemaDefinitions().getBeaconBlockSchema(), block.getSlot(), block.getMessage().getProposerIndex(), block.getMessage().hashTreeRoot(), block.getMessage().getStateRoot(), block.getMessage().getBody());
    final Signer signer = localChain.getSigner(block.getMessage().getProposerIndex().intValue());
    final SignedBeaconBlock invalidAncestryBlock = SignedBeaconBlock.create(spec, invalidAncestryUnsignedBlock, signer.signBlock(invalidAncestryUnsignedBlock, otherStorage.getCurrentForkInfo().orElseThrow()).join());
    final BlockImportResult result = blockImporter.importBlock(invalidAncestryBlock).get();
    assertThat(result.isSuccessful()).isFalse();
    assertThat(result.getFailureReason()).isEqualTo(BlockImportResult.FAILED_INVALID_ANCESTRY.getFailureReason());
}
Also used : Signer(tech.pegasys.teku.core.signatures.Signer) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BlockImportResult(tech.pegasys.teku.spec.logic.common.statetransition.results.BlockImportResult) Test(org.junit.jupiter.api.Test)

Example 8 with Signer

use of tech.pegasys.teku.core.signatures.Signer in project teku by ConsenSys.

the class ActiveKeyManager method deleteExternalValidator.

DeleteKeyResult deleteExternalValidator(final Validator activeValidator) {
    final Signer signer = activeValidator.getSigner();
    signer.delete();
    LOG.info("Removed remote validator: {}", activeValidator.getPublicKey().toString());
    return validatorLoader.deleteExternalMutableValidator(activeValidator.getPublicKey());
}
Also used : Signer(tech.pegasys.teku.core.signatures.Signer)

Example 9 with Signer

use of tech.pegasys.teku.core.signatures.Signer in project teku by ConsenSys.

the class LocalValidatorSourceTest method assertProviderMatchesKey.

private void assertProviderMatchesKey(final ValidatorProvider provider, final BLSKeyPair expectedKeyPair) {
    assertThat(provider.getPublicKey()).isEqualTo(expectedKeyPair.getPublicKey());
    final Signer signer = provider.createSigner();
    final Bytes4 version = Bytes4.fromHexString("0x00000000");
    final UInt64 epoch = UInt64.ZERO;
    final ForkInfo forkInfo = new ForkInfo(new Fork(version, version, UInt64.ZERO), Bytes32.ZERO);
    final Bytes signingRoot = signingRootUtil.signingRootForRandaoReveal(epoch, forkInfo);
    final SafeFuture<BLSSignature> signingFuture = signer.createRandaoReveal(epoch, forkInfo);
    asyncRunner.executeQueuedActions();
    assertThat(signingFuture).isCompleted();
    final BLSSignature signature = signingFuture.getNow(null);
    assertThat(BLS.verify(expectedKeyPair.getPublicKey(), signingRoot, signature)).isTrue();
}
Also used : Signer(tech.pegasys.teku.core.signatures.Signer) Bytes(org.apache.tuweni.bytes.Bytes) Fork(tech.pegasys.teku.spec.datastructures.state.Fork) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BLSSignature(tech.pegasys.teku.bls.BLSSignature)

Example 10 with Signer

use of tech.pegasys.teku.core.signatures.Signer in project teku by ConsenSys.

the class SlashingProtectedValidatorSourceTest method addValidator_shouldDemonstrateSlashingProtectedSigner.

@Test
void addValidator_shouldDemonstrateSlashingProtectedSigner() {
    final KeyStoreData keyStoreData = mock(KeyStoreData.class);
    final Signer signer = mock(Signer.class);
    final BLSPublicKey publicKey = dataStructureUtil.randomPublicKey();
    when(signer.signBlock(any(), any())).thenReturn(SafeFuture.completedFuture(dataStructureUtil.randomSignature()));
    when(keyStoreData.getPubkey()).thenReturn(publicKey.toSSZBytes());
    when(delegate.addValidator(any(), any(), any())).thenReturn(new AddValidatorResult(PostKeyResult.success(), Optional.of(signer)));
    final AddValidatorResult result = validatorSource.addValidator(keyStoreData, "pass", publicKey);
    final Signer slashingSigner = result.getSigner().orElseThrow();
    final BeaconBlock block = dataStructureUtil.randomBeaconBlock(1234);
    final ForkInfo forkInfo = dataStructureUtil.randomForkInfo();
    assertThat(slashingSigner.signBlock(block, forkInfo)).isCompleted();
    assertThat(slashingSigner.signBlock(block, forkInfo)).isCompletedExceptionally();
}
Also used : Signer(tech.pegasys.teku.core.signatures.Signer) ForkInfo(tech.pegasys.teku.spec.datastructures.state.ForkInfo) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) KeyStoreData(tech.pegasys.signers.bls.keystore.model.KeyStoreData) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) Test(org.junit.jupiter.api.Test)

Aggregations

Signer (tech.pegasys.teku.core.signatures.Signer)10 LocalSigner (tech.pegasys.teku.core.signatures.LocalSigner)3 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 Test (org.junit.jupiter.api.Test)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 SlashingProtectedSigner (tech.pegasys.teku.core.signatures.SlashingProtectedSigner)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 BeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock)2 SignedBlockAndState (tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState)2 Checkpoint (tech.pegasys.teku.spec.datastructures.state.Checkpoint)2 ForkInfo (tech.pegasys.teku.spec.datastructures.state.ForkInfo)2 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 NavigableMap (java.util.NavigableMap)1 TreeMap (java.util.TreeMap)1 Bytes (org.apache.tuweni.bytes.Bytes)1 KeyStoreData (tech.pegasys.signers.bls.keystore.model.KeyStoreData)1 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)1