[libevmasm] EVM Assembly import: Fix sub-assembly object import.

This commit is contained in:
Alexander Arlt 2023-05-16 19:55:41 -05:00
parent 72b4629118
commit b0d65f83ce
14 changed files with 819 additions and 14 deletions

View File

@ -578,17 +578,49 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
{
shared_ptr<Assembly> subassembly(Assembly::fromJSON(code, sourceList, _level + 1).first);
solAssert(subassembly);
result->m_subs.emplace_back(make_shared<Assembly>(*subassembly));
// TODO: this shouldn't be enough for the general case.
result->encodeSubPath({0, 0});
result->m_subs.emplace_back(subassembly);
}
else
solThrow(AssemblyImportException, "Key inside '.data' '" + dataItemID + "' can only be a valid hex-string or an object.");
}
}
if (_level == 0)
result->updatePaths();
return std::make_pair(result, sourceList);
}
void Assembly::updatePaths(std::vector<Assembly*> const& _parents, std::vector<size_t> const& _absolutePathFromRoot)
{
size_t subId = 0;
for (auto& assembly: this->m_subs)
{
std::vector<Assembly*> parents{_parents};
parents.push_back(this);
std::vector<size_t> absolutePathFromRoot{_absolutePathFromRoot};
absolutePathFromRoot.emplace_back(subId);
int pindex = 0;
for (auto& parent: parents)
{
if (pindex == 0)
parent->encodeSubPath(absolutePathFromRoot);
else
{
std::vector<size_t> relativePath{absolutePathFromRoot};
for (int i = 0; i < pindex; ++i)
relativePath.erase(relativePath.begin());
parent->encodeSubPath(relativePath);
}
++pindex;
}
assembly->updatePaths(parents, absolutePathFromRoot);
++subId;
}
}
AssemblyItem Assembly::namedTag(string const& _name, size_t _params, size_t _returns, optional<uint64_t> _sourceID)
{
assertThrow(!_name.empty(), AssemblyException, "Empty named tag.");

View File

@ -196,6 +196,8 @@ private:
Assembly const* subAssemblyById(size_t _subId) const;
void updatePaths(std::vector<Assembly *> const& _parents = {}, std::vector<size_t> const& _absolutePathFromRoot = {});
protected:
/// 0 is reserved for exception
unsigned m_usedTags = 1;

View File

@ -0,0 +1 @@
--strict-assembly - --asm-json --pretty-json

View File

@ -0,0 +1,365 @@
======= <stdin> (EVM) =======
{
".code":
[
{
"begin": 37,
"end": 51,
"name": "PUSHSIZE",
"source": 0
},
{
"begin": 34,
"end": 35,
"name": "PUSH",
"source": 0,
"value": "0"
},
{
"begin": 27,
"end": 52,
"name": "SSTORE",
"source": 0
},
{
"begin": 67,
"end": 81,
"name": "PUSH #[$]",
"source": 0,
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"begin": 64,
"end": 65,
"name": "PUSH",
"source": 0,
"value": "1"
},
{
"begin": 57,
"end": 82,
"name": "SSTORE",
"source": 0
},
{
"begin": 97,
"end": 114,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000ffffffffffffffff"
},
{
"begin": 94,
"end": 95,
"name": "PUSH",
"source": 0,
"value": "2"
},
{
"begin": 87,
"end": 115,
"name": "SSTORE",
"source": 0
},
{
"begin": 130,
"end": 152,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000fffffffffffffffe"
},
{
"begin": 127,
"end": 128,
"name": "PUSH",
"source": 0,
"value": "3"
},
{
"begin": 120,
"end": 153,
"name": "SSTORE",
"source": 0
},
{
"begin": 168,
"end": 190,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000fffffffffffffffd"
},
{
"begin": 165,
"end": 166,
"name": "PUSH",
"source": 0,
"value": "4"
},
{
"begin": 158,
"end": 191,
"name": "SSTORE",
"source": 0
},
{
"begin": 206,
"end": 228,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000fffffffffffffffc"
},
{
"begin": 203,
"end": 204,
"name": "PUSH",
"source": 0,
"value": "5"
},
{
"begin": 196,
"end": 229,
"name": "SSTORE",
"source": 0
}
],
".data":
{
"0":
{
".code":
[
{
"begin": 278,
"end": 292,
"name": "PUSHSIZE",
"source": 0
},
{
"begin": 275,
"end": 276,
"name": "PUSH",
"source": 0,
"value": "6"
},
{
"begin": 268,
"end": 293,
"name": "SSTORE",
"source": 0
},
{
"begin": 310,
"end": 324,
"name": "PUSH #[$]",
"source": 0,
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"begin": 307,
"end": 308,
"name": "PUSH",
"source": 0,
"value": "7"
},
{
"begin": 300,
"end": 325,
"name": "SSTORE",
"source": 0
},
{
"begin": 342,
"end": 361,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000ffffffffffffffff"
},
{
"begin": 339,
"end": 340,
"name": "PUSH",
"source": 0,
"value": "8"
},
{
"begin": 332,
"end": 362,
"name": "SSTORE",
"source": 0
},
{
"begin": 379,
"end": 398,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000fffffffffffffffe"
},
{
"begin": 376,
"end": 377,
"name": "PUSH",
"source": 0,
"value": "9"
},
{
"begin": 369,
"end": 399,
"name": "SSTORE",
"source": 0
},
{
"begin": 417,
"end": 436,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000fffffffffffffffd"
},
{
"begin": 413,
"end": 415,
"name": "PUSH",
"source": 0,
"value": "A"
},
{
"begin": 406,
"end": 437,
"name": "SSTORE",
"source": 0
}
],
".data":
{
"0":
{
".code":
[
{
"begin": 494,
"end": 508,
"name": "PUSHSIZE",
"source": 0
},
{
"begin": 490,
"end": 492,
"name": "PUSH",
"source": 0,
"value": "B"
},
{
"begin": 483,
"end": 509,
"name": "SSTORE",
"source": 0
},
{
"begin": 529,
"end": 545,
"name": "PUSH #[$]",
"source": 0,
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"begin": 525,
"end": 527,
"name": "PUSH",
"source": 0,
"value": "C"
},
{
"begin": 518,
"end": 546,
"name": "SSTORE",
"source": 0
},
{
"begin": 566,
"end": 582,
"name": "PUSH #[$]",
"source": 0,
"value": "0000000000000000000000000000000000000000000000000000000000000001"
},
{
"begin": 562,
"end": 564,
"name": "PUSH",
"source": 0,
"value": "D"
},
{
"begin": 555,
"end": 583,
"name": "SSTORE",
"source": 0
},
{
"begin": 603,
"end": 619,
"name": "PUSH #[$]",
"source": 0,
"value": "0000000000000000000000000000000000000000000000000000000000000002"
},
{
"begin": 599,
"end": 601,
"name": "PUSH",
"source": 0,
"value": "E"
},
{
"begin": 592,
"end": 620,
"name": "SSTORE",
"source": 0
}
],
".data":
{
"0":
{
".code":
[
{
"begin": 676,
"end": 685,
"name": "INVALID",
"source": 0
}
]
},
"1":
{
".code":
[
{
"begin": 751,
"end": 760,
"name": "INVALID",
"source": 0
}
]
},
"2":
{
".code":
[
{
"begin": 826,
"end": 835,
"name": "INVALID",
"source": 0
}
]
}
}
}
}
}
},
"sourceList":
[
"<stdin>"
]
}

View File

@ -0,0 +1,43 @@
object "L0" {
code {
sstore(0, datasize("L0"))
sstore(1, datasize("L1"))
sstore(2, datasize("L1.L2"))
sstore(3, datasize("L1.L2.L2_0"))
sstore(4, datasize("L1.L2.L2_1"))
sstore(5, datasize("L1.L2.L2_2"))
}
object "L1" {
code {
sstore(6, datasize("L1"))
sstore(7, datasize("L2"))
sstore(8, datasize("L2.L2_0"))
sstore(9, datasize("L2.L2_1"))
sstore(10, datasize("L2.L2_2"))
}
object "L2" {
code {
sstore(11, datasize("L2"))
sstore(12, datasize("L2_0"))
sstore(13, datasize("L2_1"))
sstore(14, datasize("L2_2"))
}
object "L2_0" {
code {
invalid()
}
}
object "L2_1" {
code {
invalid()
}
}
object "L2_2" {
code {
invalid()
}
}
}
}
}

View File

@ -37,9 +37,9 @@
"#utility.yul"
]
},
"bin": "6000fe",
"bin": "5ffe",
"bin-runtime": "6001",
"opcodes": "PUSH1 0x0 INVALID ",
"opcodes": "PUSH0 INVALID ",
"srcmap": "0:0::-:0",
"srcmap-runtime": "0:0::-:0"
}
@ -52,7 +52,7 @@
"version": "<VERSION REMOVED>"
}
Binary:
6000fe
5ffe
Binary of the runtime part:
6001
EVM assembly:

