Skip to content

Commit 4120fce

Browse files
cameelr0qs
authored andcommitted
fixup! [libevmasm] Add support to import evm assembly json.
1 parent 520098e commit 4120fce

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

libevmasm/Assembly.cpp

Lines changed: 13 additions & 12 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' is missing 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;
@@ -514,24 +514,25 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
514514
static std::set<std::string> const validMembers{".code", ".data", ".auxdata", "sourceList"};
515515
for (std::string const& attribute: _json.getMemberNames())
516516
solRequire(validMembers.count(attribute), AssemblyImportException, "Unknown attribute '" + attribute + "'.");
517-
solRequire(_json.isMember(".code"), AssemblyImportException, "Member '.code' does not exist.");
517+
518+
solRequire(_json.isMember(".code"), AssemblyImportException, "Member '.code' is missing.");
518519
solRequire(_json[".code"].isArray(), AssemblyImportException, "Member '.code' is not an array.");
519520
for (Json::Value const& codeItem: _json[".code"])
520-
solRequire(codeItem.isObject(), AssemblyImportException, "Item of '.code' array is not an object.");
521+
solRequire(codeItem.isObject(), AssemblyImportException, "The '.code' array contains an item that is not an object.");
521522

522523
if (_level == 0)
523524
{
524525
if (_json.isMember("sourceList"))
525526
{
526527
solRequire(_json["sourceList"].isArray(), AssemblyImportException, "Optional member 'sourceList' is not an array.");
527528
for (Json::Value const& sourceListItem: _json["sourceList"])
528-
solRequire(sourceListItem.isString(), AssemblyImportException, "Item of 'sourceList' array is not of type string.");
529+
solRequire(sourceListItem.isString(), AssemblyImportException, "The 'sourceList' array contains an item that is not a string.");
529530
}
530531
} else
531532
solRequire(
532533
!_json.isMember("sourceList"),
533534
AssemblyImportException,
534-
"Member 'sourceList' is only allowed in root JSON object."
535+
"Member 'sourceList' may only be present in the root JSON object."
535536
);
536537

537538
std::shared_ptr<Assembly> result = std::make_shared<Assembly>(langutil::EVMVersion(), _level == 0, "");
@@ -554,7 +555,7 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
554555
result->importAssemblyItemsFromJSON(_json[".code"], sourceList);
555556
if (_json[".auxdata"])
556557
{
557-
solRequire(_json[".auxdata"].isString(), AssemblyImportException, "Optional member '.auxdata' is not of type string.");
558+
solRequire(_json[".auxdata"].isString(), AssemblyImportException, "Optional member '.auxdata' is not a string.");
558559
bytes auxdata{fromHex(_json[".auxdata"].asString())};
559560
solRequire(!auxdata.empty(), AssemblyImportException, "Optional member '.auxdata' is not a valid hexadecimal string.");
560561
result->m_auxiliaryData = auxdata;
@@ -566,7 +567,7 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
566567
Json::Value const& data = _json[".data"];
567568
for (Json::ValueConstIterator dataIter = data.begin(); dataIter != data.end(); dataIter++)
568569
{
569-
solRequire(dataIter.key().isString(), AssemblyImportException, "Key inside '.data' is not of type string.");
570+
solRequire(dataIter.key().isString(), AssemblyImportException, "Key inside '.data' is not a string.");
570571
std::string dataItemID = dataIter.key().asString();
571572
Json::Value const& code = data[dataItemID];
572573
if (code.isString())
@@ -577,7 +578,7 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
577578
solRequire(
578579
!data_value.empty(),
579580
AssemblyImportException,
580-
"Member '.data' contains a value for '" + dataItemID + "' that is not a valid hexadecimal string.");
581+
"The value for key '" + dataItemID + "' inside '.data' is not a valid hexadecimal string.");
581582
}
582583
result->m_data[h256(fromHex(dataItemID))] = fromHex(code.asString());
583584
}
@@ -591,7 +592,7 @@ std::pair<std::shared_ptr<Assembly>, std::vector<std::string>> Assembly::fromJSO
591592
result->m_subs[index] = subassembly;
592593
}
593594
else
594-
solThrow(AssemblyImportException, "Key inside '.data' '" + dataItemID + "' can only be a valid hex-string or an object.");
595+
solThrow(AssemblyImportException, "The value of key '" + dataItemID + "' inside '.data' is neither a hex string nor an object.");
595596
}
596597
}
597598
if (_level == 0)

solc/CommandLineParser.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,10 +1468,9 @@ void CommandLineParser::parseCombinedJsonOption()
14681468
solThrow(
14691469
CommandLineValidationError,
14701470
fmt::format(
1471-
"Invalid option to --{}: {} for --{}",
1471+
"The --{} {} output is not available in EVM assembly import mode.",
14721472
g_strCombinedJson,
1473-
CombinedJsonRequests::componentName(invalidOption),
1474-
g_strImportEvmAssemblerJson
1473+
CombinedJsonRequests::componentName(invalidOption)
14751474
)
14761475
);
14771476
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Error: Assembly Import Error: Member '.data' contains a value for '0' that is not a valid hexadecimal string.
1+
Error: Assembly Import Error: The value for key '0' inside '.data' is not a valid hexadecimal string.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Error: Assembly Import Error: Key inside '.data' '0' can only be a valid hex-string or an object.
1+
Error: Assembly Import Error: The value of key '0' inside '.data' is neither a hex string nor an object.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Error: Assembly Import Error: Member 'value' was not defined for instruction 'PUSH', but the instruction needs a value.
1+
Error: Assembly Import Error: Member 'value' is missing for instruction 'PUSH', but the instruction needs a value.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Error: Assembly Import Error: Unknown member '_name'. Valid members are begin, end, jumpType, modifierDepth, name, source, value.
1+
Error: Assembly Import Error: Unknown member '_name'. Valid members are: begin, end, jumpType, modifierDepth, name, source, value.

0 commit comments

Comments
 (0)