-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): test memory corruption in dynamic-to-static array conversi…
…on (#1880)
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,28 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.21; | ||
|
||
import { MudTest } from "@latticexyz/world/test/MudTest.t.sol"; | ||
|
||
import { toStaticArray_uint256_2 } from "../src/codegen/tables/StaticArray.sol"; | ||
|
||
contract StaticArrayTest is MudTest { | ||
uint256 internal memoryCorruptionCheck = uint256(keccak256("memoryCorruptionCheck")); | ||
|
||
function testMemoryCorruption() public { | ||
uint256[] memory data = new uint256[](3); | ||
data[0] = 1; | ||
data[1] = 2; | ||
data[2] = memoryCorruptionCheck; | ||
|
||
uint256[2] memory result = toStaticArray_uint256_2(data); | ||
assertEq(result[0], 0); | ||
assertEq(result[1], 0); | ||
|
||
uint256 memoryAfterResult; | ||
assembly { | ||
memoryAfterResult := mload(add(result, 0x40)) | ||
mstore(0x40, add(mload(0x40), 0x20)) | ||
} | ||
assertNotEq(memoryAfterResult, memoryCorruptionCheck); | ||
} | ||
} |