Lock evmtool code-validate into runtime mode (#7397)

To conform to fuzzing practices, `code-validate` expects all code to be
runtime code.

Signed-off-by: Danno Ferrin <danno@numisight.com>
pull/7412/head
Danno Ferrin 4 months ago committed by GitHub
parent 6b1ae691e6
commit 9592b64310
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/CodeValidateSubCommand.java
  2. 5
      ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/EvmToolSpecTests.java
  3. 7
      ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/code-validate/initcode.json
  4. 7
      ethereum/evmtool/src/test/resources/org/hyperledger/besu/evmtool/code-validate/runtime.json

@ -23,7 +23,9 @@ import org.hyperledger.besu.evm.Code;
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.code.EOFLayout;
import org.hyperledger.besu.evm.code.EOFLayout.EOFContainerMode;
import org.hyperledger.besu.util.LogConfigurator;
import java.io.BufferedReader;
@ -45,7 +47,7 @@ import picocli.CommandLine.ParentCommand;
* fuzzing. It implements the Runnable interface and is annotated with the {@code
* CommandLine.Command} annotation.
*/
@SuppressWarnings({"ConstantValue", "DataFlowIssue"})
@SuppressWarnings({"ConstantValue"})
@CommandLine.Command(
name = COMMAND_NAME,
description = "Validates EVM code for fuzzing",
@ -154,6 +156,9 @@ public class CodeValidateSubCommand implements Runnable {
Code code = evm.getCodeUncached(codeBytes);
if (code instanceof CodeInvalid codeInvalid) {
return "err: " + codeInvalid.getInvalidReason();
} else if (EOFContainerMode.INITCODE.equals(
((CodeV1) code).getEofLayout().containerMode().get())) {
return "err: code is valid initcode. Runtime code expected";
} else {
return "OK "
+ IntStream.range(0, code.getCodeSectionCount())

@ -62,6 +62,10 @@ public class EvmToolSpecTests {
return findSpecFiles(new String[] {"b11r"});
}
public static Object[][] codeValidateTests() {
return findSpecFiles(new String[] {"code-validate"});
}
public static Object[][] prettyPrintTests() {
return findSpecFiles(new String[] {"pretty-print"});
}
@ -122,6 +126,7 @@ public class EvmToolSpecTests {
@MethodSource({
"blocktestTests",
"b11rTests",
"codeValidateTests",
"prettyPrintTests",
"stateTestTests",
"t8nTests",

@ -0,0 +1,7 @@
{
"cli": [
"code-validate"
],
"stdin": "ef000101000402000100060300010014040000000080000260006000ee00ef00010100040200010001040000000080000000",
"stdout": "err: code is valid initcode. Runtime code expected"
}

@ -0,0 +1,7 @@
{
"cli": [
"code-validate"
],
"stdin": "ef00010100040200010001040000000080000000",
"stdout": "OK 00\n"
}
Loading…
Cancel
Save