Skip to content

Commit

Permalink
Lock evmtool code-validate into runtime mode (hyperledger#7397)
Browse files Browse the repository at this point in the history
To conform to fuzzing practices, `code-validate` expects all code to be
runtime code.

Signed-off-by: Danno Ferrin <danno@numisight.com>
  • Loading branch information
shemnon authored Jul 30, 2024
1 parent 6b1ae69 commit 9592b64
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
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;
Expand All @@ -45,7 +47,7 @@
* 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",
Expand Down Expand Up @@ -154,6 +156,9 @@ public String considerCode(final String hexCode) {
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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public static Object[][] b11rTests() {
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"});
}
Expand Down Expand Up @@ -122,6 +126,7 @@ private static Object[] pathToParams(final String subDir, final File file) {
@MethodSource({
"blocktestTests",
"b11rTests",
"codeValidateTests",
"prettyPrintTests",
"stateTestTests",
"t8nTests",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"cli": [
"code-validate"
],
"stdin": "ef000101000402000100060300010014040000000080000260006000ee00ef00010100040200010001040000000080000000",
"stdout": "err: code is valid initcode. Runtime code expected"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"cli": [
"code-validate"
],
"stdin": "ef00010100040200010001040000000080000000",
"stdout": "OK 00\n"
}

0 comments on commit 9592b64

Please sign in to comment.