use of tech.pegasys.teku.bls.BLSSignatureVerifier 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.bls.BLSSignatureVerifier in project teku by ConsenSys.
the class TransitionTestExecutor method processAltairUpgrade.
private void processAltairUpgrade(final TestDefinition testDefinition, final MetaData metadata) throws Exception {
final UInt64 forkEpoch = UInt64.valueOf(metadata.forkEpoch);
final SpecConfig config = SpecConfigLoader.loadConfig(testDefinition.getConfigName(), c -> c.altairBuilder(a -> a.altairForkEpoch(forkEpoch)));
final Spec spec = SpecFactory.create(config);
final BeaconState preState = TestDataUtils.loadSsz(testDefinition, "pre.ssz_snappy", spec::deserializeBeaconState);
final BeaconState postState = TestDataUtils.loadSsz(testDefinition, "post.ssz_snappy", spec::deserializeBeaconState);
BeaconState result = preState;
for (int i = 0; i < metadata.blocksCount; i++) {
final SignedBeaconBlock block = TestDataUtils.loadSsz(testDefinition, "blocks_" + i + ".ssz_snappy", spec::deserializeSignedBeaconBlock);
try {
final BLSSignatureVerifier signatureVerifier = metadata.blsSetting == 2 ? BLSSignatureVerifier.NO_OP : BLSSignatureVerifier.SIMPLE;
result = spec.processBlock(result, block, signatureVerifier, OptimisticExecutionPayloadExecutor.NOOP);
} catch (final StateTransitionException e) {
Assertions.fail("Failed to process block " + i + " at slot " + block.getSlot() + ": " + e.getMessage(), e);
}
}
assertThatSszData(result).isEqualByGettersTo(postState);
}
Aggregations