-
-
Notifications
You must be signed in to change notification settings - Fork 793
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
Add msg.data environment variable VIP-1181 #2343
Conversation
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 was thinking the implementation would be slightly different, more like this:
Ahhh @fubuloubu I like that syntax/implementation better, since it looks like one is explicitly extracting a piece of the calldata, instead of the syntax I used which looks like indexing a reference to calldata. I'll get to work on adjusting 👍 |
Codecov Report
@@ Coverage Diff @@
## master #2343 +/- ##
==========================================
+ Coverage 85.73% 85.77% +0.03%
==========================================
Files 90 90
Lines 8765 8795 +30
Branches 2091 2099 +8
==========================================
+ Hits 7515 7544 +29
Misses 760 760
- Partials 490 491 +1
Continue to review full report at Codecov.
|
Sorry for the force push ... not sure if that's accepted around these parts 👀 |
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.
Sorry for the force push ... not sure if that's accepted around these parts
No worries, works for me!
I didn't implement the compile-time bounds checking as you commented @fubuloubu, since there are times in which
calldatasize
will exceed the compile-time expected size. EIP-2771 for example. I also totally missed previously handlinglen(msg.data)
so that's included now, as well as the right syntaxslice(msg.data, x, k)
.
This should be okay! I think if you try to pull calldata longer than CALLDATASIZE
the EVM's behavior is to give you empty data. So, it should be safe. Also, it is okay for CALLDATASIZE
to exceed the expected size, the check was that it is at least the expected size to make sure we don't run into empty values unexpectedly (leading to difficult-to-debug behavior).
As such, this PR is a great addition! Thank you!
ahh @fubuloubu I see what you mean, isn't that handled already though? Indirectly through
Should I remove that runtime bounds check then? Since like you said, if you slice past the bound of |
I prefer to have it. For some reason I misread and thought you hadn't implemented it, but I see now that you did! |
Awesome! The checks just have to run through one last time and should be good then 🤞 |
- Assignment to storage - Free memory pointer correctly goes to next position - TypeMismatch Error for assignment to bytes32
@iamdefinitelyahuman that's a good test case I didn't include, I added it in, looks like that works as expected, along with the memory position advancement, and assignment to bytes32 throwing a TypeMismatch exception. |
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.
Great job!
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.
lgtm
does anyone know how can I do this without use msg.data??? |
What I did
As per #1181, I added the msg.data environment variable, allowing access to the complete calldata within external functions.
Also updated the docs to include information on the syntax/usage of msg.data.
How I did it
data
member in themsg
environment variable -vyper/context/environment.py
msg.data
node depending on usage -vyper/context/validation/annotation.py
msg.data
branch in theparse_Attribute
fn, to return the appropriate LLLNode based on whether usage is inlen
orslice
-vyper/parser/expr.py
msg.data
is used inside an internal function -vyper/context/validation/local.py
msg.data
is used outside oflen
orslice
Similar to before this copies the calldata to an internal variable before it gets sliced, I'm sure in the future we can work on cacheing
msg.data
but that's a whole 'nother beast. The use oflen(msg.data)
simply just used thecalldatasize
opcode and isn't as bad I hope.How to verify it
I've added a few tests, which can be found in
tests/parser/syntax/test_msg_data.py
.Description for the changelog
Added msg.data syntax allowing access to full calldata in external functions
Cute Animal Picture
Closes #1181