Skip to content

feat(Arrays): add uniquifySorted for value arrays#6571

Open
knoal wants to merge 2 commits into
OpenZeppelin:masterfrom
knoal:feat/arrays-uniquify-sorted-5520
Open

feat(Arrays): add uniquifySorted for value arrays#6571
knoal wants to merge 2 commits into
OpenZeppelin:masterfrom
knoal:feat/arrays-uniquify-sorted-5520

Conversation

@knoal

@knoal knoal commented Jun 1, 2026

Copy link
Copy Markdown

Summary

  • add Arrays.uniquifySorted for uint256[], address[], and bytes32[] memory arrays
  • deduplicate sorted arrays in place by compacting unique runs and shrinking the memory array length
  • cover the new helper in the JS and Foundry Arrays test suites

Motivation

Closes #5520.

This pairs naturally with Arrays.sort() for consumers that need to sort short arrays and then remove duplicates without allocating a second result array.

Testing

  • npx hardhat test test/utils/Arrays.test.js
  • ~/.foundry/bin/forge test --match-path test/utils/Arrays.t.sol

@knoal knoal requested a review from a team as a code owner June 1, 2026 00:57
@changeset-bot

changeset-bot Bot commented Jun 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ce08bae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openzeppelin-solidity Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dc02566d-96f8-4516-8840-553b25f89173

📥 Commits

Reviewing files that changed from the base of the PR and between 74edc4b and 4319204.

📒 Files selected for processing (5)
  • contracts/mocks/ArraysMock.sol
  • contracts/utils/Arrays.sol
  • scripts/generate/templates/Arrays.js
  • test/utils/Arrays.t.sol
  • test/utils/Arrays.test.js

Walkthrough

This PR adds uniquifySorted to the Arrays utility library to deduplicate sorted arrays in-place. The implementation includes three type-specific overloads for uint256[], address[], and bytes32[] that remove consecutive duplicates by compacting elements with a read/write index and truncating the array length. A code generation template maintains the implementations, mock contracts expose the functions for testing, and comprehensive property-based Solidity and hardcoded JavaScript tests validate correctness across edge cases.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(Arrays): add uniquifySorted for value arrays' accurately describes the main change - adding the uniquifySorted function to the Arrays library for multiple value types.
Description check ✅ Passed The description clearly explains the purpose, changes made, testing approach, and motivation, directly relating to the changeset implementation of uniquifySorted.
Linked Issues check ✅ Passed The PR successfully implements the requirements from issue #5520: adds Arrays.uniquifySorted for uint256, address, and bytes32; enables in-place deduplication of sorted arrays; and provides comprehensive test coverage in both JS and Foundry test suites.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the objective of adding uniquifySorted functionality - no out-of-scope modifications were introduced in the implementation, templates, mocks, or tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Array.uniquifySorted to the Arrays library

1 participant