Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Throw if ECKey.recoverPubBytesFromSignature results in point at infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalinin committed May 3, 2018
1 parent 17dfc1e commit df3350b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ethereumj-core/src/main/java/org/ethereum/crypto/ECKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,9 @@ public static byte[] recoverPubBytesFromSignature(int recId, ECDSASignature sig,
BigInteger srInv = rInv.multiply(sig.s).mod(n);
BigInteger eInvrInv = rInv.multiply(eInv).mod(n);
ECPoint.Fp q = (ECPoint.Fp) ECAlgorithms.sumOfTwoMultiplies(CURVE.getG(), eInvrInv, R, srInv);
// result sanity check: point must not be at infinity
if (q.isInfinity())
return null;
return q.getEncoded(/* compressed */ false);
}

Expand Down
16 changes: 16 additions & 0 deletions ethereumj-core/src/test/java/org/ethereum/crypto/ECKeyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,22 @@ public void testVerifySignature3() throws SignatureException {
// todo: add test assertion when the sign/verify part actually works.
}

@Test // result is a point at infinity
public void testVerifySignature4() {

byte[] hash = Hex.decode("acb1c19ac0832320815b5e886c6b73ad7d6177853d44b026f2a7a9e11bb899fc");
byte[] r = Hex.decode("89ea49159b334f9aebbf54481b69d000d285baa341899db355a4030f6838394e");
byte[] s = Hex.decode("540e9f9fa17bef441e32d98d5f4554cfefdc6a56101352e4b92efafd0d9646e8");
byte v = (byte) 28;

ECDSASignature sig = ECKey.ECDSASignature.fromComponents(r, s, v);

try {
ECKey.signatureToKey(hash, sig);
fail("Result is a point at infinity, recovery must fail");
} catch (SignatureException e) {
}
}

@Test
public void testSValue() throws Exception {
Expand Down

0 comments on commit df3350b

Please sign in to comment.