View File

@ -1,5 +1,5 @@
Opcodes:
PUSH1 0x0 CALLDATALOAD PUSH1 0x14 DUP1 DUP3 SSTORE PUSH1 0x20 CALLDATALOAD ISZERO PUSH1 0x20 JUMPI DUP1 DUP3 SSTORE PUSH1 0x0 DUP1 PUSH1 0x0 DUP1 PUSH1 0x0 DUP1 STATICCALL POP PUSH25 0x797A5B80825550500000000000000000000000000000000000
PUSH0 CALLDATALOAD PUSH1 0x14 DUP1 DUP3 SSTORE PUSH1 0x20 CALLDATALOAD ISZERO PUSH1 0x1C JUMPI DUP1 DUP3 SSTORE PUSH0 DUP1 PUSH0 DUP1 PUSH0 DUP1 STATICCALL POP PUSH25 0x797A5B80825550500000000000000000000000000000000000
EVM assembly:
/* "<stdin>":28:29 b */
0x00

View File

@ -0,0 +1 @@
--import-asm-json - --opcodes

View File

@ -0,0 +1,2 @@
Opcodes:
PUSH1 0x1E PUSH0 SSTORE PUSH1 0x1A PUSH1 0x1 SSTORE PUSH1 0x15 PUSH1 0x2 SSTORE PUSH1 0x1 PUSH1 0x3 SSTORE PUSH1 0x1 PUSH1 0x4 SSTORE PUSH1 0x1 PUSH1 0x5 SSTORE INVALID

