Add Memory utility library (#5189)

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com>
This commit is contained in:
Ernesto García
2025-07-10 01:15:27 -06:00
committed by GitHub
parent a5350ecdd3
commit 21cd7e8aa3
7 changed files with 146 additions and 1 deletions

21
test/utils/Memory.t.sol Normal file
View File

@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Test} from "forge-std/Test.sol";
import {Memory} from "@openzeppelin/contracts/utils/Memory.sol";
contract MemoryTest is Test {
using Memory for *;
// - first 0x80 bytes are reserved (scratch + FMP + zero)
uint256 constant START_PTR = 0x80;
// - moving the free memory pointer to far causes OOG errors
uint256 constant END_PTR = type(uint24).max;
function testGetsetFreeMemoryPointer(uint256 seed) public pure {
bytes32 ptr = bytes32(bound(seed, START_PTR, END_PTR));
ptr.asPointer().setFreeMemoryPointer();
assertEq(Memory.getFreeMemoryPointer().asBytes32(), ptr);
}
}