|
17 | 17 | import static java.lang.Math.toIntExact;
|
18 | 18 | import static tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH;
|
19 | 19 |
|
20 |
| -import com.google.common.annotations.VisibleForTesting; |
21 | 20 | import it.unimi.dsi.fastutil.ints.IntList;
|
22 | 21 | import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
23 | 22 | import java.util.ArrayList;
|
|
29 | 28 | import org.apache.logging.log4j.Logger;
|
30 | 29 | import org.apache.tuweni.bytes.Bytes;
|
31 | 30 | import org.apache.tuweni.bytes.Bytes32;
|
| 31 | +import tech.pegasys.teku.bls.BLS; |
32 | 32 | import tech.pegasys.teku.bls.BLSPublicKey;
|
33 | 33 | import tech.pegasys.teku.bls.BLSSignature;
|
34 | 34 | import tech.pegasys.teku.bls.BLSSignatureVerifier;
|
| 35 | +import tech.pegasys.teku.bls.impl.BlsException; |
35 | 36 | import tech.pegasys.teku.infrastructure.bytes.Bytes4;
|
36 | 37 | import tech.pegasys.teku.infrastructure.crypto.Hash;
|
37 | 38 | import tech.pegasys.teku.infrastructure.ssz.SszList;
|
|
77 | 78 | import tech.pegasys.teku.spec.logic.versions.bellatrix.block.OptimisticExecutionPayloadExecutor;
|
78 | 79 |
|
79 | 80 | public abstract class AbstractBlockProcessor implements BlockProcessor {
|
80 |
| - |
81 |
| - @VisibleForTesting |
82 |
| - public static final BLSSignatureVerifier DEFAULT_DEPOSIT_SIGNATURE_VERIFIER = |
83 |
| - BLSSignatureVerifier.SIMPLE; |
84 | 81 | /**
|
85 | 82 | * For debug/test purposes only enables/disables {@link DepositData} BLS signature verification
|
86 | 83 | * Setting to <code>false</code> significantly speeds up state initialization
|
87 | 84 | */
|
88 |
| - @VisibleForTesting |
89 |
| - public static BLSSignatureVerifier depositSignatureVerifier = DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; |
| 85 | + public static boolean blsVerifyDeposit = true; |
90 | 86 |
|
91 | 87 | private static final Logger LOG = LogManager.getLogger();
|
92 | 88 |
|
@@ -610,25 +606,30 @@ public void processDeposits(MutableBeaconState state, SszList<? extends Deposit>
|
610 | 606 | throws BlockProcessingException {
|
611 | 607 | safelyProcess(
|
612 | 608 | () -> {
|
613 |
| - final boolean depositSignaturesAreAllGood = batchVerifyDepositSignatures(deposits); |
| 609 | + final boolean depositSignaturesAreAllGood = |
| 610 | + !blsVerifyDeposit || batchVerifyDepositSignatures(deposits); |
614 | 611 | for (Deposit deposit : deposits) {
|
615 | 612 | processDeposit(state, deposit, depositSignaturesAreAllGood);
|
616 | 613 | }
|
617 | 614 | });
|
618 | 615 | }
|
619 | 616 |
|
620 | 617 | private boolean batchVerifyDepositSignatures(SszList<? extends Deposit> deposits) {
|
621 |
| - final List<List<BLSPublicKey>> publicKeys = new ArrayList<>(); |
622 |
| - final List<Bytes> messages = new ArrayList<>(); |
623 |
| - final List<BLSSignature> signatures = new ArrayList<>(); |
624 |
| - for (Deposit deposit : deposits) { |
625 |
| - final BLSPublicKey pubkey = deposit.getData().getPubkey(); |
626 |
| - publicKeys.add(List.of(pubkey)); |
627 |
| - messages.add(computeDepositSigningRoot(deposit, pubkey)); |
628 |
| - signatures.add(deposit.getData().getSignature()); |
| 618 | + try { |
| 619 | + final List<List<BLSPublicKey>> publicKeys = new ArrayList<>(); |
| 620 | + final List<Bytes> messages = new ArrayList<>(); |
| 621 | + final List<BLSSignature> signatures = new ArrayList<>(); |
| 622 | + for (Deposit deposit : deposits) { |
| 623 | + final BLSPublicKey pubkey = deposit.getData().getPubkey(); |
| 624 | + publicKeys.add(List.of(pubkey)); |
| 625 | + messages.add(computeDepositSigningRoot(deposit, pubkey)); |
| 626 | + signatures.add(deposit.getData().getSignature()); |
| 627 | + } |
| 628 | + // Overwhelmingly often we expect all the deposit signatures to be good |
| 629 | + return BLS.batchVerify(publicKeys, messages, signatures); |
| 630 | + } catch (final BlsException e) { |
| 631 | + return false; |
629 | 632 | }
|
630 |
| - // Overwhelmingly often we expect all the deposit signatures to be good |
631 |
| - return depositSignatureVerifier.verify(publicKeys, messages, signatures); |
632 | 633 | }
|
633 | 634 |
|
634 | 635 | public void processDeposit(
|
@@ -704,8 +705,13 @@ private void handleInvalidDeposit(
|
704 | 705 | }
|
705 | 706 |
|
706 | 707 | private boolean depositSignatureIsValid(final Deposit deposit, BLSPublicKey pubkey) {
|
707 |
| - return depositSignatureVerifier.verify( |
708 |
| - pubkey, computeDepositSigningRoot(deposit, pubkey), deposit.getData().getSignature()); |
| 708 | + try { |
| 709 | + return !blsVerifyDeposit |
| 710 | + || BLS.verify( |
| 711 | + pubkey, computeDepositSigningRoot(deposit, pubkey), deposit.getData().getSignature()); |
| 712 | + } catch (final BlsException e) { |
| 713 | + return false; |
| 714 | + } |
709 | 715 | }
|
710 | 716 |
|
711 | 717 | private Bytes computeDepositSigningRoot(final Deposit deposit, BLSPublicKey pubkey) {
|
|
0 commit comments