ECRec precompile should return empty instead of 0 when the input is invalid. (#227)

Adrian Sutton 6 years ago committed by Lucas Saldanha
parent 8354acd071
commit a07a5d64ae
  1. 4
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/ECRECPrecompiledContract.java
  2. 5
      ethereum/core/src/test/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/ECRECPrecompiledContractTest.java

@ -72,7 +72,7 @@ public class ECRECPrecompiledContract extends AbstractPrecompiledContract {
try { try {
final Optional<PublicKey> recovered = PublicKey.recoverFromSignature(h, signature); final Optional<PublicKey> recovered = PublicKey.recoverFromSignature(h, signature);
if (!recovered.isPresent()) { if (!recovered.isPresent()) {
return Bytes32.ZERO; return Bytes32.EMPTY;
} }
final Bytes32 hashed = Hash.hash(recovered.get().getEncodedBytes()); final Bytes32 hashed = Hash.hash(recovered.get().getEncodedBytes());
@ -80,7 +80,7 @@ public class ECRECPrecompiledContract extends AbstractPrecompiledContract {
hashed.slice(12).copyTo(result, 12); hashed.slice(12).copyTo(result, 12);
return result; return result;
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
return Bytes32.ZERO; return Bytes32.EMPTY;
} }
} }
} }

@ -37,7 +37,7 @@ public class ECRECPrecompiledContractTest {
return new Object[][] { return new Object[][] {
{ {
"acb1c19ac0832320815b5e886c6b73ad7d6177853d44b026f2a7a9e11bb899fc000000000000000000000000000000000000000000000000000000000000001c89ea49159b334f9aebbf54481b69d000d285baa341899db355a4030f6838394e540e9f9fa17bef441e32d98d5f4554cfefdc6a56101352e4b92efafd0d9646e8", "acb1c19ac0832320815b5e886c6b73ad7d6177853d44b026f2a7a9e11bb899fc000000000000000000000000000000000000000000000000000000000000001c89ea49159b334f9aebbf54481b69d000d285baa341899db355a4030f6838394e540e9f9fa17bef441e32d98d5f4554cfefdc6a56101352e4b92efafd0d9646e8",
"0x" null
}, },
{ {
"0x0049872459827432342344987245982743234234498724598274323423429943000000000000000000000000000000000000000000000000000000000000001be8359c341771db7f9ea3a662a1741d27775ce277961470028e054ed3285aab8e31f63eaac35c4e6178abbc2a1073040ac9bbb0b67f2bc89a2e9593ba9abe8c53", "0x0049872459827432342344987245982743234234498724598274323423429943000000000000000000000000000000000000000000000000000000000000001be8359c341771db7f9ea3a662a1741d27775ce277961470028e054ed3285aab8e31f63eaac35c4e6178abbc2a1073040ac9bbb0b67f2bc89a2e9593ba9abe8c53",
@ -454,7 +454,8 @@ public class ECRECPrecompiledContractTest {
@Test @Test
public void shouldRecoverAddress() { public void shouldRecoverAddress() {
final BytesValue input = BytesValue.fromHexString(this.input); 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); assertThat(contract.compute(input)).isEqualTo(expected);
} }
} }

Loading…
Cancel
Save