Search in sources :

Example 6 with BLSKeyPair

use of tech.pegasys.teku.bls.BLSKeyPair in project web3signer by ConsenSys.

the class BlsArtifactSignerFactory method create.

@Override
public ArtifactSigner create(final HashicorpSigningMetadata hashicorpMetadata) {
    try (final TimingContext ignored = privateKeyRetrievalTimer.labels("hashicorp").startTimer()) {
        final Bytes privateKeyBytes = extractBytesFromVault(hashicorpMetadata);
        final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(Bytes32.wrap(privateKeyBytes)));
        return signerFactory.apply(new BlsArtifactSignerArgs(keyPair, SignerOrigin.HASHICORP));
    }
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) TimingContext(org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext)

Example 7 with BLSKeyPair

use of tech.pegasys.teku.bls.BLSKeyPair in project web3signer by ConsenSys.

the class FcBlsArtifactSignerTest method setup.

@BeforeEach
public void setup() {
    final Bytes fcPrivateKey = Bytes.fromBase64String(FC_BLS_PRIVATE_KEY);
    // Filecoin private keys are serialised in little endian so must convert to big endian
    final Bytes32 privateKey = Bytes32.wrap(fcPrivateKey.reverse());
    final BLSKeyPair keyPair = new BLSKeyPair(BLSSecretKey.fromBytes(privateKey));
    fcBlsArtifactSigner = new FcBlsArtifactSigner(keyPair, FilecoinNetwork.TESTNET);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Bytes32(org.apache.tuweni.bytes.Bytes32) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with BLSKeyPair

use of tech.pegasys.teku.bls.BLSKeyPair in project teku by ConsenSys.

the class ValidatorKeystoreGenerator method generateKeystoreAndPasswordFiles.

public void generateKeystoreAndPasswordFiles(final List<BLSKeyPair> keyPairs) {
    try {
        for (BLSKeyPair keyPair : keyPairs) {
            encryptedKeystoreWriter.writeValidatorKey(keyPair);
            final String validatorPasswordFileName = keyPair.getPublicKey().toAbbreviatedString() + "_validator.txt";
            Path validatorPasswordFile = Files.createFile(passwordsOutputPath.resolve(validatorPasswordFileName));
            Files.write(validatorPasswordFile, validatorKeyPassword.getBytes(Charset.defaultCharset()));
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : Path(java.nio.file.Path) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair)

Example 9 with BLSKeyPair

use of tech.pegasys.teku.bls.BLSKeyPair in project teku by ConsenSys.

the class Generator method generateBlocks.

@Disabled
@Test
public void generateBlocks() throws Exception {
    final Spec spec = TestSpecFactory.createMainnetAltair();
    AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;
    System.out.println("Generating keypairs...");
    int validatorsCount = 32 * 1024;
    List<BLSKeyPair> validatorKeys = BlsKeyPairIO.createReaderForResource("/bls-key-pairs/bls-key-pairs-200k-seed-0.txt.gz").readAll(validatorsCount);
    System.out.println("Keypairs done.");
    RecentChainData localStorage = MemoryOnlyRecentChainData.create(spec);
    BeaconChainUtil localChain = BeaconChainUtil.builder().specProvider(spec).recentChainData(localStorage).validatorKeys(validatorKeys).signDeposits(false).build();
    localChain.initializeStorage();
    AttestationGenerator attestationGenerator = new AttestationGenerator(spec, validatorKeys);
    UInt64 currentSlot = localStorage.getHeadSlot();
    List<Attestation> attestations = Collections.emptyList();
    final int slotsPerEpoch = spec.getGenesisSpecConfig().getSlotsPerEpoch();
    String blocksFile = "blocks_epoch_" + slotsPerEpoch + "_validators_" + validatorsCount + ".ssz.gz";
    try (Writer writer = BlockIO.createFileWriter(blocksFile)) {
        for (int j = 0; j < 50; j++) {
            for (int i = 0; i < slotsPerEpoch; i++) {
                long s = System.currentTimeMillis();
                currentSlot = currentSlot.plus(UInt64.ONE);
                final SignedBeaconBlock block = localChain.createAndImportBlockAtSlotWithAttestations(currentSlot, AttestationGenerator.groupAndAggregateAttestations(attestations));
                writer.accept(block);
                final StateAndBlockSummary postState = localStorage.getStore().retrieveStateAndBlockSummary(block.getMessage().hashTreeRoot()).join().orElseThrow();
                attestations = UInt64.ONE.equals(currentSlot) ? Collections.emptyList() : attestationGenerator.getAttestationsForSlot(postState, currentSlot);
                System.out.println("Processed: " + currentSlot + ", " + getCommittees(spec, postState.getState()) + ", " + (System.currentTimeMillis() - s) + " ms");
            }
            Optional<BeaconState> bestState = localStorage.retrieveBlockState(localStorage.getBestBlockRoot().orElse(null)).join();
            System.out.println("Epoch done: " + bestState);
        }
    }
}
Also used : MemoryOnlyRecentChainData(tech.pegasys.teku.storage.client.MemoryOnlyRecentChainData) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) StateAndBlockSummary(tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary) AttestationGenerator(tech.pegasys.teku.core.AttestationGenerator) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) BeaconChainUtil(tech.pegasys.teku.statetransition.BeaconChainUtil) Spec(tech.pegasys.teku.spec.Spec) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Writer(tech.pegasys.teku.benchmarks.gen.BlockIO.Writer) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 10 with BLSKeyPair

use of tech.pegasys.teku.bls.BLSKeyPair in project teku by ConsenSys.

the class EpochTransitionBenchmark method init.

@Setup(Level.Trial)
public void init() throws Exception {
    AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;
    String blocksFile = "/blocks/blocks_epoch_" + spec.getSlotsPerEpoch(UInt64.ZERO) + "_validators_" + validatorsCount + ".ssz.gz";
    String keysFile = "/bls-key-pairs/bls-key-pairs-200k-seed-0.txt.gz";
    System.out.println("Generating keypairs from " + keysFile);
    List<BLSKeyPair> validatorKeys = BlsKeyPairIO.createReaderForResource(keysFile).readAll(validatorsCount);
    final BlockImportNotifications blockImportNotifications = mock(BlockImportNotifications.class);
    spec = TestSpecFactory.createMainnetPhase0();
    epochProcessor = spec.getGenesisSpec().getEpochProcessor();
    wsValidator = WeakSubjectivityFactory.lenientValidator();
    recentChainData = MemoryOnlyRecentChainData.create(spec);
    final MergeTransitionBlockValidator transitionBlockValidator = new MergeTransitionBlockValidator(spec, recentChainData, ExecutionEngineChannel.NOOP);
    ForkChoice forkChoice = new ForkChoice(spec, new InlineEventThread(), recentChainData, new StubForkChoiceNotifier(), transitionBlockValidator);
    localChain = BeaconChainUtil.create(spec, recentChainData, validatorKeys, false);
    localChain.initializeStorage();
    blockImporter = new BlockImporter(spec, blockImportNotifications, recentChainData, forkChoice, wsValidator, ExecutionEngineChannel.NOOP);
    blockIterator = BlockIO.createResourceReader(spec, blocksFile).iterator();
    System.out.println("Importing 63 blocks from " + blocksFile);
    for (int i = 0; i < 63; i++) {
        SignedBeaconBlock block = blockIterator.next();
        localChain.setSlot(block.getSlot());
        lastResult = blockImporter.importBlock(block).join();
    }
    preEpochTransitionState = safeJoin(recentChainData.getBestState().orElseThrow());
    validatorStatuses = spec.getGenesisSpec().getValidatorStatusFactory().createValidatorStatuses(preEpochTransitionState);
    preEpochTransitionState.updated(mbs -> preEpochTransitionMutableState = mbs);
    attestationDeltas = epochProcessor.getRewardAndPenaltyDeltas(preEpochTransitionState, validatorStatuses);
    System.out.println("Done!");
}
Also used : MergeTransitionBlockValidator(tech.pegasys.teku.statetransition.forkchoice.MergeTransitionBlockValidator) ForkChoice(tech.pegasys.teku.statetransition.forkchoice.ForkChoice) InlineEventThread(tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) StubForkChoiceNotifier(tech.pegasys.teku.statetransition.forkchoice.StubForkChoiceNotifier) BlockImportNotifications(tech.pegasys.teku.statetransition.block.BlockImportNotifications) BlockImporter(tech.pegasys.teku.statetransition.block.BlockImporter) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)66 Test (org.junit.jupiter.api.Test)24 Bytes (org.apache.tuweni.bytes.Bytes)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 HashMap (java.util.HashMap)12 Bytes32 (org.apache.tuweni.bytes.Bytes32)11 TimingContext (org.hyperledger.besu.plugin.services.metrics.OperationTimer.TimingContext)10 Path (java.nio.file.Path)9 BlsArtifactSigner (tech.pegasys.web3signer.core.signing.BlsArtifactSigner)7 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)6 ArtifactSigner (tech.pegasys.web3signer.core.signing.ArtifactSigner)6 BlsArtifactSigner (tech.pegasys.web3signer.signing.BlsArtifactSigner)6 KeyStoreData (tech.pegasys.signers.bls.keystore.model.KeyStoreData)5 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)5 ArtifactSigner (tech.pegasys.web3signer.signing.ArtifactSigner)5 Disabled (org.junit.jupiter.api.Disabled)4 InlineEventThread (tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread)4 SignedBeaconBlock (tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock)4 Optional (java.util.Optional)3 KeyStoreValidationException (tech.pegasys.signers.bls.keystore.KeyStoreValidationException)3