View File

@ -0,0 +1,363 @@
{
".code":
[
{
"begin": 37,
"end": 51,
"name": "PUSHSIZE",
"source": 0
},
{
"begin": 34,
"end": 35,
"name": "PUSH",
"source": 0,
"value": "0"
},
{
"begin": 27,
"end": 52,
"name": "SSTORE",
"source": 0
},
{
"begin": 67,
"end": 81,
"name": "PUSH #[$]",
"source": 0,
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"begin": 64,
"end": 65,
"name": "PUSH",
"source": 0,
"value": "1"
},
{
"begin": 57,
"end": 82,
"name": "SSTORE",
"source": 0
},
{
"begin": 97,
"end": 114,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000ffffffffffffffff"
},
{
"begin": 94,
"end": 95,
"name": "PUSH",
"source": 0,
"value": "2"
},
{
"begin": 87,
"end": 115,
"name": "SSTORE",
"source": 0
},
{
"begin": 130,
"end": 152,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000fffffffffffffffe"
},
{
"begin": 127,
"end": 128,
"name": "PUSH",
"source": 0,
"value": "3"
},
{
"begin": 120,
"end": 153,
"name": "SSTORE",
"source": 0
},
{
"begin": 168,
"end": 190,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000fffffffffffffffd"
},
{
"begin": 165,
"end": 166,
"name": "PUSH",
"source": 0,
"value": "4"
},
{
"begin": 158,
"end": 191,
"name": "SSTORE",
"source": 0
},
{
"begin": 206,
"end": 228,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000fffffffffffffffc"
},
{
"begin": 203,
"end": 204,
"name": "PUSH",
"source": 0,
"value": "5"
},
{
"begin": 196,
"end": 229,
"name": "SSTORE",
"source": 0
}
],
".data":
{
"0":
{
".code":
[
{
"begin": 278,
"end": 292,
"name": "PUSHSIZE",
"source": 0
},
{
"begin": 275,
"end": 276,
"name": "PUSH",
"source": 0,
"value": "6"
},
{
"begin": 268,
"end": 293,
"name": "SSTORE",
"source": 0
},
{
"begin": 310,
"end": 324,
"name": "PUSH #[$]",
"source": 0,
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"begin": 307,
"end": 308,
"name": "PUSH",
"source": 0,
"value": "7"
},
{
"begin": 300,
"end": 325,
"name": "SSTORE",
"source": 0
},
{
"begin": 342,
"end": 361,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000ffffffffffffffff"
},
{
"begin": 339,
"end": 340,
"name": "PUSH",
"source": 0,
"value": "8"
},
{
"begin": 332,
"end": 362,
"name": "SSTORE",
"source": 0
},
{
"begin": 379,
"end": 398,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000fffffffffffffffe"
},
{
"begin": 376,
"end": 377,
"name": "PUSH",
"source": 0,
"value": "9"
},
{
"begin": 369,
"end": 399,
"name": "SSTORE",
"source": 0
},
{
"begin": 417,
"end": 436,
"name": "PUSH #[$]",
"source": 0,
"value": "000000000000000000000000000000000000000000000000fffffffffffffffd"
},
{
"begin": 413,
"end": 415,
"name": "PUSH",
"source": 0,
"value": "A"
},
{
"begin": 406,
"end": 437,
"name": "SSTORE",
"source": 0
}
],
".data":
{
"0":
{
".code":
[
{
"begin": 494,
"end": 508,
"name": "PUSHSIZE",
"source": 0
},
{
"begin": 490,
"end": 492,
"name": "PUSH",
"source": 0,
"value": "B"
},
{
"begin": 483,
"end": 509,
"name": "SSTORE",
"source": 0
},
{
"begin": 529,
"end": 545,
"name": "PUSH #[$]",
"source": 0,
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"begin": 525,
"end": 527,
"name": "PUSH",
"source": 0,
"value": "C"
},
{
"begin": 518,
"end": 546,
"name": "SSTORE",
"source": 0
},
{
"begin": 566,
"end": 582,
"name": "PUSH #[$]",
"source": 0,
"value": "0000000000000000000000000000000000000000000000000000000000000001"
},
{
"begin": 562,
"end": 564,
"name": "PUSH",
"source": 0,
"value": "D"
},
{
"begin": 555,
"end": 583,
"name": "SSTORE",
"source": 0
},
{
"begin": 603,
"end": 619,
"name": "PUSH #[$]",
"source": 0,
"value": "0000000000000000000000000000000000000000000000000000000000000002"
},
{
"begin": 599,
"end": 601,
"name": "PUSH",
"source": 0,
"value": "E"
},
{
"begin": 592,
"end": 620,
"name": "SSTORE",
"source": 0
}
],
".data":
{
"0":
{
".code":
[
{
"begin": 676,
"end": 685,
"name": "INVALID",
"source": 0
}
]
},
"1":
{
".code":
[
{
"begin": 751,
"end": 760,
"name": "INVALID",
"source": 0
}
]
},
"2":
{
".code":
[
{
"begin": 826,
"end": 835,
"name": "INVALID",
"source": 0
}
]
}
}
}
}
}
},
"sourceList":
[
"<stdin>"
]
}

