diff --git a/crypto/algorithms/src/main/java/org/hyperledger/besu/crypto/CodeDelegationSignature.java b/crypto/algorithms/src/main/java/org/hyperledger/besu/crypto/CodeDelegationSignature.java index 70fc2bde489..06ec72bf0a9 100644 --- a/crypto/algorithms/src/main/java/org/hyperledger/besu/crypto/CodeDelegationSignature.java +++ b/crypto/algorithms/src/main/java/org/hyperledger/besu/crypto/CodeDelegationSignature.java @@ -56,7 +56,7 @@ public static CodeDelegationSignature create( "Invalid 's' value, should be < 2^256 but got " + s.toString(16)); } - if (yParity.compareTo(TWO_POW_256) > 0) { + if (yParity.compareTo(TWO_POW_256) >= 0) { throw new IllegalArgumentException( "Invalid 'yParity' value, should be < 2^256 but got " + yParity.toString(16)); } diff --git a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/CodeDelegationSignatureTest.java b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/CodeDelegationSignatureTest.java index 79ca542d62c..332aa14893f 100644 --- a/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/CodeDelegationSignatureTest.java +++ b/crypto/algorithms/src/test/java/org/hyperledger/besu/crypto/CodeDelegationSignatureTest.java @@ -78,6 +78,17 @@ void testSValueExceedsTwoPow256() { .withMessageContainingAll("Invalid 's' value, should be < 2^256"); } + @Test + void testYParityExceedsTwoPow256() { + BigInteger r = BigInteger.ONE; + BigInteger s = BigInteger.TWO; + BigInteger yParity = TWO_POW_256; + + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> CodeDelegationSignature.create(r, s, yParity)) + .withMessageContainingAll("Invalid 'yParity' value, should be < 2^256"); + } + @Test void testValidYParityZero() { BigInteger r = BigInteger.ONE;