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");
}
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());
}
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());
}
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();
}
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();
}
Aggregations