From 0b17ad14b2967bbe9f99251c051001f6b021f8c0 Mon Sep 17 00:00:00 2001 From: Vectorized Date: Sun, 8 Jun 2025 11:07:55 +0000 Subject: [PATCH 1/3] Strengthen test --- test/LibSort.t.sol | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/LibSort.t.sol b/test/LibSort.t.sol index 46a32eb297..87eb83b262 100644 --- a/test/LibSort.t.sol +++ b/test/LibSort.t.sol @@ -1390,18 +1390,25 @@ contract LibSortTest is SoladyTest { } function testHasDuplicate(uint256[] memory a, uint256 r) public { + bytes32 aHash = keccak256(abi.encode(a)); if (r & 1 != 0) _brutalizeMemory(); if (r & 2 != 0) _misalignFreeMemoryPointer(); bool computed = LibSort.hasDuplicate(a); + _checkMemory(a); bool expected = _hasDuplicateOriginal(a); + _checkMemory(a); assertEq(computed, expected); + _checkMemory(a); + assertEq(keccak256(abi.encode(a)), aHash); if (r & 4 != 0) { if (a.length >= 2) { a[_randomUniform() % a.length] = a[_randomUniform() % a.length]; + aHash = keccak256(abi.encode(a)); } computed = LibSort.hasDuplicate(a); expected = _hasDuplicateOriginal(a); assertEq(computed, expected); + assertEq(keccak256(abi.encode(a)), aHash); } } From 22f2ce7aeccd5e462c32eca874d719b1ee665d67 Mon Sep 17 00:00:00 2001 From: Vectorized Date: Sun, 8 Jun 2025 11:10:14 +0000 Subject: [PATCH 2/3] T --- test/LibSort.t.sol | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/LibSort.t.sol b/test/LibSort.t.sol index 87eb83b262..c05b1d11a9 100644 --- a/test/LibSort.t.sol +++ b/test/LibSort.t.sol @@ -1412,8 +1412,10 @@ contract LibSortTest is SoladyTest { } } - function testHasDuplicate(bytes32) public { - testHasDuplicate(_randomUints(_randomArrayLength()), _randomUniform()); + function testHasDuplicate(bytes32 x) public { + uint256[] memory a; + if (uint256(x) & 0xf > 0) a = _randomUints(_randomArrayLength()); + testHasDuplicate(a, _randomUniform()); } function _hasDuplicateOriginal(uint256[] memory a) internal pure returns (bool) { From ad272cc4b4d484145ce493e28814317191708c1b Mon Sep 17 00:00:00 2001 From: Vectorized Date: Sun, 8 Jun 2025 11:11:32 +0000 Subject: [PATCH 3/3] T --- test/LibSort.t.sol | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/LibSort.t.sol b/test/LibSort.t.sol index c05b1d11a9..14ea5c31be 100644 --- a/test/LibSort.t.sol +++ b/test/LibSort.t.sol @@ -1412,9 +1412,11 @@ contract LibSortTest is SoladyTest { } } - function testHasDuplicate(bytes32 x) public { + function testHasDuplicate(uint256 r) public { uint256[] memory a; - if (uint256(x) & 0xf > 0) a = _randomUints(_randomArrayLength()); + if (r & 1 != 0) _brutalizeMemory(); + if (r & 2 != 0) _misalignFreeMemoryPointer(); + if (r & 0xff00 != 0) a = _randomUints(_randomArrayLength()); testHasDuplicate(a, _randomUniform()); }