[libevmasm] Add support to import evm assembly json.

This commit is contained in:
Alexander Arlt
2023-05-16 19:57:31 -05:00
parent aa9e25021d
commit fd137e2929
59 changed files with 1110 additions and 61 deletions
+12
View File
@@ -671,6 +671,18 @@ SOLTMPDIR=$(mktemp -d)
)
rm -r "$SOLTMPDIR"
printTask "Testing EVM Assembly JSON import/export..."
SOLTMPDIR=$(mktemp -d)
(
cd "$SOLTMPDIR"
if ! "$REPO_ROOT/scripts/ASTImportTest.sh" evm-assembly
then
rm -r "$SOLTMPDIR"
fail
fi
)
rm -r "$SOLTMPDIR"
printTask "Testing AST import/export..."
SOLTMPDIR=$(mktemp -d)
(
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
--pretty-json --json-indent 4 --combined-json bin,bin-runtime,opcodes,asm,srcmap,srcmap-runtime --asm --bin --bin-runtime --asm-json --import-asm-json -
@@ -0,0 +1,91 @@
{
"contracts":
{
"<stdin>":
{
"asm":
{
".code":
[
{
"begin": 0,
"end": 0,
"name": "PUSH",
"source": -1,
"value": "0"
}
],
".data":
{
"0":
{
".code":
[
{
"begin": 0,
"end": 0,
"name": "PUSH",
"source": -1,
"value": "1"
}
]
}
},
"sourceList":
[
"contract.sol",
"#utility.yul"
]
},
"bin": "6000fe",
"bin-runtime": "6001",
"opcodes": "PUSH1 0x0 INVALID ",
"srcmap": "0:0::-:0",
"srcmap-runtime": "0:0::-:0"
}
},
"sourceList":
[
"contract.sol",
"#utility.yul"
],
"version": "<VERSION REMOVED>"
}
Binary:
6000fe
Binary of the runtime part:
6001
EVM assembly:
{
".code":
[
{
"begin": 0,
"end": 0,
"name": "PUSH",
"source": -1,
"value": "0"
}
],
".data":
{
"0":
{
".code":
[
{
"begin": 0,
"end": 0,
"name": "PUSH",
"source": -1,
"value": "1"
}
]
}
},
"sourceList":
[
"contract.sol",
"#utility.yul"
]
}
@@ -0,0 +1,22 @@
{
".code": [
{
"name": "PUSH",
"value": "0"
}
],
".data": {
"0": {
".code": [
{
"name": "PUSH",
"value": "1"
}
]
}
},
"sourceList": [
"contract.sol",
"#utility.yul"
]
}
@@ -0,0 +1 @@
--import-asm-json - --opcodes --asm
@@ -0,0 +1,6 @@
Opcodes:
PREVRANDAO PREVRANDAO
EVM assembly:
/* */
prevrandao
prevrandao
@@ -0,0 +1,6 @@
{
".code": [
{ "name": "DIFFICULTY" },
{ "name": "PREVRANDAO" }
]
}
@@ -0,0 +1 @@
--import-asm-json - --opcodes --asm
@@ -0,0 +1 @@
Assembly Import Error: Member '.data' contains a value for '0' that is not a valid hexadecimal string.
@@ -0,0 +1 @@
1
@@ -0,0 +1,11 @@
{
".code": [
{
"name": "PUSH",
"value": "0"
}
],
".data": {
"0": "no-hex-string"
}
}
@@ -0,0 +1 @@
--import-asm-json - --opcodes --asm
@@ -0,0 +1 @@
Assembly Import Error: Key inside '.data' '0' can only be a valid hex-string or an object.
@@ -0,0 +1 @@
1
@@ -0,0 +1,16 @@
{
".code": [
{
"name": "PUSH",
"value": "0"
}
],
".data": {
"0": [
0,
1,
2,
3
]
}
}
@@ -0,0 +1 @@
--import-asm-json - --opcodes --asm
@@ -0,0 +1 @@
Assembly Import Error: Member 'jumpType' set on instruction different from JUMP or JUMPI (was set on instruction 'PUSH')
@@ -0,0 +1,9 @@
{
".code": [
{
"name": "PUSH",
"value": "0",
"jumpType": "[in]"
}
]
}
@@ -0,0 +1 @@
--import-asm-json - --opcodes --asm
@@ -0,0 +1 @@
Assembly Import Error: Member 'value' defined for instruction 'DIFFICULTY', but the instruction does not need a value.
@@ -0,0 +1 @@
1
@@ -0,0 +1,8 @@
{
".code": [
{
"name": "DIFFICULTY",
"value": "0"
}
]
}
@@ -0,0 +1 @@
--optimize --import-asm-json - --opcodes --asm
@@ -0,0 +1 @@
Option --optimize is not supported with --import-asm-json.
@@ -0,0 +1 @@
1
@@ -0,0 +1,6 @@
{
".code": [
{ "name": "DIFFICULTY" },
{ "name": "PREVRANDAO" }
]
}
@@ -0,0 +1 @@
--import-asm-json - --opcodes --asm
@@ -0,0 +1 @@
Assembly Import Error: Member 'value' was not defined for instruction 'PUSH', but the instruction needs a value.
@@ -0,0 +1 @@
1
@@ -0,0 +1,5 @@
{
".code": [
{ "name": "PUSH" }
]
}
@@ -0,0 +1 @@
--import-asm-json - --opcodes --asm
@@ -0,0 +1 @@
Assembly Import Error: Unknown member '_name'. Valid members are begin, end, jumpType, modifierDepth, name, source, value.
@@ -0,0 +1 @@
1
@@ -0,0 +1,5 @@
{
".code": [
{ "_name": "DIFFICULTY" }
]
}
@@ -0,0 +1 @@
--import-asm-json - --opcodes --asm
@@ -0,0 +1 @@
Assembly Import Error: JUMPDEST instruction found that was not followed by tag.
@@ -0,0 +1 @@
1
@@ -0,0 +1,10 @@
{
".code": [
{
"name": "tag",
"value": "0x00"
},
{ "name": "JUMPDEST" },
{ "name": "JUMPDEST" }
]
}
@@ -1 +1 @@
The following outputs are not supported in assembler mode: --abi, --asm-json, --bin-runtime, --devdoc, --hashes, --ir, --metadata, --opcodes, --storage-layout, --userdoc.
The following outputs are not supported in assembler mode: --abi, --bin-runtime, --devdoc, --hashes, --ir, --metadata, --opcodes, --storage-layout, --userdoc.
+4 -11
View File
@@ -55,13 +55,9 @@ BOOST_AUTO_TEST_SUITE(Assembler)
BOOST_AUTO_TEST_CASE(all_assembly_items)
{
map<string, unsigned> indices = {
{ "root.asm", 0 },
{ "sub.asm", 1 },
{ "verbatim.asm", 2 }
};
EVMVersion evmVersion = solidity::test::CommonOptions::get().evmVersion();
Assembly _assembly{evmVersion, false, {}};
_assembly.setSourceList({"root.asm", "sub.asm", "verbatim.asm"});
auto root_asm = make_shared<string>("root.asm");
_assembly.setSourceLocation({1, 3, root_asm});
@@ -212,7 +208,7 @@ BOOST_AUTO_TEST_CASE(all_assembly_items)
};
Json::Value jsonValue;
BOOST_CHECK(util::jsonParseStrict(json, jsonValue));
BOOST_CHECK_EQUAL(util::jsonCompactPrint(_assembly.assemblyJSON(indices)), util::jsonCompactPrint(jsonValue));
BOOST_CHECK_EQUAL(util::jsonCompactPrint(_assembly.assemblyJSON()), util::jsonCompactPrint(jsonValue));
}
BOOST_AUTO_TEST_CASE(immutables_and_its_source_maps)
@@ -301,12 +297,9 @@ BOOST_AUTO_TEST_CASE(immutables_and_its_source_maps)
BOOST_AUTO_TEST_CASE(immutable)
{
map<string, unsigned> indices = {
{ "root.asm", 0 },
{ "sub.asm", 1 }
};
EVMVersion evmVersion = solidity::test::CommonOptions::get().evmVersion();
Assembly _assembly{evmVersion, true, {}};
_assembly.setSourceList({"root.asm", "sub.asm"});
auto root_asm = make_shared<string>("root.asm");
_assembly.setSourceLocation({1, 3, root_asm});
@@ -383,7 +376,7 @@ BOOST_AUTO_TEST_CASE(immutable)
"}\n"
);
BOOST_CHECK_EQUAL(
util::jsonCompactPrint(_assembly.assemblyJSON(indices)),
util::jsonCompactPrint(_assembly.assemblyJSON()),
"{\".code\":["
"{\"begin\":1,\"end\":3,\"name\":\"PUSH\",\"source\":0,\"value\":\"2A\"},"
"{\"begin\":1,\"end\":3,\"name\":\"PUSH\",\"source\":0,\"value\":\"0\"},"
+3 -2
View File
@@ -148,7 +148,7 @@ BOOST_AUTO_TEST_CASE(version)
BOOST_AUTO_TEST_CASE(multiple_input_modes)
{
array<string, 9> inputModeOptions = {
array<string, 10> inputModeOptions = {
"--help",
"--license",
"--version",
@@ -158,10 +158,11 @@ BOOST_AUTO_TEST_CASE(multiple_input_modes)
"--strict-assembly",
"--yul",
"--import-ast",
"--import-asm-json",
};
string expectedMessage =
"The following options are mutually exclusive: "
"--help, --license, --version, --standard-json, --link, --assemble, --strict-assembly, --yul, --import-ast, --lsp. "
"--help, --license, --version, --standard-json, --link, --assemble, --strict-assembly, --yul, --import-ast, --lsp, --import-asm-json. "
"Select at most one.";
for (string const& mode1: inputModeOptions)