-
Notifications
You must be signed in to change notification settings - Fork 333
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
stdStorage: support packed variables #505
Conversation
Two comments, though I have not reviewed yet, and cc @brockelmore in case he has any thoughts:
|
|
hey @mds1 after some updates I managed to make that test pass. Do you think that it makes sense to make packed variables discovery optional as it's done in #148 via |
Is there a way we can special case these traces upstream in forge to hide them from output, or condense them into a one-line summary of what's been hidden? If not, I do think we should make it opt-in, because the size of the trace can be pretty dominating compared to the rest of the trace |
I don't think that we have a way to hide specific traces. I'll make it optional for now, and will keep that in mind for the moment when we'll be upstreaming |
I will take a look but i thought about doing the algorithm laid out in this paper: https://seclab.cs.ucsb.edu/files/publications/ruaro24crush.pdf basically: you track sloads’ masks and shifts, then when an sload is returned you’re given the offset right and left. this would be a modification of a cheatcode (or an entirely new cheatcode). Likely this would look like watching for an sload, tracking its spot in the stack, and any mask or shifting operations would be recorded. Upon a return, the left and right offset would be calculated and returned. Inside StdStorage, these offsets would be stored and applied on a write. |
@mds1 it seems that this fixes the USDC issues even with this is happening because of the overall change of slot discovery logic previously it was working like this:
The new impl always uses first slot such that it affects return value (checked via New impl is safe to use for writing as we only support "checked" writes which verify that resulted slot value matches the value that we wanted to write to it. However, in some cases new impl might be bad at reading as it may mistakenly find packed slot. Previous impl could do that too for single read case. I don't think that using |
Oh cool, that's great that it fixes the USDC issues even with Also, given that the USDC case works even with And admittedly I have not closely read the code in this PR yet so unfamiliar with the details which may answer these questions |
in that case slot value will not match call return value and
when it's enabled we do not require slot value to exactly match call result, but instead are looking for a slot bits range (basically pair of offsets) that does match 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.
Thank you!
This was initially designed to fix probles with USDC, but it seems that we are now able to modify pretty much any packed storage variables.
This is still a WIP as I believe binary operations can be rewritten a bit cleaner but it already works.
I've updated some of the negative tests on failing packed variables decoding to being positive.
The solution is to try finding such
offsetLeft
andoffsetRight
for a storage slot, that it'svalue[offsetLeft:-offsetRight]
exactly equals the return data of the given function