-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Yul builtin for MCOPY
#14779
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
Merged
Yul builtin for MCOPY
#14779
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ using namespace solidity::langutil; | |
| using namespace solidity::evmasm; | ||
| using namespace solidity::frontend; | ||
| using namespace solidity::frontend::test; | ||
| using namespace solidity::test; | ||
|
|
||
| namespace solidity::frontend::test | ||
| { | ||
|
|
@@ -339,6 +340,113 @@ BOOST_AUTO_TEST_CASE(complex_control_flow) | |
| testRunTimeGas("ln(int128)", std::vector<bytes>{encodeArgs(0), encodeArgs(10), encodeArgs(105), encodeArgs(30000)}); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_CASE( | ||
| mcopy_memory_expansion_gas, | ||
| *boost::unit_test::precondition(minEVMVersionCheck(EVMVersion::cancun())) | ||
| ) | ||
| { | ||
| char const* sourceCode = R"( | ||
| contract C { | ||
| function no_expansion() public { | ||
| assembly { | ||
| mstore(0xffe0, 1) // expand memory before using mcopy | ||
| mcopy(0, 0xffff, 1) | ||
| return(0, 1) | ||
| } | ||
| } | ||
|
|
||
| function expansion_on_write() public { | ||
| assembly { | ||
| mcopy(0xffff, 0, 1) | ||
| return(0xffff, 1) | ||
| } | ||
| } | ||
|
|
||
| function expansion_on_read() public { | ||
| assembly { | ||
| mcopy(0, 0xffff, 1) | ||
| return(0, 1) | ||
| } | ||
| } | ||
|
|
||
| function expansion_on_read_write() public { | ||
| assembly { | ||
| mcopy(0xffff, 0xffff, 1) | ||
| return(0, 1) | ||
| } | ||
| } | ||
|
|
||
| function expansion_on_zero_size() public { | ||
| assembly { | ||
| mcopy(0xffff, 0xffff, 0) | ||
| return(0, 1) | ||
| } | ||
| } | ||
|
|
||
| function expansion_on_0_0_0() public { | ||
| assembly { | ||
| mcopy(0, 0, 0) | ||
| return(0, 1) | ||
| } | ||
| } | ||
| } | ||
| )"; | ||
| testCreationTimeGas(sourceCode); | ||
| testRunTimeGas("no_expansion()", {encodeArgs()}); | ||
| testRunTimeGas("expansion_on_write()", {encodeArgs()}); | ||
| testRunTimeGas("expansion_on_read()", {encodeArgs()}); | ||
| testRunTimeGas("expansion_on_read_write()", {encodeArgs()}); | ||
| testRunTimeGas("expansion_on_zero_size()", {encodeArgs()}); | ||
| testRunTimeGas("expansion_on_0_0_0()", {encodeArgs()}); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_CASE( | ||
| mcopy_word_gas, | ||
| *boost::unit_test::precondition(minEVMVersionCheck(EVMVersion::cancun())) | ||
| ) | ||
| { | ||
| char const* sourceCode = R"( | ||
| contract C { | ||
| function no_overlap() public { | ||
| assembly { | ||
| mstore(0xffe0, 1) // expand memory before using mcopy | ||
| mcopy(0x4000, 0x2000, 0x2000) | ||
| return(0, 0x10000) | ||
| } | ||
| } | ||
|
|
||
| function overlap_right() public { | ||
| assembly { | ||
| mstore(0xffe0, 1) // expand memory before using mcopy | ||
| mcopy(0x3000, 0x2000, 0x2000) | ||
| return(0, 0x10000) | ||
| } | ||
| } | ||
|
|
||
| function overlap_left() public { | ||
| assembly { | ||
| mstore(0xffe0, 1) // expand memory before using mcopy | ||
| mcopy(0x1000, 0x2000, 0x2000) | ||
| return(0, 0x10000) | ||
| } | ||
| } | ||
|
|
||
| function overlap_full() public { | ||
| assembly { | ||
| mstore(0xffe0, 1) // expand memory before using mcopy | ||
| mcopy(0x2000, 0x2000, 0x2000) | ||
| return(0, 0x10000) | ||
| } | ||
| } | ||
| } | ||
| )"; | ||
| testCreationTimeGas(sourceCode); | ||
| testRunTimeGas("no_overlap()", {encodeArgs()}); | ||
| testRunTimeGas("overlap_right()", {encodeArgs()}); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should have this kind of test for all the Cancun opcodes - |
||
| testRunTimeGas("overlap_left()", {encodeArgs()}); | ||
| testRunTimeGas("overlap_full()", {encodeArgs()}); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_SUITE_END() | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| contract C { | ||
| constructor() { | ||
| assembly ("memory-safe") {} | ||
| } | ||
|
|
||
| function f() public { | ||
| assembly ("memory-safe") {} | ||
| } | ||
| } | ||
| // ---- | ||
| // :C(creation) true | ||
| // :C(runtime) true |
16 changes: 16 additions & 0 deletions
16
test/libsolidity/memoryGuardTests/marked_with_memory_access.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| contract C { | ||
| constructor() { | ||
| assembly ("memory-safe") { | ||
| mstore(0, 1) | ||
| } | ||
| } | ||
|
|
||
| function store() public { | ||
| assembly ("memory-safe") { | ||
| mstore(0, 1) | ||
| } | ||
| } | ||
| } | ||
| // ---- | ||
| // :C(creation) true | ||
| // :C(runtime) true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| contract C { | ||
| constructor() { | ||
| assembly {} | ||
| } | ||
|
|
||
| function f() public { | ||
| assembly {} | ||
| } | ||
| } | ||
| // ---- | ||
| // :C(creation) true | ||
| // :C(runtime) true |
8 changes: 0 additions & 8 deletions
8
test/libsolidity/memoryGuardTests/unmarked_with_memory_access.sol
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
test/libsolidity/memoryGuardTests/unmarked_with_memory_access_mcopy.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| contract C { | ||
| constructor() { | ||
| assembly { | ||
| mcopy(1000, 2000, 1000) | ||
| } | ||
| } | ||
|
|
||
| function copy() public { | ||
| assembly { | ||
| mcopy(1000, 2000, 1000) | ||
| } | ||
| } | ||
| } | ||
| // ==== | ||
| // EVMVersion: >=cancun | ||
| // ---- | ||
| // :C(creation) false | ||
| // :C(runtime) false | ||
cameel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.