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