Search in sources :

Example 1 with DepositMessage

use of tech.pegasys.teku.spec.datastructures.operations.DepositMessage 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 2 with DepositMessage

use of tech.pegasys.teku.spec.datastructures.operations.DepositMessage in project teku by ConsenSys.

the class BlockProcessorTest method processDepositIgnoresDepositWithInvalidPublicKey.

@Test
void processDepositIgnoresDepositWithInvalidPublicKey() throws BlockProcessingException {
    // The following deposit uses a "rogue" public key that is not in the G1 group
    BLSPublicKey pubkey = BLSPublicKey.fromBytesCompressed(Bytes48.fromHexString("0x9378a6e3984e96d2cd50450c76ca14732f1300efa04aecdb805b22e6d6926a85ef409e8f3acf494a1481090bf32ce3bd"));
    Bytes32 withdrawalCredentials = Bytes32.fromHexString("0x79e43d39ee55749c55994a7ab2a3cb91460cec544fdbf27eb5717c43f970c1b6");
    UInt64 amount = UInt64.valueOf(1000000000L);
    BLSSignature signature = BLSSignature.fromBytesCompressed(Bytes.fromHexString("0xddc1ca509e29c6452441069f26da6e073589b3bd1cace50e3427426af5bfdd566d077d4bdf618e249061b9770471e3d515779aa758b8ccb4b06226a8d5ebc99e19d4c3278e5006b837985bec4e0ce39df92c1f88d1afd0f98dbae360024a390d"));
    DepositData depositInput = new DepositData(new DepositMessage(pubkey, withdrawalCredentials, amount), signature);
    BeaconState preState = createBeaconState();
    int originalValidatorRegistrySize = preState.getValidators().size();
    int originalValidatorBalancesSize = preState.getBalances().size();
    BeaconState postState = processDepositHelper(preState, depositInput);
    assertEquals(postState.getValidators().size(), originalValidatorRegistrySize, "The validator was added to the validator registry.");
    assertEquals(postState.getBalances().size(), originalValidatorBalancesSize, "The balance was added to the validator balances.");
    assertEquals(preState.getBalances().hashTreeRoot(), postState.getBalances().hashTreeRoot(), "The balances list has changed.");
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) DepositMessage(tech.pegasys.teku.spec.datastructures.operations.DepositMessage) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32) BLSSignature(tech.pegasys.teku.bls.BLSSignature) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 3 with DepositMessage

use of tech.pegasys.teku.spec.datastructures.operations.DepositMessage in project teku by ConsenSys.

the class AbstractBlockProcessor method depositSignatureIsValid.

private boolean depositSignatureIsValid(final Deposit deposit, BLSPublicKey pubkey) {
    if (!BLS_VERIFY_DEPOSIT) {
        return true;
    }
    final UInt64 amount = deposit.getData().getAmount();
    final DepositMessage deposit_message = new DepositMessage(pubkey, deposit.getData().getWithdrawal_credentials(), amount);
    final Bytes32 domain = miscHelpers.computeDomain(Domain.DEPOSIT);
    final Bytes signing_root = miscHelpers.computeSigningRoot(deposit_message, domain);
    // in blocks and processing differs based on whether the signature is valid or not.
    return BLS.verify(pubkey, signing_root, deposit.getData().getSignature());
}
Also used : DepositMessage(tech.pegasys.teku.spec.datastructures.operations.DepositMessage) Bytes(org.apache.tuweni.bytes.Bytes) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Bytes32(org.apache.tuweni.bytes.Bytes32)

Example 4 with DepositMessage

use of tech.pegasys.teku.spec.datastructures.operations.DepositMessage in project teku by ConsenSys.

the class DepositGenerator method createDepositData.

public DepositData createDepositData(final BLSKeyPair validatorKeyPair, final UInt64 amountInGwei, final BLSPublicKey withdrawalPublicKey) {
    final Bytes32 withdrawalCredentials = createWithdrawalCredentials(withdrawalPublicKey);
    final DepositMessage depositMessage = new DepositMessage(validatorKeyPair.getPublicKey(), withdrawalCredentials, amountInGwei);
    final SpecVersion specVersion = spec.getGenesisSpec();
    final Bytes32 depositDomain = specVersion.miscHelpers().computeDomain(Domain.DEPOSIT);
    final BLSSignature signature = signDeposit ? BLS.sign(validatorKeyPair.getSecretKey(), specVersion.miscHelpers().computeSigningRoot(depositMessage, depositDomain)) : BLSSignature.empty();
    return new DepositData(depositMessage, signature);
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) DepositMessage(tech.pegasys.teku.spec.datastructures.operations.DepositMessage) SpecVersion(tech.pegasys.teku.spec.SpecVersion) Bytes32(org.apache.tuweni.bytes.Bytes32) BLSSignature(tech.pegasys.teku.bls.BLSSignature)

Aggregations

Bytes32 (org.apache.tuweni.bytes.Bytes32)4 DepositMessage (tech.pegasys.teku.spec.datastructures.operations.DepositMessage)4 BLSSignature (tech.pegasys.teku.bls.BLSSignature)3 DepositData (tech.pegasys.teku.spec.datastructures.operations.DepositData)3 Bytes (org.apache.tuweni.bytes.Bytes)2 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)2 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)2 Test (org.junit.jupiter.api.Test)1 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)1 SpecVersion (tech.pegasys.teku.spec.SpecVersion)1 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)1