-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Memory-safety annotation for inline assembly. #12620
Conversation
62de5d3
to
4539718
Compare
Can you also define what exactly memory safety means? |
Sure, this needs extensive documentation before I undraft it :-). |
Eventually we should also add better reports for all of this... But that's a bit of a hassle, since codegen so far is not meant to report stuff like that and we may need to store the source locations somewhere, etc., so I'd keep that separate for now... |
bfd815c
to
a3e16d7
Compare
test/libsolidity/ASTJSON/assembly/inline_assembly_memory_safe_parseOnly.json
Outdated
Show resolved
Hide resolved
d177ebf
to
e9c8803
Compare
{ | ||
if (!_assembly.documentation()) | ||
return true; | ||
StructuredDocumentation documentation{-1, _assembly.location(), _assembly.documentation()}; |
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 -1
node id is a bit creepy...
77e0d2f
to
2f37409
Compare
I just added a first rough draft for documenting this. I'm wondering how restrictive we should define this - technically it's valid for stack-to-memory to access any memory that is known to be past the initial value of the free memory pointer... |
2f37409
to
3d19b07
Compare
Test failures are just pending #12624 I think |
#12624 is ready. |
3d19b07
to
d38f89a
Compare
docs/assembly.rst
Outdated
All accessed memory (read or written) was properly allocated. This can either be memory allocated by yourself | ||
using a mechanism like the ``allocate`` function described above, or memory allocated by Solidity, | ||
e.g. memory within the bounds of a memory array you reference. The only exception to this is the scratch space | ||
between memory offset 0 and 64 mentioned above. |
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.
For this we still need to discuss what our actual requirements should really be, so I expect this to still change - for the rest of the docs, a review would be good already, though :-).
@@ -3,6 +3,7 @@ | |||
Language Features: | |||
* General: Support ``ContractName.functionName`` for ``abi.encodeCall``, in addition to external function pointers. | |||
* General: Add equality-comparison operators for external function types. | |||
* General: Allow annotating inline assembly as memory-safe to allow optimizations and stack limit evasion that rely on respecting Solidity's memory model. |
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 only applies to "via ir", does it?
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.
In practice at least... in principle, we could use the information for old codegen as well, but we probably won't.
docs/assembly.rst
Outdated
While we recommend to always respect Solidity's memory model, it is possible to use memory | ||
in an incompatible way from inline assembly. Therefore, moving stack variables to memory and additional |
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.
While we recommend to always respect Solidity's memory model, it is possible to use memory | |
in an incompatible way from inline assembly. Therefore, moving stack variables to memory and additional | |
While we recommend to always respect Solidity's memory model, inline assembly allows you to use memory | |
in an incompatible way. Therefore, moving stack variables to memory and additional |
d4542f4
to
5a41d45
Compare
7de3b3c
to
38a8612
Compare
|
||
set<string> valuesSeen; | ||
set<string> duplicates; | ||
for (auto const& value: values | ranges::views::filter(not_fn(&string::empty))) |
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.
Instead of the boost::split
I could also split on the fly using ranges...
constexpr auto splitString = [](auto _pred) {
return ranges::views::split_when(move(_pred)) | ranges::views::transform([](auto&& _rng){
return string_view(&*begin(_rng), static_cast<string_view::size_type>(ranges::distance(_rng)));
});
};
for (auto value: tagValue.content | splitString(isWhiteSpace) | ranges::views::filter(not_fn(&string_view::empty)))
But maybe that's over the top...
38a8612
to
d924581
Compare
Updated the warnings. We should probably be clear that we can also merge the other one, before merging this, though. Although it doesn't matter as long as we manage for the same release I guess. |
d924581
to
3730c58
Compare
3730c58
to
6b6e163
Compare
} | ||
// ---- | ||
// Warning 6269: (177-188): Unexpected NatSpec tag "after" with value "bogus-value" in inline assembly. | ||
// Warning 6269: (177-188): Unexpected NatSpec tag "before" with value "@solidity a memory-safe-assembly b c d" in inline 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.
We can also properly make inline assembly
StructurallyDocumented
, etc, but then we need to double-check that existing natspec-style comments don't cause any errors to keep this fully non-breaking.