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