Fix evmtool JSON Error Field to Return Hex String Instead of Long Null String on REVERT (#7774)

Signed-off-by: 7at <itisfor@outlook.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/7816/head
7at 4 weeks ago committed by GitHub
parent 8ed4a904f1
commit 42b3cd4291
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java
  2. 2
      ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/revert.json
  3. 35
      evm/src/main/java/org/hyperledger/besu/evm/tracing/StandardJsonTracer.java
  4. 5
      evm/src/test/java/org/hyperledger/besu/evm/toy/EvmToyCommand.java

@ -529,9 +529,7 @@ public class EvmToolCommand implements Runnable {
messageFrame messageFrame
.getExceptionalHaltReason() .getExceptionalHaltReason()
.ifPresent(haltReason -> out.println(haltReason)); .ifPresent(haltReason -> out.println(haltReason));
messageFrame messageFrame.getRevertReason().ifPresent(bytes -> out.println(bytes.toHexString()));
.getRevertReason()
.ifPresent(bytes -> out.println(new String(bytes.toArrayUnsafe(), UTF_8)));
} }
} }
} }

@ -12,7 +12,7 @@
{"pc":7,"op":82,"gas":"0x2540be3fa","gasCost":"0x6","memSize":0,"stack":["0x4e6f7065","0x0"],"depth":1,"refund":0,"opName":"MSTORE"}, {"pc":7,"op":82,"gas":"0x2540be3fa","gasCost":"0x6","memSize":0,"stack":["0x4e6f7065","0x0"],"depth":1,"refund":0,"opName":"MSTORE"},
{"pc":8,"op":96,"gas":"0x2540be3f4","gasCost":"0x3","memSize":32,"stack":[],"depth":1,"refund":0,"opName":"PUSH1"}, {"pc":8,"op":96,"gas":"0x2540be3f4","gasCost":"0x3","memSize":32,"stack":[],"depth":1,"refund":0,"opName":"PUSH1"},
{"pc":10,"op":96,"gas":"0x2540be3f1","gasCost":"0x3","memSize":32,"stack":["0x4"],"depth":1,"refund":0,"opName":"PUSH1"}, {"pc":10,"op":96,"gas":"0x2540be3f1","gasCost":"0x3","memSize":32,"stack":["0x4"],"depth":1,"refund":0,"opName":"PUSH1"},
{"pc":12,"op":253,"gas":"0x2540be3ee","gasCost":"0x0","memSize":32,"stack":["0x4","0x1c"],"depth":1,"refund":0,"opName":"REVERT","error":"Nope"}, {"pc":12,"op":253,"gas":"0x2540be3ee","gasCost":"0x0","memSize":32,"stack":["0x4","0x1c"],"depth":1,"refund":0,"opName":"REVERT","error":"0x4e6f7065"},
{"stateRoot":"0x405bbd98da2aca6dff77f79e0b270270c48d6a3e07b76db675b20e454b50bbcb","output":"0x4e6f7065","gasUsed":"0x12","pass":true,"fork":"Cancun"} {"stateRoot":"0x405bbd98da2aca6dff77f79e0b270270c48d6a3e07b76db675b20e454b50bbcb","output":"0x4e6f7065","gasUsed":"0x12","pass":true,"fork":"Cancun"}
] ]
} }

@ -14,8 +14,6 @@
*/ */
package org.hyperledger.besu.evm.tracing; package org.hyperledger.besu.evm.tracing;
import static com.google.common.base.Strings.padStart;
import org.hyperledger.besu.evm.code.OpcodeInfo; import org.hyperledger.besu.evm.code.OpcodeInfo;
import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason;
import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.frame.MessageFrame;
@ -224,7 +222,7 @@ public class StandardJsonTracer implements OperationTracer {
.append("\""); .append("\"");
} else if (messageFrame.getRevertReason().isPresent()) { } else if (messageFrame.getRevertReason().isPresent()) {
sb.append(",\"error\":\"") sb.append(",\"error\":\"")
.append(quoteEscape(messageFrame.getRevertReason().orElse(Bytes.EMPTY))) .append(messageFrame.getRevertReason().get().toHexString())
.append("\""); .append("\"");
} }
@ -232,37 +230,6 @@ public class StandardJsonTracer implements OperationTracer {
out.println(sb); out.println(sb);
} }
private static String quoteEscape(final Bytes bytes) {
final StringBuilder result = new StringBuilder(bytes.size());
for (final byte b : bytes.toArrayUnsafe()) {
final int c = Byte.toUnsignedInt(b);
// list from RFC-4627 section 2
if (c == '"') {
result.append("\\\"");
} else if (c == '\\') {
result.append("\\\\");
} else if (c == '/') {
result.append("\\/");
} else if (c == '\b') {
result.append("\\b");
} else if (c == '\f') {
result.append("\\f");
} else if (c == '\n') {
result.append("\\n");
} else if (c == '\r') {
result.append("\\r");
} else if (c == '\t') {
result.append("\\t");
} else if (c <= 0x1F) {
result.append("\\u");
result.append(padStart(Integer.toHexString(c), 4, '0'));
} else {
result.append((char) b);
}
}
return result.toString();
}
@Override @Override
public void tracePrecompileCall( public void tracePrecompileCall(
final MessageFrame frame, final long gasRequirement, final Bytes output) { final MessageFrame frame, final long gasRequirement, final Bytes output) {

@ -32,7 +32,6 @@ import org.hyperledger.besu.evm.worldstate.WorldUpdater;
import java.io.PrintStream; import java.io.PrintStream;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.Deque; import java.util.Deque;
import java.util.List; import java.util.List;
@ -208,9 +207,7 @@ public class EvmToyCommand implements Runnable {
out.println(messageFrame.getExceptionalHaltReason().get()); out.println(messageFrame.getExceptionalHaltReason().get());
} }
if (messageFrame.getRevertReason().isPresent()) { if (messageFrame.getRevertReason().isPresent()) {
out.println( out.println(messageFrame.getRevertReason().get().toHexString());
new String(
messageFrame.getRevertReason().get().toArrayUnsafe(), StandardCharsets.UTF_8));
} }
} }
if (messageFrameStack.isEmpty()) { if (messageFrameStack.isEmpty()) {

Loading…
Cancel
Save