-
Notifications
You must be signed in to change notification settings - Fork 266
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
Adding MCOPY Instruction #2711
base: master
Are you sure you want to change the base?
Adding MCOPY Instruction #2711
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.
Good job. Simple, straight to the point and with an amazing test. Well done!
rskj-core/src/test/resources/dsl/opcode/mcopy/mCopyTestCase1.txt
Outdated
Show resolved
Hide resolved
// gas cost = 3 * (length + 31) + memory expansion cost + very low | ||
long length = stack.get(stack.size() - 3).longValue(); | ||
long newMemSize = memNeeded(stack.peek(), length); | ||
long cost = 3 * (length + 31) + calcMemGas(oldMemSize, newMemSize, 0) + 3; // TODO -> Check copy size |
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 order to calculate the number of words we are missing to divide the total size by the dataword length being (length + 31) / 32
instead of only (length + 31)
.
Also I think it is more readable if we store the different values separated adding a meaningful name to them
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.
Nice! will continue with this in the next PR. 💪🏼
e640b71
to
a47d5c9
Compare
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.
Nice job!
Really liked the organization from DSL tests and the tests itself, well done!
DataWord length = program.stackPop(); | ||
|
||
if (isLogEnabled) { | ||
hint = "dst: " + dst + " src: " + src + " length: " + length; |
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.
suggestion:
I noticed that you are not logging at the end, maybe would be good to log these parameters that you set.
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.
Take a look at this comment @nagarev. :)
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.
Well done @nagarev. These tests are pretty complete and shows a hard work in fulfil the scenarios of test from the EIP.
I just have a few comments to improve it even more the readability. But they are not blocking and doesn't prevent the approval.
You need to fix some tests though, it seems that it's broke for java-17 and java-21.
// See "Gas Cost" section on EIP 5656 | ||
// gas cost = 3 * (length + 31) + memory expansion cost + very low |
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.
suggestion:
The part very low
isn't clear as long as we read the EIP. I suggest you rephrase it. Maybe to gas fixed for very low mem usage
. Or just put it plainly 3.
DataWord length = program.stackPop(); | ||
|
||
if (isLogEnabled) { | ||
hint = "dst: " + dst + " src: " + src + " length: " + length; |
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.
Take a look at this comment @nagarev. :)
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.
suggestion:
You are using meaningful names for the variables and methods, I think you don't need the comments explaining that you are checking that a block has a single transaction, or that that the transaction has a receipt. Let the code speak for itself, you are already using principles of clean code with good names for variables and methods, the comments can age badly and wouldn't be missed. 🙂
// There's one block (b01) containing only 1 transaction | ||
Block block1 = world.getBlockByName("b01"); | ||
Assertions.assertNotNull(block1); | ||
Assertions.assertEquals(1, block1.getTransactionsList().size()); | ||
|
||
// There's a transaction called txTestMCopy | ||
Transaction txTestMCopy = world.getTransactionByName("txTestMCopy"); | ||
Assertions.assertNotNull(txTestMCopy); | ||
|
||
// Transaction txTestMCopy has a transaction receipt | ||
TransactionReceipt txTestMCopyReceipt = world.getTransactionReceiptByName("txTestMCopy"); | ||
Assertions.assertNotNull(txTestMCopyReceipt); | ||
|
||
// Transaction txTestMCopy has been processed correctly | ||
byte[] creationStatus = txTestMCopyReceipt.getStatus(); | ||
Assertions.assertNotNull(creationStatus); | ||
Assertions.assertEquals(1, creationStatus.length); | ||
Assertions.assertEquals(1, creationStatus[0]); |
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.
suggestion:
You could extract these assertions to a method, because they are repeating thoroughly in your class. Something like this one here could do the job.v Be aware that you might need to adapt this methid, since you might have transactionReceipt but with the length 0.
// https://github.com/ethereum/execution-spec-tests/blob/c0065176a79f89d93f4c326186fc257ec5b8d5f1/tests/cancun/eip5656_mcopy/test_mcopy.py) | ||
|
||
@Test | ||
void testMCOPY_overwriteCases_behaveAsExpected() throws FileNotFoundException, DslProcessorException { |
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.
praise:
Well done my friend, this test it's very complete and it should have been a bit tricky understand the python one and convert it to a proper DSL. 👏
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.OpenSSF Scorecard
Scanned Manifest Files |
Description
Besides memory copying being a basic operation, implementing it on the VM comes with overhead, as described in the EIP-5656
Currently memory copying can be achieved by the usage of
CALL
,MLOAD
andMSTORE
(among others opcodes) depending on the scenarios where the memory copy is being done.The
MCOPY
instruction will be introduced at0x5E
.Motivation and Context
Increase compatibility
How Has This Been Tested?
Types of changes
Checklist:
N/A