Skip to content

Commit 041d05c

Browse files
committed
fixup! [libevmasm] Add support to import evm assembly json.
1 parent fac98de commit 041d05c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

libevmasm/Assembly.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ AssemblyItem Assembly::createAssemblyItemFromJSON(Json::Value const& _json, std:
101101
solRequire(
102102
validMembers.count(member),
103103
AssemblyImportException,
104-
"Unknown member '" + member + "'. Valid members are " +
104+
"Unknown member '" + member + "'. Valid members are: " +
105105
solidity::util::joinHumanReadable(validMembers, ", ") + "."
106106
);
107107
solRequire(isOfType<std::string>(_json["name"]), AssemblyImportException, "Member 'name' missing or not of type string.");
@@ -121,7 +121,7 @@ AssemblyItem Assembly::createAssemblyItemFromJSON(Json::Value const& _json, std:
121121
);
122122

123123
std::string name = get<std::string>(_json["name"]);
124-
solRequire(!name.empty(), AssemblyImportException, "Member 'name' was empty.");
124+
solRequire(!name.empty(), AssemblyImportException, "Member 'name' is empty.");
125125

126126
SourceLocation location;
127127
location.start = get<int>(_json["begin"]);
@@ -158,7 +158,7 @@ AssemblyItem Assembly::createAssemblyItemFromJSON(Json::Value const& _json, std:
158158
solRequire(
159159
!_value.empty(),
160160
AssemblyImportException,
161-
"Member 'value' was not defined for instruction '" + _name + "', but the instruction needs a value."
161+
"Member 'value' not defined for instruction '" + _name + "', but the instruction needs a value."
162162
);
163163
};
164164

@@ -171,7 +171,7 @@ AssemblyItem Assembly::createAssemblyItemFromJSON(Json::Value const& _json, std:
171171
);
172172
};
173173

174-
solRequire(srcIndex >= -1 && srcIndex < static_cast<int>(_sourceList.size()), AssemblyImportException, "srcIndex out of bound.");
174+
solRequire(srcIndex >= -1 && srcIndex < static_cast<int>(_sourceList.size()), AssemblyImportException, "Source index out of bounds.");
175175
if (srcIndex != -1)
176176
{
177177
static std::map<std::string, std::shared_ptr<std::string const>> sharedSourceNames;
@@ -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)