-
Notifications
You must be signed in to change notification settings - Fork 319
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 MCOPY tests #1229
Add MCOPY tests #1229
Conversation
The MCOPY test file focus on properly copying memory bytes. The MCOPY_copy_cost test file focus on properly calculating the MCOPY instruction copy gas cost. The MCOPY_memory_expansion_cost test file focus on properly calculating potential memory expansion cost in the MCOPY instruction.
This is ready from my side. |
Besu passes these tests. |
EthereumJS passes these tests. However, there is a case missing (I think). We had a bug in the gas calculation where the src > dst, and we are going to read out-of-bounds of current memory. The memory should thus be expanded to |
So, what should be done in that test, is perform the exact same MCOPY again, to see if memory is properly expanded or not (now memory expansion costs are 0). In our case, memory expansion costs will not be zero. |
Actually, never mind, we do extend, but if uncovered it should maybe be added. |
Nethermind passes these tests :) |
All tests in
In
However, I'm not sure how effective these are for finding bugs out-of-bound or uninitialized-memory bugs. We can add more cases if you have precise values of |
I just saw that MSIZE is stored, but the idea would be to, after storing MSIZE, perform the exact same MCOPY operation again. This would detect a case that internally the MSIZE is set correctly, but somehow when resizing it, it takes the wrong MSIZE (for instance if it did not properly expand the memory with extra zeros). However upon writing this, this seems like a super exotic bug. But you could edit the test code to MCOPY again, to ensure that the gas costs are also correct if you call it again (hence now expansion cost is zero). I'll add a comment, but I doubt this will find bugs. |
mcopy(calldataload(0), calldataload(32), calldataload(64)) | ||
|
||
// Put MSIZE in storage. | ||
sstore(0, msize()) |
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.
After this line, do
mcopy(calldataload(0), calldataload(32), calldataload(64))
again
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 will add one more test suite for 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.
Ok great 😄
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.
Added in #1234.
The MCOPY test file focus on properly copying memory bytes.
The MCOPY_copy_cost test file focus on properly calculating the MCOPY instruction copy gas cost.
The MCOPY_memory_expansion_cost test file focus on properly calculating potential memory expansion cost in the MCOPY instruction.