Skip to content

Commit 3f47c2d

Browse files
committed
fixup! Yul builtin for MCOPY
1 parent 8fa3441 commit 3f47c2d

File tree

10 files changed

+199
-0
lines changed

10 files changed

+199
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
contract C {
2+
function expansion_on_write_only() public returns (uint newMsize) {
3+
assembly {
4+
mcopy(0xfff0, 0, 1)
5+
newMsize := msize()
6+
}
7+
}
8+
9+
function expansion_on_read_only() public returns (uint newMsize) {
10+
assembly {
11+
mcopy(0, 0xfff0, 1)
12+
newMsize := msize()
13+
}
14+
}
15+
16+
function expansion_on_read_write() public returns (uint newMsize) {
17+
assembly {
18+
mcopy(0xfff0, 0xfff0, 1)
19+
newMsize := msize()
20+
}
21+
}
22+
23+
function expansion_on_zero_size() public returns (uint newMsize) {
24+
assembly {
25+
mcopy(0xfff0, 0xfff0, 0)
26+
newMsize := msize()
27+
}
28+
}
29+
}
30+
// ====
31+
// EVMVersion: >=cancun
32+
// ----
33+
// expansion_on_write_only() -> 0x010000
34+
// expansion_on_read_only() -> 0x010000
35+
// expansion_on_read_write() -> 0x010000
36+
// expansion_on_zero_size() -> 0x60
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
// Should not affect msize
3+
mcopy(0x30, 0x30, 0)
4+
sstore(0, msize())
5+
}
6+
// ====
7+
// EVMVersion: >=cancun
8+
// ----
9+
// Trace:
10+
// MCOPY(48, 48, 0)
11+
// Memory dump:
12+
// Storage dump:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
// Should expand memory to two full words (0x40 bytes)
3+
mcopy(0x30, 0, 1)
4+
sstore(0, msize())
5+
}
6+
// ====
7+
// EVMVersion: >=cancun
8+
// ----
9+
// Trace:
10+
// MCOPY(48, 0, 1)
11+
// Memory dump:
12+
// Storage dump:
13+
// 0000000000000000000000000000000000000000000000000000000000000000: 0000000000000000000000000000000000000000000000000000000000000040
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
// Should expand memory to two full words (0x40 bytes)
3+
mcopy(0x30, 0, 1)
4+
sstore(0, msize())
5+
}
6+
// ====
7+
// EVMVersion: >=cancun
8+
// ----
9+
// Trace:
10+
// MCOPY(48, 0, 1)
11+
// Memory dump:
12+
// Storage dump:
13+
// 0000000000000000000000000000000000000000000000000000000000000000: 0000000000000000000000000000000000000000000000000000000000000040
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
calldatacopy(0, 0, 0x60)
3+
4+
mcopy(0x20, 0x40, 0x20)
5+
6+
return(0, 0x60)
7+
}
8+
// ====
9+
// EVMVersion: >=cancun
10+
// ----
11+
// step: expressionSimplifier
12+
//
13+
// {
14+
// {
15+
// let _1 := 0x60
16+
// let _2 := 0
17+
// calldatacopy(_2, _2, _1)
18+
// let _4 := 0x20
19+
// mcopy(_4, 0x40, _4)
20+
// return(_2, _1)
21+
// }
22+
// }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
calldatacopy(0, 0, 0x60)
3+
4+
mcopy(0x20, 0x40, 0) // Equivalent to mcopy(0, 0, 0)
5+
6+
return(0, 0x60)
7+
}
8+
// ====
9+
// EVMVersion: >=cancun
10+
// ----
11+
// step: expressionSimplifier
12+
//
13+
// {
14+
// {
15+
// let _1 := 0x60
16+
// let _2 := 0
17+
// calldatacopy(_2, _2, _1)
18+
// mcopy(0, 0, _2)
19+
// return(_2, _1)
20+
// }
21+
// }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
calldatacopy(0, 0, 0x40)
3+
4+
mcopy(0x20, 0, 0x20) // Not redundant. MCOPY reads it.
5+
mcopy(0x40, 0x10, 0x30)
6+
mstore(0x20, 42)
7+
8+
return(0, 0x40)
9+
}
10+
// ====
11+
// EVMVersion: >=cancun
12+
// ----
13+
// step: fullSuite
14+
//
15+
// {
16+
// {
17+
// calldatacopy(0, 0, 0x40)
18+
// mcopy(0x20, 0, 0x20)
19+
// mcopy(0x40, 0x10, 0x30)
20+
// mstore(0x20, 42)
21+
// return(0, 0x40)
22+
// }
23+
// }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
calldatacopy(0, 0, 0x40)
3+
4+
mcopy(0, 0x20, 0x20) // Redundant. Overwritten by MSTORE.
5+
mstore(0, 42)
6+
7+
return(0, 0x40)
8+
}
9+
// ====
10+
// EVMVersion: >=cancun
11+
// ----
12+
// step: fullSuite
13+
//
14+
// {
15+
// {
16+
// calldatacopy(0, 0, 0x40)
17+
// mcopy(0, 0x20, 0x20)
18+
// mstore(0, 42)
19+
// return(0, 0x40)
20+
// }
21+
// }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
calldatacopy(0, 0, 0x20)
3+
4+
mcopy(0, 0, 0x20) // Redundant. Does not change any values (only affects MSIZE).
5+
6+
return(0, 0x20)
7+
}
8+
// ====
9+
// EVMVersion: >=cancun
10+
// ----
11+
// step: fullSuite
12+
//
13+
// {
14+
// {
15+
// calldatacopy(0, 0, 0x20)
16+
// mcopy(0, 0, 0x20)
17+
// return(0, 0x20)
18+
// }
19+
// }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
calldatacopy(0, 0, 0x40)
3+
4+
mcopy(0, 0x20, 0) // Redundant. Does not copy anything.
5+
6+
return(0, 0x40)
7+
}
8+
// ====
9+
// EVMVersion: >=cancun
10+
// ----
11+
// step: fullSuite
12+
//
13+
// {
14+
// {
15+
// calldatacopy(0, 0, 0x40)
16+
// mcopy(0, 0, 0)
17+
// return(0, 0x40)
18+
// }
19+
// }

0 commit comments

Comments
 (0)