Search in sources :

Example 11 with BLSKeyPair

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

the class MockStartValidatorKeyPairFactory method createKeyPairForValidator.

private BLSKeyPair createKeyPairForValidator(final int validatorIndex) {
    final Bytes hash = Hash.sha256(uintToBytes32(validatorIndex));
    final BigInteger privKey = hash.reverse().toUnsignedBigInteger().mod(CURVE_ORDER);
    final Bytes32 privKeyBytes = Bytes32.leftPad(Bytes.of(privKey.toByteArray()));
    return new BLSKeyPair(BLSSecretKey.fromBytes(privKeyBytes));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) BigInteger(java.math.BigInteger) MathHelpers.uintToBytes32(tech.pegasys.teku.spec.logic.common.helpers.MathHelpers.uintToBytes32) Bytes32(org.apache.tuweni.bytes.Bytes32) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair)

Example 12 with BLSKeyPair

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

the class DataStructureUtil method randomDepositData.

public DepositData randomDepositData() {
    BLSKeyPair keyPair = BLSTestUtil.randomKeyPair(nextSeed());
    BLSPublicKey pubkey = keyPair.getPublicKey();
    Bytes32 withdrawal_credentials = randomBytes32();
    DepositMessage proof_of_possession_data = new DepositMessage(pubkey, withdrawal_credentials, getMaxEffectiveBalance());
    final Bytes32 domain = computeDomain();
    final Bytes signing_root = getSigningRoot(proof_of_possession_data, domain);
    BLSSignature proof_of_possession = BLS.sign(keyPair.getSecretKey(), signing_root);
    return new DepositData(proof_of_possession_data, proof_of_possession);
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) DepositMessage(tech.pegasys.teku.spec.datastructures.operations.DepositMessage) Bytes(org.apache.tuweni.bytes.Bytes) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Bytes32(org.apache.tuweni.bytes.Bytes32) BLSSignature(tech.pegasys.teku.bls.BLSSignature)

Example 13 with BLSKeyPair

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

the class DataStructureUtil method newDeposits.

public List<DepositWithIndex> newDeposits(int numDeposits) {
    List<DepositWithIndex> deposits = new ArrayList<>();
    final DepositGenerator depositGenerator = new DepositGenerator(spec);
    for (int i = 0; i < numDeposits; i++) {
        BLSKeyPair keypair = BLSTestUtil.randomKeyPair(i);
        DepositData depositData = depositGenerator.createDepositData(keypair, getMaxEffectiveBalance(), keypair.getPublicKey());
        DepositWithIndex deposit = new DepositWithIndex(Deposit.SSZ_SCHEMA.getProofSchema().getDefault(), depositData, UInt64.valueOf(i));
        deposits.add(deposit);
    }
    return deposits;
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) DepositGenerator(tech.pegasys.teku.spec.datastructures.util.DepositGenerator) DepositWithIndex(tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex) ArrayList(java.util.ArrayList) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint)

Example 14 with BLSKeyPair

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

the class MockStartBeaconStateGeneratorTest method shouldCreateInitialBeaconChainState.

@Test
public void shouldCreateInitialBeaconChainState() {
    final UInt64 genesisTime = UInt64.valueOf(498294294824924924L);
    final int validatorCount = 10;
    final List<BLSKeyPair> validatorKeyPairs = new MockStartValidatorKeyPairFactory().generateKeyPairs(0, validatorCount);
    final List<DepositData> deposits = new MockStartDepositGenerator(spec).createDeposits(validatorKeyPairs);
    final BeaconState initialBeaconState = new MockStartBeaconStateGenerator(spec).createInitialBeaconState(genesisTime, deposits, Optional.empty());
    assertEquals(validatorCount, initialBeaconState.getValidators().size());
    assertEquals(validatorCount, initialBeaconState.getEth1_data().getDeposit_count().longValue());
    final List<BLSPublicKey> actualValidatorPublicKeys = initialBeaconState.getValidators().stream().map(Validator::getPubkeyBytes).map(BLSPublicKey::fromBytesCompressed).collect(Collectors.toList());
    final List<BLSPublicKey> expectedValidatorPublicKeys = validatorKeyPairs.stream().map(BLSKeyPair::getPublicKey).collect(Collectors.toList());
    assertEquals(expectedValidatorPublicKeys, actualValidatorPublicKeys);
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) MockStartBeaconStateGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartBeaconStateGenerator) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) MockStartValidatorKeyPairFactory(tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory) Validator(tech.pegasys.teku.spec.datastructures.state.Validator) Test(org.junit.jupiter.api.Test)

Example 15 with BLSKeyPair

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

the class InMemoryStorageSystemBuilder method build.

public StorageSystem build() {
    final Database database;
    switch(version) {
        case LEVELDB_TREE:
            database = createLevelDbTreeDatabase();
            break;
        // Leveldb only varies by db type which doesn't apply to in-memory
        case LEVELDB2:
        case V6:
            database = createV6Database();
            break;
        // Leveldb only varies by db type which doesn't apply to in-memory
        case LEVELDB1:
        case V5:
            database = createV5Database();
            break;
        case V4:
            database = createV4Database();
            break;
        default:
            throw new UnsupportedOperationException("Unsupported database version: " + version);
    }
    final List<BLSKeyPair> validatorKeys = new MockStartValidatorKeyPairFactory().generateKeyPairs(0, numberOfValidators);
    return StorageSystem.create(database, createRestartSupplier(), storageMode, storeConfig, spec, ChainBuilder.create(spec, validatorKeys));
}
Also used : Database(tech.pegasys.teku.storage.server.Database) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) MockStartValidatorKeyPairFactory(tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory)

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