Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
contract C {
uint16[2][3] nestedU16;
uint256[4][5][4] nestedU256;

constructor() {
nestedU16[0][0] = 1;
nestedU16[0][1] = 2;
nestedU16[1][0] = 3;
nestedU16[1][1] = 4;
nestedU16[2][0] = 5;
nestedU16[2][1] = 6;

uint256 value = 1;
for (uint256 i = 0; i < 4; ++i) {
for (uint256 j = 0; j < 5; ++j) {
for (uint256 k = 0; k < 4; ++k)
nestedU256[i][j][k] = value++;
}
}
}

function ep_nested_u16_memory(uint16[2][3] memory x) public pure returns (bytes memory) {
return abi.encodePacked(x);
}

function ep_nested_u16_calldata(uint16[2][3] calldata x) external pure returns (bytes memory) {
return abi.encodePacked(x);
}

function ep_nested_u16_storage() external view returns (bytes memory) {
return abi.encodePacked(nestedU16);
}

function ep_nested_u256_memory(uint256[4][5][4] memory x) public pure returns (bytes memory) {
return abi.encodePacked(x);
}

function ep_nested_u256_calldata(uint256[4][5][4] calldata x) external pure returns (bytes memory) {
return abi.encodePacked(x);
}

function ep_nested_u256_storage() external view returns (bytes memory) {
return abi.encodePacked(nestedU256);
}

function ep_nested_addr_memory(address[2][2] memory x) public pure returns (bytes memory) {
return abi.encodePacked(x);
}
}

// ====
// compileViaMlir: true
// ----
// constructor() ->
// ep_nested_u16_memory(uint16[2][3]): 1, 2, 3, 4, 5, 6 -> 32, 192, 1, 2, 3, 4, 5, 6
// ep_nested_u16_calldata(uint16[2][3]): 1, 2, 3, 4, 5, 6 -> 32, 192, 1, 2, 3, 4, 5, 6
// ep_nested_u16_storage() -> 32, 192, 1, 2, 3, 4, 5, 6
// ep_nested_u256_memory(uint256[4][5][4]): 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80 -> 32, 2560, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80
// ep_nested_u256_calldata(uint256[4][5][4]): 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80 -> 32, 2560, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80
// ep_nested_u256_storage() -> 32, 2560, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80
// ep_nested_addr_memory(address[2][2]): 1, 2, 3, 4 -> 32, 128, 1, 2, 3, 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
contract C {
uint256[] dyn256;
uint128[] dyn128;
uint8[] dyn8;

uint256[10] static256x10;
uint128[3] static128x3;
uint8[31] static8x31;
uint8[32] static8x32;
uint8[33] static8x33;

constructor() {
dyn256.push(0x11);
dyn256.push(0x22);

dyn128.push(0x1234);
dyn128.push(0x5678);
dyn128.push(0x9abc);

dyn8.push(1);
dyn8.push(2);
dyn8.push(3);
dyn8.push(4);

for (uint256 i = 0; i < 10; ++i)
static256x10[i] = i + 1;

for (uint256 i = 0; i < 3; ++i)
static128x3[i] = uint128((i + 1) * 16);

for (uint256 i = 0; i < 31; ++i)
static8x31[i] = uint8(i + 1);

for (uint256 i = 0; i < 32; ++i)
static8x32[i] = uint8(i + 1);

for (uint256 i = 0; i < 33; ++i)
static8x33[i] = uint8(i + 1);
}

function ep_u256_array_dynamic_storage() public view returns (bytes memory) {
return abi.encodePacked(dyn256);
}

function ep_u128_array_dynamic_storage() public view returns (bytes memory) {
return abi.encodePacked(dyn128);
}

function ep_u8_array_dynamic_storage() public view returns (bytes memory) {
return abi.encodePacked(dyn8);
}

function ep_u256_array_static_storage() public view returns (bytes memory) {
return abi.encodePacked(static256x10);
}

function ep_u128_array_static_storage() public view returns (bytes memory) {
return abi.encodePacked(static128x3);
}

function ep_u8_array_static_storage_31() public view returns (bytes memory) {
return abi.encodePacked(static8x31);
}

function ep_u8_array_static_storage_32() public view returns (bytes memory) {
return abi.encodePacked(static8x32);
}

function ep_u8_array_static_storage_33() public view returns (bytes memory) {
return abi.encodePacked(static8x33);
}
}

