From 59d10c278dbbe4511bf669b42c2c51526d266189 Mon Sep 17 00:00:00 2001 From: "Danno Ferrin (shemnon)" Date: Tue, 6 Aug 2024 09:42:09 -0600 Subject: [PATCH 1/2] EVMTool Docker Support A few fixes that re-enable docker support for evm tool * evmtool is the entrypoint * turn off some noisy logging * ensure EOF respects the create flag Signed-off-by: Danno Ferrin (shemnon) --- ethereum/evmtool/src/main/docker/Dockerfile | 2 +- .../src/main/java/org/hyperledger/besu/evmtool/EvmTool.java | 2 +- .../main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ethereum/evmtool/src/main/docker/Dockerfile b/ethereum/evmtool/src/main/docker/Dockerfile index 9d7b48d3cb1..b16407be293 100644 --- a/ethereum/evmtool/src/main/docker/Dockerfile +++ b/ethereum/evmtool/src/main/docker/Dockerfile @@ -24,7 +24,7 @@ WORKDIR /opt/besu-evmtool COPY --chown=besu:besu besu-evmtool /opt/besu-evmtool/ ENV PATH="/opt/besu-evmtool/bin:${PATH}" -ENTRYPOINT ["evm"] +ENTRYPOINT ["evmtool"] # Build-time metadata as defined at http://label-schema.org ARG BUILD_DATE diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmTool.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmTool.java index dec0555640c..12632070281 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmTool.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmTool.java @@ -28,7 +28,7 @@ public EvmTool() {} * @param args The command line arguments. */ public static void main(final String... args) { - LogConfigurator.setLevel("", "DEBUG"); + LogConfigurator.setLevel("", "OFF"); final EvmToolCommand evmToolCommand = new EvmToolCommand(); evmToolCommand.execute(args); diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java index 898f1dd4b6a..d5132e7bf1f 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java @@ -418,7 +418,7 @@ public void run() { if (codeBytes.isEmpty() && !createTransaction) { codeBytes = component.getWorldState().get(receiver).getCode(); } - Code code = evm.getCodeForCreation(codeBytes); + Code code = createTransaction ? evm.getCodeForCreation(codeBytes) : evm.getCodeUncached(codeBytes); if (!code.isValid()) { out.println(((CodeInvalid) code).getInvalidReason()); return; From c90b0ac51f4efa2c96e8960192220376950435f8 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Tue, 6 Aug 2024 10:40:55 -0600 Subject: [PATCH 2/2] spotless, better tests, and changelog Signed-off-by: Danno Ferrin --- CHANGELOG.md | 1 + .../besu/evmtool/EvmToolCommand.java | 14 +++++++++++++- .../besu/evmtool/trace/create-eof-error.json | 15 +++++++++++++++ .../org/hyperledger/besu/evmtool/trace/eof.json | 17 +++++++++++++++++ .../besu/evmtool/trace/initcode-error.json | 14 ++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/create-eof-error.json create mode 100644 ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/eof.json create mode 100644 ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/initcode-error.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 0db9e9df3f5..bae9c5b77c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - In process RPC service [#7395](https://github.com/hyperledger/besu/pull/7395) ### Bug fixes +- Correct entrypoint in Docker evmtool [#7430](https://github.com/hyperledger/besu/pull/7430) ## 24.7.1 diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java index d5132e7bf1f..989c6e0b7fe 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java @@ -15,6 +15,7 @@ package org.hyperledger.besu.evmtool; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.hyperledger.besu.evm.code.EOFLayout.EOFContainerMode.INITCODE; import static picocli.CommandLine.ScopeType.INHERIT; import org.hyperledger.besu.cli.config.NetworkName; @@ -34,6 +35,7 @@ import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.EvmSpecVersion; import org.hyperledger.besu.evm.code.CodeInvalid; +import org.hyperledger.besu.evm.code.CodeV1; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.evm.tracing.OperationTracer; @@ -418,11 +420,21 @@ public void run() { if (codeBytes.isEmpty() && !createTransaction) { codeBytes = component.getWorldState().get(receiver).getCode(); } - Code code = createTransaction ? evm.getCodeForCreation(codeBytes) : evm.getCodeUncached(codeBytes); + Code code = + createTransaction ? evm.getCodeForCreation(codeBytes) : evm.getCodeUncached(codeBytes); if (!code.isValid()) { out.println(((CodeInvalid) code).getInvalidReason()); return; + } else if (code.getEofVersion() == 1 + && createTransaction + != INITCODE.equals(((CodeV1) code).getEofLayout().containerMode().get())) { + out.println( + createTransaction + ? "--create requires EOF in INITCODE mode" + : "To evaluate INITCODE mode EOF code use the --create flag"); + return; } + final Stopwatch stopwatch = Stopwatch.createUnstarted(); long lastTime = 0; do { diff --git a/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/create-eof-error.json b/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/create-eof-error.json new file mode 100644 index 00000000000..58402eeaa48 --- /dev/null +++ b/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/create-eof-error.json @@ -0,0 +1,15 @@ +{ + "cli": [ + "--notime", + "--json", + "--create", + "--code", + "ef00010100040200010001040000000080000000c0de471fe5", + "--coinbase", + "4444588443C3A91288C5002483449ABA1054192B", + "--fork", + "CancunEOF" + ], + "stdin": "", + "stdout": "EOF Code Invalid : STOP is only a valid opcode in containers used for runtime operations.\n" +} \ No newline at end of file diff --git a/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/eof.json b/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/eof.json new file mode 100644 index 00000000000..ff9bf415e60 --- /dev/null +++ b/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/eof.json @@ -0,0 +1,17 @@ +{ + "cli": [ + "--notime", + "--json", + "--code", + "ef00010100040200010001040000000080000000", + "--coinbase", + "4444588443C3A91288C5002483449ABA1054192B", + "--fork", + "CancunEOF" + ], + "stdin": "", + "stdout": [ + {"pc":0,"section":0,"op":0,"gas":"0x2540be400","gasCost":"0x0","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"STOP"}, + {"gasUser":"0x0","gasTotal":"0x0","output":"0x"} + ] +} \ No newline at end of file diff --git a/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/initcode-error.json b/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/initcode-error.json new file mode 100644 index 00000000000..b88134778ec --- /dev/null +++ b/ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/trace/initcode-error.json @@ -0,0 +1,14 @@ +{ + "cli": [ + "--notime", + "--json", + "--code", + "ef00010100040200010009030001001404000000008000035f355f5fa15f5fee00ef00010100040200010001040000000080000000", + "--coinbase", + "4444588443C3A91288C5002483449ABA1054192B", + "--fork", + "CancunEOF" + ], + "stdin": "", + "stdout": "To evaluate INITCODE mode EOF code use the --create flag\n" +} \ No newline at end of file