Skip to content

Commit 80b96e0

Browse files
cameelr0qs
authored andcommitted
fixup! [libevmasm] Add support to import evm assembly json.
1 parent ed4f888 commit 80b96e0

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

libevmasm/Assembly.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -532,31 +532,29 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
532532
"Member 'sourceList' may only be present in the root JSON object."
533533
);
534534

535-
std::shared_ptr<Assembly> result = std::make_shared<Assembly>(langutil::EVMVersion(), _level == 0, "");
536-
std::vector<std::string> sourceList;
535+
auto result = std::make_shared<Assembly>(EVMVersion{}, _level == 0 /* _creation */, "" /* _name */);
536+
std::vector<std::string> parsedSourceList;
537537
if (_json.isMember("sourceList"))
538538
{
539539
solAssert(_level == 0);
540540
solAssert(_sourceList.empty());
541541
for (Json::Value const& sourceName: _json["sourceList"])
542542
{
543543
solRequire(
544-
std::find(sourceList.begin(), sourceList.end(), sourceName.asString()) == sourceList.end(),
544+
std::find(parsedSourceList.begin(), parsedSourceList.end(), sourceName.asString()) == parsedSourceList.end(),
545545
AssemblyImportException,
546546
"Items in 'sourceList' array are not unique."
547547
);
548-
sourceList.emplace_back(sourceName.asString());
548+
parsedSourceList.emplace_back(sourceName.asString());
549549
}
550550
}
551-
else
552-
sourceList = _sourceList;
553551

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

559-
result->importAssemblyItemsFromJSON(_json[".code"], sourceList);
557+
result->importAssemblyItemsFromJSON(_json[".code"], _level == 0 ? parsedSourceList : _sourceList);
560558

561559
if (_json[".auxdata"])
562560
{
@@ -605,8 +603,9 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
605603

606604
if (result->m_subs.size() <= index)
607605
result->m_subs.resize(index + 1);
608-
std::shared_ptr<Assembly> subassembly(Assembly::fromJSON(dataItem, sourceList, _level + 1).first);
606+
auto [subassembly, emptySourceList] = Assembly::fromJSON(dataItem, _level == 0 ? parsedSourceList : _sourceList, _level + 1);
609607
solAssert(subassembly);
608+
solAssert(emptySourceList.empty());
610609
result->m_subs[index] = subassembly;
611610
}
612611
else
@@ -615,7 +614,7 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
615614
}
616615
if (_level == 0)
617616
result->updatePaths();
618-
return std::make_pair(result, sourceList);
617+
return std::make_pair(result, _level == 0 ? parsedSourceList : std::vector<std::string>{});
619618
}
620619

621620
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)