Skip to content
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

Merged
merged 27 commits into from
Dec 17, 2024
Merged

Adding MCOPY Instruction #2711

merged 27 commits into from
Dec 17, 2024

Conversation

nagarev
Copy link
Contributor

@nagarev nagarev commented Sep 5, 2024

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 and MSTORE (among others opcodes) depending on the scenarios where the memory copy is being done.

The MCOPY instruction will be introduced at 0x5E.

Motivation and Context

Increase compatibility

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Tests for the changes have been added (for bug fixes / features)
  • Requires Activation Code (Hard Fork)
  • Other information:

N/A

fmacleal
fmacleal previously approved these changes Sep 19, 2024
Copy link
Contributor

@fmacleal fmacleal left a 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!

fmacleal
fmacleal previously approved these changes Sep 27, 2024
Copy link
Contributor

@fmacleal fmacleal left a 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!

fmacleal
fmacleal previously approved these changes Oct 15, 2024
Copy link
Contributor

@fmacleal fmacleal left a 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.

Copy link

github-actions bot commented Nov 4, 2024

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Manifest Files

@fmacleal fmacleal mentioned this pull request Dec 3, 2024
8 tasks
@nagarev nagarev marked this pull request as ready for review December 9, 2024 13:20
@nagarev nagarev requested a review from Vovchyk December 9, 2024 13:20
Vovchyk
Vovchyk previously approved these changes Dec 10, 2024
asoto-iov
asoto-iov previously approved these changes Dec 10, 2024
@@ -767,6 +767,16 @@ private long computeDataCopyGas() {
return calcMemGas(oldMemSize, newMemSize, copySize);
}

private long computeMemoryCopyGas() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still only charging for memory expansion, but ignoring the copy cost. Please update following the specs

https://github.com/ethereum/EIPs/blob/master/EIPS/eip-5656.md#gas-costs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donequis , do you mean the constant MCopy cost (value of g_verylow from the formula) ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. There's a price pay for word copied. 3 * words_copied

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. if so, it's defined in here, and used in here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the formula has 3 components. First is memory expansion which is considered here. Second is the basic cost. Third part is the length copied. This las part is not considered in the cost.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't that part in here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right. My bad.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we are good to go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries. It's good to validate assumptions and align on that

@nagarev nagarev requested a review from donequis December 13, 2024 19:45
Copy link
Contributor

@fmacleal fmacleal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, the improvements and refactors in tests are very nice. Indeed a complete number of tests.

private Program executeCodeWithActivationConfig(String code, DataWord[] stack, int nsteps, ActivationConfig.ForBlock activations) {
return executeCodeWithActivationConfig(compiler.compile(code), stack, nsteps, activations);
}

private Program executeCodeWithActivationConfig(byte[] code, int nsteps, ActivationConfig.ForBlock activations) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

This method could be simplified as well to something like this:

    private Program executeCodeWithActivationConfig(byte[] code, int nsteps, ActivationConfig.ForBlock activations) {
        return executeCodeWithActivationConfig(code, new DataWord[0], nsteps, activations);
    }

@MethodSource("provideParametersForMCOPYTestCases")
void testMCOPY_OnEachTestCase_ExecutesAsExpected(String dslFile) throws FileNotFoundException, DslProcessorException {

DslParser parser = DslParser.fromResource("dsl/opcode/mcopy/" + dslFile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise:

Congrats to have simplified the tests with the input arguments. well done!


@ParameterizedTest
@MethodSource("provideParametersForMCOPYTestCases")
void testMCOPY_OnEachTestCase_ExecutesAsExpected(String dslFile) throws FileNotFoundException, DslProcessorException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise:

I liked of the simplification with the name of each scenario file. Saved a lot of lines of testing.

@Vovchyk Vovchyk merged commit d072012 into master Dec 17, 2024
13 checks passed
@Vovchyk Vovchyk deleted the add-mcopy branch December 17, 2024 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants