solang
solang copied to clipboard
Solang loads vectors from storage incorrectly
contract Testing {
struct PaddedStruct {
uint128 a;
uint8 b;
bytes32 c;
}
PaddedStruct[2][3][] stor_arr;
function addData() public {
PaddedStruct memory a = PaddedStruct(56, 1, "oi");
PaddedStruct memory b = PaddedStruct(78, 6, "bc");
PaddedStruct memory c = PaddedStruct(89, 4, "sn");
PaddedStruct memory d = PaddedStruct(42, 56, "cn");
PaddedStruct memory e = PaddedStruct(23, 78, "fr");
PaddedStruct memory f = PaddedStruct(445, 46, "br");
PaddedStruct[2][3] memory vec = [[a, b], [c, d], [e, f]];
stor_arr.push(vec);
}
function getThis() public view returns (uint32) {
PaddedStruct[2][3][] memory arr2 = stor_arr;
return arr2.length;
}
}
Calling getThis after addData returns 6, instead it should return 1. If we modify stor_arr to PaddedStruct[2][2][] stor_arr and do all the necessary changes, addData returns 4. I think we are incorrectly merging the first two dimensions into one.
uint16[4][2][] simple_arr;
function multiDim() public returns (uint32) {
uint16[4][2] memory vec = [[uint16(1), 2, 3, 4], [uint16(5), 6, 7, 8]];
simple_arr.push(vec);
uint16[4][2][] memory mem_vec = simple_arr;
return mem_vec.length;
}
This returns 8 🤨