-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Add support for importing asm-json. #11807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This comment has been minimized.
This comment has been minimized.
solc/CommandLineParser.cpp
Outdated
("Import assembly to be used, assumes input holds assembly in JSON format. " | ||
"Supported Input is the output of the --" + g_strAsmJson + ".").c_str() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be clarified a bit more, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, what should be clarified a bit more?
Ok, finally I found out what created the mismatching bytecode. I added the auxiliary data to the wrong assembly object. |
If exporting and importing anything really works and produces identical bytecode everywhere, it would probably be nice to add a test run similar to the AST import tests, that just compiles all sources in the repo once directly to bytecode and once via exporting assembly and then importing it back first, comparing the resulting bytecode :-). |
65c86cc
to
d120ae4
Compare
After checking what assembly items where exactly imported by
TODO: Add specific tests for these assembly items. |
413ff83
to
f89d6b8
Compare
Added json re-import - and byte code equivalence test to
|
f89d6b8
to
7238056
Compare
libevmasm/Assembly.cpp
Outdated
|
||
auto updateLibraries = [&](string const& value) -> h256 { | ||
h256 hash(util::keccak256(value)); | ||
_assembly.m_libraries[hash] = value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to check that it's a valid address (length, chars, maybe checksum?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not using any addresses here. value
is just a name of a library (I will change the parameter name). The hash is just used as a placeholder, where linking will replace the placeholder with the actual library address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess linking will do some checks on the supplied addresses, but I haven't checked this yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right, these are the placeholders.
Still, the placeholders need to have a specific length, start and end with __
, etc. Linking is done in LinkerObject.cpp
and it does not seem to have any validations (or even assertions) against that. AFAIK all the validation is in the CLI and StandardCompiler
.
BTW, some other parts of this JSON structure might need some validation too.
libevmasm/Assembly.cpp
Outdated
@@ -227,6 +229,221 @@ string Assembly::toStringInHex(u256 _value) | |||
return hexStr.str(); | |||
} | |||
|
|||
AssemblyItem Assembly::assemblyItemFromJSON(Json::Value const& _json, Assembly& _assembly) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At first I thought this just returns a new item but then I noticed that the function actually modifies _assembly
. I think the name should reflect that.
Actually, maybe a better design would be to have two functions - one that just gives you a list of items (and does not modify the assembly) and another one that takes the list and updates the assembly based on it? If you had to explicitly run the update function, it would be clearer that an update is taking place.
libevmasm/Assembly.cpp
Outdated
root[".auxdata"] = toHex(m_auxiliaryData); | ||
|
||
return root; | ||
} | ||
|
||
void Assembly::forEachJSONAssemblyItem(Json::Value const& _code, Assembly& _assembly) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the change I suggested above this function would get a list of assembly items. You would not have to call assemblyItemFromJSON()
twice for each item (which is especially bad given that assemblyItemFromJSON
has side-effects - it modifies the assembly).
solc/CommandLineInterface.cpp
Outdated
!m_compiler->compilationSuccessful() && | ||
m_options.output.stopAfter == CompilerStack::State::CompilationSuccessful | ||
) | ||
if (m_assembly) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can m_assembly
and m_compiler
both be present at the same time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, only m_assembly
or m_compiler
is possible at the same time. Change this to else if
.
solc/CommandLineParser.cpp
Outdated
@@ -1187,7 +1195,7 @@ General Information)").c_str(), | |||
if (m_options.input.mode == InputMode::Compiler) | |||
m_options.input.errorRecovery = (m_args.count(g_strErrorRecovery) > 0); | |||
|
|||
solAssert(m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, ""); | |||
solAssert(m_options.input.mode == InputMode::AssemblyJson || m_options.input.mode == InputMode::Compiler || m_options.input.mode == InputMode::CompilerWithASTImport, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this new input mode support all of the arguments that the compiler does? If not, I think it should make the function return at a much earlier point.
Also, which other command-line flags are usable in this mode? There's an issue underway to report errors for flags invalid in other modes (#11629) and I think we should start rejecting invalid flags in this new mode from the very beginning.
Each input mode has a test in test/solc/CommandLineParser.cpp
that checks all the options valid in that mode. This new mode should have such a test too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a very simple check in solc/CommandLineParser.cpp
. Basically with the new import mode only --asm
, --bin
and --opcodes
are right now supported.
solc/CommandLineParser.h
Outdated
@@ -49,6 +49,7 @@ enum class InputMode | |||
StandardJson, | |||
Linker, | |||
Assembler, | |||
AssemblyJson, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assembly is a bit ambiguous. On the CLI it usually refers to Yul. Maybe we should call it EVMAssemblyJson
instead? Or rename Assembler
mode to Yul
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about ImportAssemblyJson
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem I see is just that it might not be clear that Assembly
refers to EVM assembly rather than Yul here. On the other hand the class is named Assembly
, so maybe it's not such a big problem...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just changed that now to ImportEVMAssemblyJson
.
9a65e7e
to
c30f027
Compare
acdbc32
to
2e4ddd9
Compare
3c3eb0e
to
5c3a618
Compare
73a7a6e
to
9721c82
Compare
Replaced by #12704. |
Closes #11787.
--import-asm-json
.--opcodes
,--asm
and--bin
and--bin-runtime
, if--import-asm-json
is used.PUSH tag
PUSH [ErrorTag]
PUSHLIB
PUSHDEPLOYADDRESS
PUSHIMMUTABLE
VERBATIM
combinedJson
for--import-asm-json
srcmap
,srcmap-runtime
combinedJson
parametersAsmJsonImportTest.sh
: also compare optimiser outputNote:
PUSH tag
got removed, see Remove unused AssemblyItemType::PushString. #11948