Skip to content

Commit ef30e28

Browse files
committed
fixup! [libevmasm] Add support to import evm assembly json.
1 parent 5111cad commit ef30e28

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

libevmasm/Assembly.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,30 +536,28 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
536536
"Member 'sourceList' may only be present in the root JSON object."
537537
);
538538

539-
std::vector<std::string> sourceList;
539+
std::vector<std::string> parsedSourceList;
540540
if (_json.isMember("sourceList"))
541541
{
542542
solAssert(_level == 0);
543543
solAssert(_sourceList.empty());
544544
for (Json::Value const& sourceName: _json["sourceList"])
545545
{
546546
solRequire(
547-
std::find(sourceList.begin(), sourceList.end(), sourceName.asString()) == sourceList.end(),
547+
std::find(parsedSourceList.begin(), parsedSourceList.end(), sourceName.asString()) == parsedSourceList.end(),
548548
AssemblyImportException,
549549
"Items in 'sourceList' array are not unique."
550550
);
551-
sourceList.emplace_back(sourceName.asString());
551+
parsedSourceList.emplace_back(sourceName.asString());
552552
}
553553
}
554-
else
555-
sourceList = _sourceList;
556554

557555
solRequire(_json.isMember(".code"), AssemblyImportException, "Member '.code' is missing.");
558556
solRequire(_json[".code"].isArray(), AssemblyImportException, "Member '.code' is not an array.");
559557
for (Json::Value const& codeItem: _json[".code"])
560558
solRequire(codeItem.isObject(), AssemblyImportException, "The '.code' array contains an item that is not an object.");
561559

562-
result->importAssemblyItemsFromJSON(_json[".code"], sourceList);
560+
result->importAssemblyItemsFromJSON(_json[".code"], _level == 0 ? parsedSourceList : _sourceList);
563561

564562
if (_json[".auxdata"])
565563
{
@@ -608,8 +606,9 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
608606

609607
if (result->m_subs.size() <= index)
610608
result->m_subs.resize(index + 1);
611-
std::shared_ptr<Assembly> subassembly(Assembly::fromJSON(dataItem, sourceList, _level + 1).first);
609+
auto [subassembly, emptySourceList] = Assembly::fromJSON(dataItem, _level == 0 ? parsedSourceList : _sourceList, _level + 1);
612610
solAssert(subassembly);
611+
solAssert(emptySourceList.empty());
613612
result->m_subs[index] = subassembly;
614613
}
615614
else
@@ -618,7 +617,7 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
618617
}
619618
if (_level == 0)
620619
result->updatePaths();
621-
return std::make_pair(result, sourceList);
620+
return std::make_pair(result, _level == 0 ? parsedSourceList : std::vector<std::string>{});
622621
}
623622

624623
void Assembly::updatePaths(std::vector<Assembly*> const& _parents, std::vector<size_t> const& _absolutePathFromRoot)

libevmasm/Assembly.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class Assembly
161161
/// at level 0 and the value increases down the tree. Necessary to distinguish between creation
162162
/// and deployed objects.
163163
/// @returns Created @a Assembly and the source list read from the 'sourceList' field of the root
164-
/// assembly.
164+
/// assembly or an empty list (in recursive calls).
165165
static std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> fromJSON(
166166
Json::Value const& _json,
167167
std::vector<std::string> const& _sourceList = {},

0 commit comments

Comments
 (0)