Skip to content

Commit ae05ed1

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

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

libevmasm/Assembly.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,24 +518,25 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
518518
static std::set<std::string> const validMembers{".code", ".data", ".auxdata", "sourceList"};
519519
for (std::string const& attribute: _json.getMemberNames())
520520
solRequire(validMembers.count(attribute), AssemblyImportException, "Unknown attribute '" + attribute + "'.");
521-
solRequire(_json.isMember(".code"), AssemblyImportException, "Member '.code' does not exist.");
521+
522+
solRequire(_json.isMember(".code"), AssemblyImportException, "Member '.code' is missing.");
522523
solRequire(_json[".code"].isArray(), AssemblyImportException, "Member '.code' is not an array.");
523524
for (Json::Value const& codeItem: _json[".code"])
524-
solRequire(codeItem.isObject(), AssemblyImportException, "Item of '.code' array is not an object.");
525+
solRequire(codeItem.isObject(), AssemblyImportException, "The '.code' array contains an item that is not an object.");
525526

526527
if (_level == 0)
527528
{
528529
if (_json.isMember("sourceList"))
529530
{
530531
solRequire(_json["sourceList"].isArray(), AssemblyImportException, "Optional member 'sourceList' is not an array.");
531532
for (Json::Value const& sourceListItem: _json["sourceList"])
532-
solRequire(sourceListItem.isString(), AssemblyImportException, "Item of 'sourceList' array is not of type string.");
533+
solRequire(sourceListItem.isString(), AssemblyImportException, "The 'sourceList' array contains an item that is not a string.");
533534
}
534535
} else
535536
solRequire(
536537
!_json.isMember("sourceList"),
537538
AssemblyImportException,
538-
"Member 'sourceList' is only allowed in root JSON object."
539+
"Member 'sourceList' may only be present in the root JSON object."
539540
);
540541

541542
std::vector<std::string> sourceList;
@@ -557,7 +558,7 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
557558
result->importAssemblyItemsFromJSON(_json[".code"], sourceList);
558559
if (_json[".auxdata"])
559560
{
560-
solRequire(_json[".auxdata"].isString(), AssemblyImportException, "Optional member '.auxdata' is not of type string.");
561+
solRequire(_json[".auxdata"].isString(), AssemblyImportException, "Optional member '.auxdata' is not a string.");
561562
bytes auxdata{fromHex(_json[".auxdata"].asString())};
562563
solRequire(!auxdata.empty(), AssemblyImportException, "Optional member '.auxdata' is not a valid hexadecimal string.");
563564
result->m_auxiliaryData = auxdata;
@@ -569,7 +570,7 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
569570
Json::Value const& data = _json[".data"];
570571
for (Json::ValueConstIterator dataIter = data.begin(); dataIter != data.end(); dataIter++)
571572
{
572-
solRequire(dataIter.key().isString(), AssemblyImportException, "Key inside '.data' is not of type string.");
573+
solRequire(dataIter.key().isString(), AssemblyImportException, "Key inside '.data' is not a string.");
573574
std::string dataItemID = dataIter.key().asString();
574575
Json::Value const& code = data[dataItemID];
575576
if (code.isString())
@@ -594,7 +595,7 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
594595
result->m_subs[index] = subassembly;
595596
}
596597
else
597-
solThrow(AssemblyImportException, "Key inside '.data' '" + dataItemID + "' can only be a valid hex-string or an object.");
598+
solThrow(AssemblyImportException, "The value of key '" + dataItemID + "' inside '.data' is neither a hex-string nor an object.");
598599
}
599600
}
600601
if (_level == 0)

0 commit comments

Comments
 (0)