From a07a5d64aef8a8104291687c7bd4e9e54b1da713 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Thu, 1 Nov 2018 20:20:35 +1000 Subject: [PATCH] ECRec precompile should return empty instead of 0 when the input is invalid. (#227) --- .../mainnet/precompiles/ECRECPrecompiledContract.java | 4 ++-- .../mainnet/precompiles/ECRECPrecompiledContractTest.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/ECRECPrecompiledContract.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/ECRECPrecompiledContract.java index 5c52556902..0f994139fd 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/ECRECPrecompiledContract.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/ECRECPrecompiledContract.java @@ -72,7 +72,7 @@ public class ECRECPrecompiledContract extends AbstractPrecompiledContract { try { final Optional recovered = PublicKey.recoverFromSignature(h, signature); if (!recovered.isPresent()) { - return Bytes32.ZERO; + return Bytes32.EMPTY; } final Bytes32 hashed = Hash.hash(recovered.get().getEncodedBytes()); @@ -80,7 +80,7 @@ public class ECRECPrecompiledContract extends AbstractPrecompiledContract { hashed.slice(12).copyTo(result, 12); return result; } catch (final IllegalArgumentException e) { - return Bytes32.ZERO; + return Bytes32.EMPTY; } } } diff --git a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/ECRECPrecompiledContractTest.java b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/ECRECPrecompiledContractTest.java index f6bf7b6587..727b34d7e6 100644 --- a/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/ECRECPrecompiledContractTest.java +++ b/ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/ECRECPrecompiledContractTest.java @@ -37,7 +37,7 @@ public class ECRECPrecompiledContractTest { return new Object[][] { { "acb1c19ac0832320815b5e886c6b73ad7d6177853d44b026f2a7a9e11bb899fc000000000000000000000000000000000000000000000000000000000000001c89ea49159b334f9aebbf54481b69d000d285baa341899db355a4030f6838394e540e9f9fa17bef441e32d98d5f4554cfefdc6a56101352e4b92efafd0d9646e8", - "0x" + null }, { "0x0049872459827432342344987245982743234234498724598274323423429943000000000000000000000000000000000000000000000000000000000000001be8359c341771db7f9ea3a662a1741d27775ce277961470028e054ed3285aab8e31f63eaac35c4e6178abbc2a1073040ac9bbb0b67f2bc89a2e9593ba9abe8c53", @@ -454,7 +454,8 @@ public class ECRECPrecompiledContractTest { @Test public void shouldRecoverAddress() { final BytesValue input = BytesValue.fromHexString(this.input); - final BytesValue expected = Bytes32.fromHexString(expectedResult); + final BytesValue expected = + expectedResult == null ? BytesValue.EMPTY : Bytes32.fromHexString(expectedResult); assertThat(contract.compute(input)).isEqualTo(expected); } }