diff --git a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockFactoryTest.java b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockFactoryTest.java index 019c4dd26c2..c6a7f621e12 100644 --- a/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockFactoryTest.java +++ b/beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/BlockFactoryTest.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import tech.pegasys.teku.bls.BLSSignature; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.ssz.SszList; import tech.pegasys.teku.infrastructure.unsigned.UInt64; @@ -94,12 +95,13 @@ class BlockFactoryTest { @BeforeAll public static void initSession() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void resetSession() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } @Test diff --git a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/EpochTransitionBenchmark.java b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/EpochTransitionBenchmark.java index 64a2515b73a..5be243872a7 100644 --- a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/EpochTransitionBenchmark.java +++ b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/EpochTransitionBenchmark.java @@ -34,6 +34,7 @@ import tech.pegasys.teku.benchmarks.gen.BlsKeyPairIO; import tech.pegasys.teku.benchmarks.util.CustomRunner; import tech.pegasys.teku.bls.BLSKeyPair; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread; import tech.pegasys.teku.infrastructure.ssz.collections.SszMutableUInt64List; import tech.pegasys.teku.infrastructure.unsigned.UInt64; @@ -88,7 +89,7 @@ public class EpochTransitionBenchmark { @Setup(Level.Trial) public void init() throws Exception { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; spec = TestSpecFactory.createMainnetAltair(); String blocksFile = diff --git a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ProcessSyncAggregateBenchmark.java b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ProcessSyncAggregateBenchmark.java index 71af135f9f9..54adea0bc9b 100644 --- a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ProcessSyncAggregateBenchmark.java +++ b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ProcessSyncAggregateBenchmark.java @@ -63,7 +63,7 @@ public class ProcessSyncAggregateBenchmark { @Setup(Level.Trial) public void init() throws Exception { spec = TestSpecFactory.createMainnetAltair(); - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; String blocksFile = "/blocks/blocks_epoch_" diff --git a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ProfilingRun.java b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ProfilingRun.java index 2a6c12744ac..c86dc9e3ce4 100644 --- a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ProfilingRun.java +++ b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/ProfilingRun.java @@ -28,6 +28,7 @@ import tech.pegasys.teku.benchmarks.gen.BlsKeyPairIO; import tech.pegasys.teku.bls.BLSKeyPair; import tech.pegasys.teku.bls.BLSPublicKey; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.bls.BLSTestUtil; import tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread; import tech.pegasys.teku.infrastructure.unsigned.UInt64; @@ -63,7 +64,7 @@ public class ProfilingRun { @Test public void importBlocks() throws Exception { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; int validatorsCount = 32 * 1024; int iterationBlockLimit = 1024; @@ -157,7 +158,7 @@ public static void main(String[] args) throws Exception { @Test public void importBlocksMemProfiling() throws Exception { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; int validatorsCount = 32 * 1024; diff --git a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/TransitionBenchmark.java b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/TransitionBenchmark.java index cbe88548422..a1761d3dc08 100644 --- a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/TransitionBenchmark.java +++ b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/TransitionBenchmark.java @@ -32,6 +32,7 @@ import tech.pegasys.teku.benchmarks.gen.BlockIO; import tech.pegasys.teku.benchmarks.gen.BlsKeyPairIO; import tech.pegasys.teku.bls.BLSKeyPair; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.Spec; @@ -72,7 +73,7 @@ public abstract class TransitionBenchmark { @Setup(Level.Trial) public void init() throws Exception { spec = TestSpecFactory.createMainnetAltair(); - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; String blocksFile = "/blocks/blocks_epoch_" diff --git a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/gen/Generator.java b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/gen/Generator.java index 66a6fec3665..835df3a1355 100644 --- a/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/gen/Generator.java +++ b/eth-benchmark-tests/src/jmh/java/tech/pegasys/teku/benchmarks/gen/Generator.java @@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test; import tech.pegasys.teku.benchmarks.gen.BlockIO.Writer; import tech.pegasys.teku.bls.BLSKeyPair; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.bls.BLSTestUtil; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.Spec; @@ -49,7 +50,7 @@ public class Generator { public void generateBlocks() throws Exception { final Spec spec = TestSpecFactory.createMainnetAltair(); - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; System.out.println("Generating keypairs..."); int validatorsCount = 400000; diff --git a/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/BuilderCircuitBreakerImplTest.java b/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/BuilderCircuitBreakerImplTest.java index c9054b10e98..e7c8d266932 100644 --- a/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/BuilderCircuitBreakerImplTest.java +++ b/ethereum/executionlayer/src/test/java/tech/pegasys/teku/ethereum/executionlayer/BuilderCircuitBreakerImplTest.java @@ -19,6 +19,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.TestSpecFactory; @@ -43,12 +44,13 @@ public class BuilderCircuitBreakerImplTest { @BeforeAll public static void disableDepositBlsVerification() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void enableDepositBlsVerification() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } @BeforeEach diff --git a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java index 71b6dc4fa51..e5d7e5550f2 100644 --- a/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java +++ b/ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/common/block/AbstractBlockProcessor.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static tech.pegasys.teku.spec.config.SpecConfig.FAR_FUTURE_EPOCH; +import com.google.common.annotations.VisibleForTesting; import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.objects.Object2IntMap; import java.util.ArrayList; @@ -28,7 +29,6 @@ import org.apache.logging.log4j.Logger; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; -import tech.pegasys.teku.bls.BLS; import tech.pegasys.teku.bls.BLSPublicKey; import tech.pegasys.teku.bls.BLSSignature; import tech.pegasys.teku.bls.BLSSignatureVerifier; @@ -81,11 +81,16 @@ import tech.pegasys.teku.spec.logic.versions.deneb.block.KzgCommitmentsProcessor; public abstract class AbstractBlockProcessor implements BlockProcessor { + + @VisibleForTesting + public static final BLSSignatureVerifier DEFAULT_DEPOSIT_SIGNATURE_VERIFIER = + BLSSignatureVerifier.SIMPLE; /** * For debug/test purposes only enables/disables {@link DepositData} BLS signature verification * Setting to false significantly speeds up state initialization */ - public static boolean blsVerifyDeposit = true; + @VisibleForTesting + public static BLSSignatureVerifier depositSignatureVerifier = DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; private static final Logger LOG = LogManager.getLogger(); @@ -667,8 +672,7 @@ public void processDeposits(MutableBeaconState state, SszList throws BlockProcessingException { safelyProcess( () -> { - final boolean depositSignaturesAreAllGood = - !blsVerifyDeposit || batchVerifyDepositSignatures(deposits); + final boolean depositSignaturesAreAllGood = batchVerifyDepositSignatures(deposits); for (Deposit deposit : deposits) { processDeposit(state, deposit, depositSignaturesAreAllGood); } @@ -687,7 +691,7 @@ private boolean batchVerifyDepositSignatures(SszList deposits signatures.add(deposit.getData().getSignature()); } // Overwhelmingly often we expect all the deposit signatures to be good - return BLS.batchVerify(publicKeys, messages, signatures); + return depositSignatureVerifier.verify(publicKeys, messages, signatures); } catch (final BlsException e) { return false; } @@ -767,9 +771,8 @@ private void handleInvalidDeposit( private boolean depositSignatureIsValid(final Deposit deposit, BLSPublicKey pubkey) { try { - return !blsVerifyDeposit - || BLS.verify( - pubkey, computeDepositSigningRoot(deposit, pubkey), deposit.getData().getSignature()); + return depositSignatureVerifier.verify( + pubkey, computeDepositSigningRoot(deposit, pubkey), deposit.getData().getSignature()); } catch (final BlsException e) { return false; } diff --git a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/common/block/BlockProcessorTest.java b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/common/block/BlockProcessorTest.java index 0bec89e31e1..a9d443b83a3 100644 --- a/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/common/block/BlockProcessorTest.java +++ b/ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/common/block/BlockProcessorTest.java @@ -57,8 +57,9 @@ public abstract class BlockProcessorTest { protected abstract Spec createSpec(); @Test - void ensureVerifyDepositDefaultsToTrue() { - assertThat(AbstractBlockProcessor.blsVerifyDeposit).isTrue(); + void ensureDepositSignatureVerifierHasDefaultValue() { + assertThat(AbstractBlockProcessor.depositSignatureVerifier) + .isSameAs(AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER); } @Test diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/block/BlockImporterTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/block/BlockImporterTest.java index c1354ee0358..6f5ca3bc005 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/block/BlockImporterTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/block/BlockImporterTest.java @@ -34,6 +34,7 @@ import org.mockito.ArgumentCaptor; import tech.pegasys.teku.bls.BLSKeyGenerator; import tech.pegasys.teku.bls.BLSKeyPair; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.bls.BLSTestUtil; import tech.pegasys.teku.ethereum.execution.types.Eth1Address; import tech.pegasys.teku.infrastructure.async.SafeFuture; @@ -116,12 +117,13 @@ public class BlockImporterTest { @BeforeAll public static void init() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void dispose() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } @BeforeEach diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/block/BlockManagerTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/block/BlockManagerTest.java index 9c5b54481cc..8a452972e1c 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/block/BlockManagerTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/block/BlockManagerTest.java @@ -45,6 +45,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread; import tech.pegasys.teku.infrastructure.collections.LimitedMap; @@ -143,12 +144,13 @@ public class BlockManagerTest { @BeforeAll public static void initSession() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void resetSession() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } @BeforeEach diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceNotifierTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceNotifierTest.java index b9d27a225d8..fd9058af8fd 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceNotifierTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoiceNotifierTest.java @@ -37,6 +37,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.invocation.InvocationOnMock; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.ethereum.execution.types.Eth1Address; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.async.SafeFutureAssert; @@ -93,12 +94,13 @@ class ForkChoiceNotifierTest { @BeforeAll public static void initSession() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void resetSession() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } @BeforeEach diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoicePayloadExecutorTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoicePayloadExecutorTest.java index b53a17b48ab..4cf75d53044 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoicePayloadExecutorTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/ForkChoicePayloadExecutorTest.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.spec.Spec; import tech.pegasys.teku.spec.TestSpecFactory; @@ -59,12 +60,13 @@ class ForkChoicePayloadExecutorTest { @BeforeAll public static void initSession() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void resetSession() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } @BeforeEach diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/MergeTransitionBlockValidatorTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/MergeTransitionBlockValidatorTest.java index a5014e778b2..35315a9ce02 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/MergeTransitionBlockValidatorTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/MergeTransitionBlockValidatorTest.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.exceptions.FatalServiceFailureException; import tech.pegasys.teku.infrastructure.unsigned.UInt64; @@ -52,12 +53,13 @@ class MergeTransitionBlockValidatorTest { @BeforeAll public static void initSession() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void resetSession() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } /** diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/TerminalPowBlockMonitorTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/TerminalPowBlockMonitorTest.java index 98b49a9bb4f..8a667b195aa 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/TerminalPowBlockMonitorTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/forkchoice/TerminalPowBlockMonitorTest.java @@ -35,6 +35,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; import tech.pegasys.infrastructure.logging.LogCaptor; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.async.StubAsyncRunner; import tech.pegasys.teku.infrastructure.logging.EventLogger; @@ -77,12 +78,13 @@ public class TerminalPowBlockMonitorTest { @BeforeAll public static void initSession() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void resetSession() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } private void setUpTerminalBlockHashConfig() { diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AggregateAttestationValidatorTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AggregateAttestationValidatorTest.java index e27fe81e88f..19d877547db 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AggregateAttestationValidatorTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AggregateAttestationValidatorTest.java @@ -127,12 +127,13 @@ class AggregateAttestationValidatorTest { @BeforeAll public static void init() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void reset() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } @BeforeEach diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AttestationStateSelectorTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AttestationStateSelectorTest.java index 4c60816c25d..e8d3422a888 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AttestationStateSelectorTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AttestationStateSelectorTest.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.Spec; @@ -52,12 +53,13 @@ class AttestationStateSelectorTest { @BeforeAll public static void initSession() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void resetSession() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } @BeforeEach diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AttestationValidatorTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AttestationValidatorTest.java index a6190b436a1..fb24bbac680 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AttestationValidatorTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/AttestationValidatorTest.java @@ -108,12 +108,13 @@ class AttestationValidatorTest { @BeforeAll public static void init() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void reset() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } @BeforeEach diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/BlockValidatorTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/BlockValidatorTest.java index ca527b9f937..5b71f63771f 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/BlockValidatorTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/BlockValidatorTest.java @@ -26,6 +26,7 @@ import tech.pegasys.teku.bls.BLSKeyGenerator; import tech.pegasys.teku.bls.BLSKeyPair; import tech.pegasys.teku.bls.BLSSignature; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.bls.BLSTestUtil; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.unsigned.UInt64; @@ -54,12 +55,13 @@ public class BlockValidatorTest { @BeforeAll public static void initSession() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void resetSession() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } @BeforeEach diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/GossipValidationHelperTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/GossipValidationHelperTest.java index 91950d4decc..3718b6bc79f 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/GossipValidationHelperTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/validation/GossipValidationHelperTest.java @@ -23,6 +23,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestTemplate; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.infrastructure.async.SafeFutureAssert; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.spec.Spec; @@ -49,12 +50,13 @@ public class GossipValidationHelperTest { @BeforeAll public static void initSession() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void resetSession() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } @BeforeEach diff --git a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLS.java b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLS.java index 824b302c9ef..5a35bdc5dcd 100644 --- a/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLS.java +++ b/infrastructure/bls/src/main/java/tech/pegasys/teku/bls/BLS.java @@ -152,13 +152,14 @@ public static boolean aggregateVerify( if (publicKeys.isEmpty()) { return false; } - List publicKeyMessagePairs = - Streams.zip( - publicKeys.stream(), - messages.stream(), - (pk, msg) -> new PublicKeyMessagePair(pk.getPublicKey(), msg)) - .collect(Collectors.toList()); try { + List publicKeyMessagePairs = + Streams.zip( + publicKeys.stream(), + messages.stream(), + (pk, msg) -> new PublicKeyMessagePair(pk.getPublicKey(), msg)) + .collect(Collectors.toList()); + return signature.getSignature().verify(publicKeyMessagePairs); } catch (BlsException e) { return false; @@ -192,9 +193,10 @@ public static boolean fastAggregateVerify( if (publicKeys.isEmpty()) { return false; } - List publicKeyObjects = - publicKeys.stream().map(BLSPublicKey::getPublicKey).collect(Collectors.toList()); try { + List publicKeyObjects = + publicKeys.stream().map(BLSPublicKey::getPublicKey).collect(Collectors.toList()); + return signature.getSignature().verify(publicKeyObjects, message); } catch (BlsException e) { return false; diff --git a/infrastructure/bls/src/test/java/tech/pegasys/teku/bls/BLSTest.java b/infrastructure/bls/src/test/java/tech/pegasys/teku/bls/BLSTest.java index 698ffcc87d5..8a77d661b4d 100644 --- a/infrastructure/bls/src/test/java/tech/pegasys/teku/bls/BLSTest.java +++ b/infrastructure/bls/src/test/java/tech/pegasys/teku/bls/BLSTest.java @@ -125,6 +125,47 @@ void fastAggregateVerify_verify4Signers() { assertTrue(BLS.fastAggregateVerify(publicKeys, message, aggregatedSignature)); } + @Test + void anyVerify_invalidPublicKeyShouldNotThrowAndReturnFalse() { + BLSKeyPair keyPair = BLSTestUtil.randomKeyPair(1); + Bytes message = + Bytes.fromHexString("0x999bb85f3690c2ccb1607dd3e11a7e114038eb4044bdbdd340bc81aa3e5e0c9e"); + BLSPublicKey invalidkey = + BLSPublicKey.fromBytesCompressed( + Bytes48.fromHexString( + "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); + BLSPublicKey validkey = + BLSPublicKey.fromBytesCompressed(keyPair.getPublicKey().toBytesCompressed()); + BLSSignature signature = BLS.sign(keyPair.getSecretKey(), message); + + assertFalse(BLS.verify(invalidkey, message, signature)); + assertFalse(BLS.aggregateVerify(List.of(invalidkey), List.of(message), signature)); + assertFalse( + BLS.aggregateVerify(List.of(validkey, invalidkey), List.of(message, message), signature)); + assertFalse(BLS.fastAggregateVerify(List.of(invalidkey), message, signature)); + assertFalse( + BLS.fastAggregateVerify(List.of(validkey, validkey, invalidkey), message, signature)); + + assertFalse( + BLS.batchVerify( + List.of(List.of(validkey), List.of(invalidkey)), + List.of(message, message), + List.of(signature, signature))); + + int validationCount = 64; + List> manyKeys = + Stream.concat( + Stream.generate(() -> validkey).limit(validationCount - 1), Stream.of(invalidkey)) + .map(List::of) + .collect(Collectors.toList()); + List manyMessages = + Stream.generate(() -> message).limit(validationCount).collect(Collectors.toList()); + List manySignatures = + Stream.generate(() -> signature).limit(validationCount).collect(Collectors.toList()); + + assertFalse(BLS.batchVerify(manyKeys, manyMessages, manySignatures)); + } + @Test void succeedsWhenAggregateVerifyWithDistinctMessagesReturnsTrue() { Bytes message1 = Bytes.wrap("Hello, world 1!".getBytes(UTF_8)); diff --git a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/PeerStatusIntegrationTest.java b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/PeerStatusIntegrationTest.java index 435d152d21c..bddec462209 100644 --- a/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/PeerStatusIntegrationTest.java +++ b/networking/eth2/src/integration-test/java/tech/pegasys/teku/networking/eth2/PeerStatusIntegrationTest.java @@ -24,6 +24,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.infrastructure.bytes.Bytes4; import tech.pegasys.teku.infrastructure.unsigned.UInt64; import tech.pegasys.teku.networking.eth2.peers.Eth2Peer; @@ -49,12 +50,13 @@ public class PeerStatusIntegrationTest { @BeforeAll public static void initSession() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void resetSession() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } @AfterEach diff --git a/storage/src/test/java/tech/pegasys/teku/storage/client/RecentChainDataTest.java b/storage/src/test/java/tech/pegasys/teku/storage/client/RecentChainDataTest.java index 6ab6ebeff21..4501af4e243 100644 --- a/storage/src/test/java/tech/pegasys/teku/storage/client/RecentChainDataTest.java +++ b/storage/src/test/java/tech/pegasys/teku/storage/client/RecentChainDataTest.java @@ -32,6 +32,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import tech.pegasys.teku.bls.BLSKeyGenerator; +import tech.pegasys.teku.bls.BLSSignatureVerifier; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory; import tech.pegasys.teku.infrastructure.unsigned.UInt64; @@ -98,12 +99,13 @@ private void generateGenesisWithoutIniting() { @BeforeAll public static void disableDepositBlsVerification() { - AbstractBlockProcessor.blsVerifyDeposit = false; + AbstractBlockProcessor.depositSignatureVerifier = BLSSignatureVerifier.NO_OP; } @AfterAll public static void enableDepositBlsVerification() { - AbstractBlockProcessor.blsVerifyDeposit = true; + AbstractBlockProcessor.depositSignatureVerifier = + AbstractBlockProcessor.DEFAULT_DEPOSIT_SIGNATURE_VERIFIER; } @Test