Skip to content

Commit b9ba67f

Browse files
committed
fixup! [libevmasm] Add support to import evm assembly json.
1 parent bc1df51 commit b9ba67f

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
@@ -539,30 +539,28 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
539539
"Member 'sourceList' may only be present in the root JSON object."
540540
);
541541

542-
std::vector<std::string> sourceList;
542+
std::vector<std::string> parsedSourceList;
543543
if (_json.isMember("sourceList"))
544544
{
545545
solAssert(_level == 0);
546546
solAssert(_sourceList.empty());
547547
for (Json::Value const& sourceName: _json["sourceList"])
548548
{
549549
solRequire(
550-
std::find(sourceList.begin(), sourceList.end(), sourceName.asString()) == sourceList.end(),
550+
std::find(parsedSourceList.begin(), parsedSourceList.end(), sourceName.asString()) == parsedSourceList.end(),
551551
AssemblyImportException,
552552
"Items in 'sourceList' array are not unique."
553553
);
554-
sourceList.emplace_back(sourceName.asString());
554+
parsedSourceList.emplace_back(sourceName.asString());
555555
}
556556
}
557-
else
558-
sourceList = _sourceList;
559557

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

565-
result->importAssemblyItemsFromJSON(_json[".code"], sourceList);
563+
result->importAssemblyItemsFromJSON(_json[".code"], _level == 0 ? parsedSourceList : _sourceList);
566564

567565
if (_json[".auxdata"])
568566
{
@@ -611,8 +609,9 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
611609

612610
if (result->m_subs.size() <= index)
613611
result->m_subs.resize(index + 1);
614-
std::shared_ptr<Assembly> subassembly(Assembly::fromJSON(dataItem, sourceList, _level + 1).first);
612+
auto [subassembly, emptySourceList] = Assembly::fromJSON(dataItem, _level == 0 ? parsedSourceList : _sourceList, _level + 1);
615613
solAssert(subassembly);
614+
solAssert(emptySourceList.empty());
616615
result->m_subs[index] = subassembly;
617616
}
618617
else
@@ -621,7 +620,7 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
621620
}
622621
if (_level == 0)
623622
result->updatePaths();
624-
return std::make_pair(result, sourceList);
623+
return std::make_pair(result, _level == 0 ? parsedSourceList : std::vector<std::string>{});
625624
}
626625

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