Skip to content
Merged
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
24 changes: 24 additions & 0 deletions test/src/lib/LibMemoryKV.gasClaims.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ contract LibMemoryKVGasClaimsTest is Test {
}
}

/// `padMemory` leaves the free memory pointer where it found it, and the
/// order two measurements are taken in after it changes neither one. The
/// two measured are the most the tests here allocate after one pad: a
/// linear export and a walk export of a store with every list occupied.
/// Each costs the same measured first after a pad as measured second.
function testPadMemoryRewindsThePointerAndMeasurementOrderChangesNeither() public view {
MemoryKV kv = spreadStore(LibMemoryKV.LIST_COUNT);

uint256 start = Pointer.unwrap(LibPointer.allocatedMemoryPointer());
padMemory();
uint256 rewound = Pointer.unwrap(LibPointer.allocatedMemoryPointer());

uint256 linearFirst = linearGas(kv);
uint256 walkSecond = walkGas(kv);

padMemory();
uint256 walkFirst = walkGas(kv);
uint256 linearSecond = linearGas(kv);

assertEq(rewound, start, "the free pointer is back where it started");
assertEq(linearFirst, linearSecond, "the linear export measured first and second");
assertEq(walkFirst, walkSecond, "the walk export measured first and second");
}

/// Exporting one pair costs exactly the same whichever list it landed in.
/// The walk reaches every list through one mask step and one table lookup,
/// so no list is nearer or further than another.
Expand Down
Loading