// ====
// compileViaMlir: true
// ----
// constructor() ->
// ep_u256_array_dynamic_storage() -> 32, 64, 17, 34
// ep_u128_array_dynamic_storage() -> 32, 96, 4660, 22136, 39612
// ep_u8_array_dynamic_storage() -> 32, 128, 1, 2, 3, 4
// ep_u256_array_static_storage() -> 32, 320, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
// ep_u128_array_static_storage() -> 32, 96, 16, 32, 48
// ep_u8_array_static_storage_31() -> 32, 992, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
// ep_u8_array_static_storage_32() -> 32, 1024, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
// ep_u8_array_static_storage_33() -> 32, 1056, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33
133 changes: 133 additions & 0 deletions test/libsolidity/semanticTests/mlir/abi-encode-storage-array.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
contract C {
struct U256Pair {
uint256 left;
uint256 right;
}

uint256[] dyn256;

uint8[4] static8x4;
uint8[31] static8x31;
uint8[32] static8x32;
uint8[33] static8x33;
uint256[3] static256x3;

uint256[][] dynRefDyn256;
uint256[2][] dynRefStatic2x;
uint256[][2] staticRefDyn256x2;
U256Pair[] dynStructPair;
U256Pair[2] staticStructPair2;

constructor() {
dyn256.push(11);
dyn256.push(22);
dyn256.push(33);

static8x4[0] = 1;
static8x4[1] = 2;
static8x4[2] = 3;
static8x4[3] = 4;

for (uint256 i = 0; i < 31; ++i)
static8x31[i] = uint8(i + 1);

for (uint256 i = 0; i < 32; ++i)
static8x32[i] = uint8(i + 1);

for (uint256 i = 0; i < 33; ++i)
static8x33[i] = uint8(i + 1);

static256x3[0] = 1;
static256x3[1] = 2;
static256x3[2] = 3;

dynRefDyn256.push();
dynRefDyn256[0].push(101);
dynRefDyn256[0].push(202);
dynRefDyn256.push();
dynRefDyn256[1].push(303);

dynRefStatic2x.push();
dynRefStatic2x[0][0] = 10;
dynRefStatic2x[0][1] = 20;
dynRefStatic2x.push();
dynRefStatic2x[1][0] = 30;
dynRefStatic2x[1][1] = 40;

staticRefDyn256x2[0].push(7);
staticRefDyn256x2[0].push(8);
staticRefDyn256x2[1].push(9);

dynStructPair.push();
dynStructPair[0].left = 111;
dynStructPair[0].right = 222;
dynStructPair.push();
dynStructPair[1].left = 333;
dynStructPair[1].right = 444;

staticStructPair2[0].left = 555;
staticStructPair2[0].right = 666;
staticStructPair2[1].left = 777;
staticStructPair2[1].right = 888;
}

function ei_u256_array_dynamic_storage() public view returns (bytes memory) {
return abi.encode(dyn256);
}

function ei_u8_array_static_storage_4() public view returns (bytes memory) {
return abi.encode(static8x4);
}

function ei_u8_array_static_storage_31() public view returns (bytes memory) {
return abi.encode(static8x31);
}

function ei_u8_array_static_storage_32() public view returns (bytes memory) {
return abi.encode(static8x32);
}

function ei_u8_array_static_storage_33() public view returns (bytes memory) {
return abi.encode(static8x33);
}

function ei_u256_array_static_storage_3() public view returns (bytes memory) {
return abi.encode(static256x3);
}

function ei_u256_array_array_dynamic_storage() public view returns (bytes memory) {
return abi.encode(dynRefDyn256);
}

function ei_u256x2_array_dynamic_storage() public view returns (bytes memory) {
return abi.encode(dynRefStatic2x);
}

function ei_u256_array_static_storage_2() public view returns (bytes memory) {
return abi.encode(staticRefDyn256x2);
}

function ei_u256_pair_array_dynamic_storage() public view returns (bytes memory) {
return abi.encode(dynStructPair);
}

function ei_u256_pair_array_static_storage_2() public view returns (bytes memory) {
return abi.encode(staticStructPair2);
}
}