View File

@ -1 +1 @@
--import-asm-json - --opcodes --asm
--import-asm-json - --opcodes

View File

@ -1,5 +0,0 @@
Uncaught exception:
/solidity/libevmasm/Assembly.cpp(1070): Throw in function vector<size_t> solidity::evmasm::Assembly::decodeSubPath(size_t) const
Dynamic exception type:
std::exception::what: Assertion failed
[solidity::util::tag_comment*] = Assertion failed

View File

@ -0,0 +1,2 @@
Opcodes:
PUSH0 DUP1 SSTORE PUSH1 0x6A PUSH1 0x1 SSTORE PUSH1 0x31 PUSH1 0x2 SSTORE PUSH1 0x2C PUSH1 0x3 SSTORE PUSH1 0x5E PUSH1 0x4 SSTORE PUSH1 0xC PUSH1 0x5 SSTORE PUSH1 0x5D PUSH1 0x6 SSTORE PUSH1 0x1 PUSH1 0x7 SSTORE PUSH1 0x5D PUSH1 0x8 SSTORE PUSH1 0x1 PUSH1 0x9 SSTORE INVALID PUSH1 0x1F PUSH1 0xA SSTORE PUSH1 0xC PUSH1 0xB SSTORE PUSH1 0x2B PUSH1 0xC SSTORE PUSH1 0x1 PUSH1 0xD SSTORE PUSH1 0x2B PUSH1 0xE SSTORE PUSH1 0x1 PUSH1 0xF SSTORE INVALID PUSH1 0xB PUSH1 0x10 SSTORE PUSH1 0x1 PUSH1 0x11 SSTORE INVALID INVALID INVALID INVALID PUSH1 0xB PUSH1 0x10 SSTORE PUSH1 0x1 PUSH1 0x11 SSTORE INVALID INVALID