Search in sources :

Example 16 with SpecVersion

use of tech.pegasys.teku.spec.SpecVersion in project teku by ConsenSys.

the class AggregateAttestationValidator method validate.

public SafeFuture<InternalValidationResult> validate(final ValidateableAttestation attestation) {
    final SignedAggregateAndProof signedAggregate = attestation.getSignedAggregateAndProof();
    final AggregateAndProof aggregateAndProof = signedAggregate.getMessage();
    final Attestation aggregate = aggregateAndProof.getAggregate();
    final UInt64 aggregateSlot = aggregate.getData().getSlot();
    final SpecVersion specVersion = spec.atSlot(aggregateSlot);
    final AggregatorIndexAndEpoch aggregatorIndexAndEpoch = new AggregatorIndexAndEpoch(aggregateAndProof.getIndex(), spec.computeEpochAtSlot(aggregateSlot));
    if (receivedAggregatorIndexAndEpochs.contains(aggregatorIndexAndEpoch)) {
        return completedFuture(ignore("Ignoring duplicate aggregate"));
    }
    if (receivedValidAggregations.contains(attestation.hash_tree_root())) {
        return completedFuture(ignore("Ignoring duplicate aggregate based on hash tree root"));
    }
    final AsyncBatchBLSSignatureVerifier signatureVerifier = new AsyncBatchBLSSignatureVerifier(this.signatureVerifier);
    return singleOrAggregateAttestationChecks(signatureVerifier, attestation, OptionalInt.empty()).thenCompose(aggregateInternalValidationResult -> {
        if (aggregateInternalValidationResult.isNotProcessable()) {
            LOG.trace("Rejecting aggregate because attestation failed validation");
            return completedFuture(aggregateInternalValidationResult);
        }
        return recentChainData.retrieveBlockState(aggregate.getData().getBeacon_block_root()).thenCompose(maybeState -> maybeState.isEmpty() ? completedFuture(Optional.empty()) : attestationValidator.resolveStateForAttestation(aggregate, maybeState.get())).thenCompose(maybeState -> {
            if (maybeState.isEmpty()) {
                return SafeFuture.completedFuture(InternalValidationResult.SAVE_FOR_FUTURE);
            }
            final BeaconState state = maybeState.get();
            final Optional<BLSPublicKey> aggregatorPublicKey = spec.getValidatorPubKey(state, aggregateAndProof.getIndex());
            if (aggregatorPublicKey.isEmpty()) {
                return SafeFuture.completedFuture(reject("Rejecting aggregate with invalid index"));
            }
            if (!isSelectionProofValid(signatureVerifier, aggregateSlot, state, aggregatorPublicKey.get(), aggregateAndProof.getSelection_proof())) {
                return SafeFuture.completedFuture(reject("Rejecting aggregate with incorrect selection proof"));
            }
            final IntList beaconCommittee = spec.getBeaconCommittee(state, aggregateSlot, aggregate.getData().getIndex());
            final int aggregatorModulo = specVersion.getValidatorsUtil().getAggregatorModulo(beaconCommittee.size());
            if (!specVersion.getValidatorsUtil().isAggregator(aggregateAndProof.getSelection_proof(), aggregatorModulo)) {
                return SafeFuture.completedFuture(reject("Rejecting aggregate because selection proof does not select validator as aggregator"));
            }
            if (!beaconCommittee.contains(toIntExact(aggregateAndProof.getIndex().longValue()))) {
                return SafeFuture.completedFuture(reject("Rejecting aggregate because attester is not in committee. Should have been one of %s", beaconCommittee));
            }
            if (!validateSignature(signatureVerifier, signedAggregate, state, aggregatorPublicKey.get())) {
                return SafeFuture.completedFuture(reject("Rejecting aggregate with invalid signature"));
            }
            return signatureVerifier.batchVerify().thenApply(signatureValid -> {
                if (!signatureValid) {
                    return reject("Rejecting aggregate with invalid batch signature");
                }
                if (!receivedAggregatorIndexAndEpochs.add(aggregatorIndexAndEpoch)) {
                    return ignore("Ignoring duplicate aggregate");
                }
                if (!receivedValidAggregations.add(attestation.hash_tree_root())) {
                    return ignore("Ignoring duplicate aggregate based on hash tree root");
                }
                return aggregateInternalValidationResult;
            });
        });
    });
}
Also used : AsyncBLSSignatureVerifier(tech.pegasys.teku.spec.logic.common.util.AsyncBLSSignatureVerifier) AggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof) SafeFuture(tech.pegasys.teku.infrastructure.async.SafeFuture) Bytes(org.apache.tuweni.bytes.Bytes) SafeFuture.completedFuture(tech.pegasys.teku.infrastructure.async.SafeFuture.completedFuture) OptionalInt(java.util.OptionalInt) BLSSignatureVerifier(tech.pegasys.teku.bls.BLSSignatureVerifier) SpecVersion(tech.pegasys.teku.spec.SpecVersion) LimitedSet(tech.pegasys.teku.infrastructure.collections.LimitedSet) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) VALID_AGGREGATE_SET_SIZE(tech.pegasys.teku.spec.config.Constants.VALID_AGGREGATE_SET_SIZE) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Math.toIntExact(java.lang.Math.toIntExact) Spec(tech.pegasys.teku.spec.Spec) Bytes32(org.apache.tuweni.bytes.Bytes32) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) Domain(tech.pegasys.teku.spec.constants.Domain) BLSSignature(tech.pegasys.teku.bls.BLSSignature) InternalValidationResult.ignore(tech.pegasys.teku.statetransition.validation.InternalValidationResult.ignore) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) Set(java.util.Set) Objects(java.util.Objects) InternalValidationResult.reject(tech.pegasys.teku.statetransition.validation.InternalValidationResult.reject) IntList(it.unimi.dsi.fastutil.ints.IntList) Logger(org.apache.logging.log4j.Logger) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) Optional(java.util.Optional) AsyncBatchBLSSignatureVerifier(tech.pegasys.teku.spec.logic.common.util.AsyncBatchBLSSignatureVerifier) LogManager(org.apache.logging.log4j.LogManager) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Attestation(tech.pegasys.teku.spec.datastructures.operations.Attestation) ValidateableAttestation(tech.pegasys.teku.spec.datastructures.attestation.ValidateableAttestation) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) IntList(it.unimi.dsi.fastutil.ints.IntList) SpecVersion(tech.pegasys.teku.spec.SpecVersion) AsyncBatchBLSSignatureVerifier(tech.pegasys.teku.spec.logic.common.util.AsyncBatchBLSSignatureVerifier) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) AggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.AggregateAndProof) SignedAggregateAndProof(tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof)

