use of tech.pegasys.teku.spec.constants.Domain in project teku by ConsenSys.
the class BlockProcessorAltair method processSyncAggregate.
@Override
public void processSyncAggregate(final MutableBeaconState baseState, final SyncAggregate aggregate, final BLSSignatureVerifier signatureVerifier) throws BlockProcessingException {
final MutableBeaconStateAltair state = MutableBeaconStateAltair.required(baseState);
final List<BLSPublicKey> participantPubkeys = new ArrayList<>();
final List<BLSPublicKey> idlePubkeys = new ArrayList<>();
for (int i = 0; i < specConfigAltair.getSyncCommitteeSize(); i++) {
final BLSPublicKey publicKey = syncCommitteeUtil.getCurrentSyncCommitteeParticipantPubKey(state, i);
if (aggregate.getSyncCommitteeBits().getBit(i)) {
participantPubkeys.add(publicKey);
} else {
idlePubkeys.add(publicKey);
}
}
final UInt64 previousSlot = state.getSlot().minusMinZero(1);
final Bytes32 domain = beaconStateAccessors.getDomain(state.getForkInfo(), Domain.SYNC_COMMITTEE, miscHelpers.computeEpochAtSlot(previousSlot));
final Bytes32 signingRoot = miscHelpersAltair.computeSigningRoot(beaconStateAccessors.getBlockRootAtSlot(state, previousSlot), domain);
if (!eth2FastAggregateVerify(signatureVerifier, participantPubkeys, signingRoot, aggregate.getSyncCommitteeSignature().getSignature())) {
throw new BlockProcessingException("Invalid sync committee signature in " + aggregate);
}
// Compute participant and proposer rewards
final UInt64 totalActiveIncrements = beaconStateAccessors.getTotalActiveBalance(state).dividedBy(specConfig.getEffectiveBalanceIncrement());
final UInt64 totalBaseRewards = beaconStateAccessorsAltair.getBaseRewardPerIncrement(state).times(totalActiveIncrements);
final UInt64 maxParticipantRewards = totalBaseRewards.times(SYNC_REWARD_WEIGHT).dividedBy(WEIGHT_DENOMINATOR).dividedBy(specConfig.getSlotsPerEpoch());
final UInt64 participantReward = maxParticipantRewards.dividedBy(specConfigAltair.getSyncCommitteeSize());
final UInt64 proposerReward = participantReward.times(PROPOSER_WEIGHT).dividedBy(WEIGHT_DENOMINATOR.minus(PROPOSER_WEIGHT));
// Apply participant and proposer rewards
participantPubkeys.stream().map(pubkey -> validatorsUtil.getValidatorIndex(state, pubkey).orElseThrow()).forEach(participantIndex -> beaconStateMutators.increaseBalance(state, participantIndex, participantReward));
UInt64 totalProposerReward = proposerReward.times(participantPubkeys.size());
beaconStateMutators.increaseBalance(state, beaconStateAccessors.getBeaconProposerIndex(state), totalProposerReward);
// impose penalties for any idle validators
idlePubkeys.stream().map(pubkey -> validatorsUtil.getValidatorIndex(state, pubkey).orElseThrow()).forEach(participantIndex -> beaconStateMutators.decreaseBalance(state, participantIndex, participantReward));
}
use of tech.pegasys.teku.spec.constants.Domain in project teku by ConsenSys.
the class BlockValidator method blockSignatureIsValidWithRespectToProposerIndex.
private boolean blockSignatureIsValidWithRespectToProposerIndex(SignedBeaconBlock block, BeaconState postState) {
final Bytes32 domain = spec.getDomain(Domain.BEACON_PROPOSER, spec.getCurrentEpoch(postState), postState.getFork(), postState.getGenesis_validators_root());
final Bytes signing_root = spec.computeSigningRoot(block.getMessage(), domain);
final BLSSignature signature = block.getSignature();
boolean signatureValid = spec.getValidatorPubKey(postState, block.getMessage().getProposerIndex()).map(publicKey -> BLS.verify(publicKey, signing_root, signature)).orElse(false);
return signatureValid && receivedValidBlockInfoSet.add(new SlotAndProposer(block));
}
use of tech.pegasys.teku.spec.constants.Domain in project teku by ConsenSys.
the class AttestationUtil method isValidIndexedAttestationAsync.
public SafeFuture<AttestationProcessingResult> isValidIndexedAttestationAsync(Fork fork, BeaconState state, IndexedAttestation indexed_attestation, AsyncBLSSignatureVerifier signatureVerifier) {
SszUInt64List indices = indexed_attestation.getAttesting_indices();
if (indices.isEmpty() || !Comparators.isInStrictOrder(indices.asListUnboxed(), Comparator.naturalOrder())) {
return completedFuture(AttestationProcessingResult.invalid("Attesting indices are not sorted"));
}
List<BLSPublicKey> pubkeys = indices.streamUnboxed().flatMap(i -> beaconStateAccessors.getValidatorPubKey(state, i).stream()).collect(toList());
if (pubkeys.size() < indices.size()) {
return completedFuture(AttestationProcessingResult.invalid("Attesting indices include non-existent validator"));
}
BLSSignature signature = indexed_attestation.getSignature();
Bytes32 domain = beaconStateAccessors.getDomain(Domain.BEACON_ATTESTER, indexed_attestation.getData().getTarget().getEpoch(), fork, state.getGenesis_validators_root());
Bytes signing_root = miscHelpers.computeSigningRoot(indexed_attestation.getData(), domain);
return signatureVerifier.verify(pubkeys, signing_root, signature).thenApply(isValidSignature -> {
if (isValidSignature) {
return AttestationProcessingResult.SUCCESSFUL;
} else {
LOG.debug("AttestationUtil.is_valid_indexed_attestation: Verify aggregate signature");
return AttestationProcessingResult.invalid("Signature is invalid");
}
});
}
Aggregations