// ====
// compileViaMlir: true
// ----
// constructor() ->
// ei_u256_array_dynamic_storage() -> 0x20, 160, 0x20, 3, 11, 22, 33
// ei_u8_array_static_storage_4() -> 0x20, 128, 1, 2, 3, 4
// ei_u8_array_static_storage_31() -> 0x20, 992, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
// ei_u8_array_static_storage_32() -> 0x20, 1024, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
// ei_u8_array_static_storage_33() -> 0x20, 1056, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33
// ei_u256_array_static_storage_3() -> 0x20, 96, 1, 2, 3
// ei_u256_array_array_dynamic_storage() -> 0x20, 288, 0x20, 2, 0x40, 0xa0, 2, 101, 202, 1, 303
// ei_u256x2_array_dynamic_storage() -> 0x20, 192, 0x20, 2, 10, 20, 30, 40
// ei_u256_array_static_storage_2() -> 0x20, 256, 0x20, 0x40, 0xa0, 2, 7, 8, 1, 9
// ei_u256_pair_array_dynamic_storage() -> 0x20, 192, 0x20, 2, 111, 222, 333, 444
// ei_u256_pair_array_static_storage_2() -> 0x20, 128, 555, 666, 777, 888
43 changes: 41 additions & 2 deletions test/libsolidity/semanticTests/mlir/abi-encode-struct.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ contract C {
uint256 d;
}

// FIXME: Enable storage encoding tests with Big/Nested once storage-array
// encoding is fixed.
struct S {
uint256 a;
uint256 b;
}

Big storageBig;
Nested storageBigNested;
StorageFlat storageFlat;
StorageNested storageNested;
StoragePacked storagePacked;
Expand All @@ -53,6 +58,25 @@ contract C {
storagePacked.b = 2;
storagePacked.c = true;
storagePacked.d = 3;

storageBig.id = 7;
storageBig.code = 8;
storageBig.note = "abc";
storageBig.fixedArr[0] = 41;
storageBig.fixedArr[1] = 42;
storageBig.dynArr.push(11);
storageBig.dynArr.push(12);
storageBig.dynArr.push(13);

storageBigNested.salt = 100;
storageBigNested.payload.id = 5;
storageBigNested.payload.code = 6;
storageBigNested.payload.note = "xy";
storageBigNested.payload.fixedArr[0] = 21;
storageBigNested.payload.fixedArr[1] = 22;
storageBigNested.payload.dynArr.push(31);
storageBigNested.payload.dynArr.push(32);
storageBigNested.extra = 200;
}

function mem_big(Big memory s) public pure returns (bytes memory) {
Expand All @@ -71,6 +95,18 @@ contract C {
return abi.encode(s);
}

function enc_struct(S[2] calldata x) public pure returns (bytes memory) {
return abi.encode(x);
}

function storage_big() public view returns (bytes memory) {
return abi.encode(storageBig);
}

function storage_big_nested() public view returns (bytes memory) {
return abi.encode(storageBigNested);
}

function storage_flat() public view returns (bytes memory) {
return abi.encode(storageFlat);
}
Expand All @@ -92,6 +128,9 @@ contract C {
// cd_big((uint256,uint256,string,uint256[2],uint256[])): 0x20, 7, 8, 0xc0, 41, 42, 0x100, 3, "abc", 3, 11, 12, 13 -> 0x20, 0x1a0, 0x20, 7, 8, 0xc0, 41, 42, 0x100, 3, "abc", 3, 11, 12, 13
// mem_nested((uint256,(uint256,uint256,string,uint256[2],uint256[]),uint256)): 0x20, 100, 0x60, 200, 5, 6, 0xc0, 21, 22, 0x100, 2, "xy", 2, 31, 32 -> 0x20, 0x1e0, 0x20, 100, 0x60, 200, 5, 6, 0xc0, 21, 22, 0x100, 2, "xy", 2, 31, 32
// cd_nested((uint256,(uint256,uint256,string,uint256[2],uint256[]),uint256)): 0x20, 100, 0x60, 200, 5, 6, 0xc0, 21, 22, 0x100, 2, "xy", 2, 31, 32 -> 0x20, 0x1e0, 0x20, 100, 0x60, 200, 5, 6, 0xc0, 21, 22, 0x100, 2, "xy", 2, 31, 32
// enc_struct((uint256,uint256)[2]): 11, 22, 33, 44 -> 0x20, 0x80, 11, 22, 33, 44
// storage_big() -> 0x20, 0x1a0, 0x20, 7, 8, 0xc0, 41, 42, 0x100, 3, "abc", 3, 11, 12, 13
// storage_big_nested() -> 0x20, 0x1e0, 0x20, 100, 0x60, 200, 5, 6, 0xc0, 21, 22, 0x100, 2, "xy", 2, 31, 32
// storage_flat() -> 0x20, 0xc0, 0x20, 9, 10, 0x60, 4, "stor"
// storage_nested() -> 0x20, 288, 0x20, 0x64, 0x60, 300, 0xc9, 0xca, 0x60, 2, 47687202278368593055453199545051370742183790376672955679702151372887807754240
// storage_packed() -> 0x20, 0x80, 1, 2, 1, 3
Loading
Loading