Example 17 with SpecVersion

use of tech.pegasys.teku.spec.SpecVersion in project teku by ConsenSys.

the class PrettyPrintCommand method call.

@Override
public Integer call() throws IOException {
    final SpecVersion spec = SpecVersion.create(milestone, SpecConfigLoader.loadConfig(network)).orElseThrow();
    final Bytes inputData;
    try (final InputStream in = openStream()) {
        inputData = Bytes.wrap(IOUtils.toByteArray(in));
    }
    final SszSchema<?> schema = type.getSchema(spec);
    final String json = prettyPrint(schema, inputData);
    SubCommandLogger.SUB_COMMAND_LOG.display(json);
    return 0;
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) SpecVersion(tech.pegasys.teku.spec.SpecVersion) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 18 with SpecVersion

use of tech.pegasys.teku.spec.SpecVersion in project teku by ConsenSys.

the class DataStructureUtil method computeDomain.

private Bytes32 computeDomain() {
    final SpecVersion genesisSpec = spec.getGenesisSpec();
    final Bytes4 domain = Domain.DEPOSIT;
    return genesisSpec.miscHelpers().computeDomain(domain);
}
Also used : SpecVersion(tech.pegasys.teku.spec.SpecVersion) Bytes4(tech.pegasys.teku.infrastructure.bytes.Bytes4)

Example 19 with SpecVersion

use of tech.pegasys.teku.spec.SpecVersion in project teku by ConsenSys.

the class SigningRootUtil method signingRootForSignBlock.

public Bytes signingRootForSignBlock(final BeaconBlock block, final ForkInfo forkInfo) {
    final SpecVersion specVersion = spec.atSlot(block.getSlot());
    final Bytes32 domain = spec.getDomain(Domain.BEACON_PROPOSER, spec.computeEpochAtSlot(block.getSlot()), forkInfo.getFork(), forkInfo.getGenesisValidatorsRoot());
    return specVersion.miscHelpers().computeSigningRoot(block, domain);
}
Also used : SpecVersion(tech.pegasys.teku.spec.SpecVersion) Bytes32(org.apache.tuweni.bytes.Bytes32)

Example 20 with SpecVersion

use of tech.pegasys.teku.spec.SpecVersion in project teku by ConsenSys.

the class RewardsTestExecutorPhase0 method runTest.

@Override
public void runTest(final TestDefinition testDefinition) throws Throwable {
    final BeaconState preState = loadStateFromSsz(testDefinition, "pre.ssz_snappy");
    final ValidatorStatusFactory statusFactory = testDefinition.getSpec().getGenesisSpec().getValidatorStatusFactory();
    final ValidatorStatuses validatorStatuses = statusFactory.createValidatorStatuses(preState);
    final SpecVersion spec = testDefinition.getSpec().getGenesisSpec();
    final RewardsAndPenaltiesCalculatorPhase0 calculator = new RewardsAndPenaltiesCalculatorPhase0(spec.getConfig(), preState, validatorStatuses, spec.miscHelpers(), spec.beaconStateAccessors());
    runTest(testDefinition, calculator);
}
Also used : ValidatorStatuses(tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatuses) SpecVersion(tech.pegasys.teku.spec.SpecVersion) RewardsAndPenaltiesCalculatorPhase0(tech.pegasys.teku.spec.logic.versions.phase0.statetransition.epoch.RewardsAndPenaltiesCalculatorPhase0) ValidatorStatusFactory(tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatusFactory) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Aggregations

SpecVersion (tech.pegasys.teku.spec.SpecVersion)23 Bytes32 (org.apache.tuweni.bytes.Bytes32)12 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)7 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)6 Bytes4 (tech.pegasys.teku.infrastructure.bytes.Bytes4)4 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 ValidatorStatusFactory (tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatusFactory)3 Optional (java.util.Optional)2 Bytes (org.apache.tuweni.bytes.Bytes)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 SafeFuture (tech.pegasys.teku.infrastructure.async.SafeFuture)2 Spec (tech.pegasys.teku.spec.Spec)2 EnrForkId (tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId)2 ValidatorStatuses (tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatuses)2 RecentChainData (tech.pegasys.teku.storage.client.RecentChainData)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 IntList (it.unimi.dsi.fastutil.ints.IntList)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1