From 3eeeb97ff8b9c482c8aef15c0354659962858e13 Mon Sep 17 00:00:00 2001 From: Volodymyr Kravets Date: Fri, 19 Apr 2024 15:11:39 +0300 Subject: [PATCH] fix: allow data with size lower than 4 bytes --- .../src/main/java/co/rsk/rpc/modules/eth/EthModule.java | 7 ++++++- .../rpc/exception/RskJsonRpcRequestException.java | 8 +++----- .../org/ethereum/rpc/exception/RskErrorResolverTest.java | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java b/rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java index acb5e1d2eb9..e7e0f978b0b 100644 --- a/rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java +++ b/rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java @@ -318,11 +318,16 @@ public ProgramResult callConstant(CallArguments args, Block executionBlock) { */ public static Pair decodeProgramRevert(ProgramResult programResult) { byte[] bytes = programResult.getHReturn(); - if (bytes == null || bytes.length < 4) { + if (bytes == null) { return Pair.of(null, null); } + if (bytes.length < 4) { + + return Pair.of(null, bytes); + } + final byte[] signature = copyOfRange(bytes, 0, 4); if (!Arrays.equals(signature, ERROR_ABI_FUNCTION_SIGNATURE)) { diff --git a/rskj-core/src/main/java/org/ethereum/rpc/exception/RskJsonRpcRequestException.java b/rskj-core/src/main/java/org/ethereum/rpc/exception/RskJsonRpcRequestException.java index a5a7578f540..bab3bceb406 100644 --- a/rskj-core/src/main/java/org/ethereum/rpc/exception/RskJsonRpcRequestException.java +++ b/rskj-core/src/main/java/org/ethereum/rpc/exception/RskJsonRpcRequestException.java @@ -16,7 +16,7 @@ protected RskJsonRpcRequestException(Integer code, @Nullable byte[] revertData, } protected RskJsonRpcRequestException(Integer code, String message, Exception e) { - this(code, new byte[]{}, message, e); + this(code, null, message, e); } public RskJsonRpcRequestException(Integer code, @Nullable byte[] revertData, String message) { @@ -26,7 +26,7 @@ public RskJsonRpcRequestException(Integer code, @Nullable byte[] revertData, Str } public RskJsonRpcRequestException(Integer code, String message) { - this(code, new byte[]{}, message); + this(code, null, message); } public Integer getCode() { @@ -50,9 +50,7 @@ public static RskJsonRpcRequestException transactionRevertedExecutionError( @Nonnull byte[] revertData ) { return executionError( - revertReason.isEmpty() - ? "transaction reverted, no reason specified" - : "revert " + revertReason, + "revert " + revertReason, revertData ); } diff --git a/rskj-core/src/test/java/org/ethereum/rpc/exception/RskErrorResolverTest.java b/rskj-core/src/test/java/org/ethereum/rpc/exception/RskErrorResolverTest.java index 53ca05d1604..08ebd954a25 100644 --- a/rskj-core/src/test/java/org/ethereum/rpc/exception/RskErrorResolverTest.java +++ b/rskj-core/src/test/java/org/ethereum/rpc/exception/RskErrorResolverTest.java @@ -38,7 +38,7 @@ void test_resolveError_givenRskJsonRpcRequestExceptionWithoutData_returnsJsonErr // Given Integer code = 1; String message = "message"; - String expectedData = "0x"; + String expectedData = null; RskJsonRpcRequestException exception = new RskJsonRpcRequestException(code, message); Method methodMock = this.getClass().getMethod("mockMethod");