fix: avoid quicksort stack overflow on worst-case inputs#6392
fix: avoid quicksort stack overflow on worst-case inputs#6392rajatbeladiya wants to merge 1 commit intoOpenZeppelin:masterfrom
Conversation
Rework Arrays._quickSort to recurse on the smaller partition and iterate over the larger partition, preventing deep recursion on already-sorted/reversed arrays. Add a regression test for uint256 arrays of length 256.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
WalkthroughThe pull request optimizes the 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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. Comment |
|
Duplicate of #6324 |
Reworks
Arrays._quickSortto recurse on the smaller partition and iterate over the larger partition. This prevents deep recursion on worst-case inputs (e.g., already-sorted/reversed arrays) which can otherwise lead to EVM stack overflow.Changes:
scripts/generate/templates/Arrays.js(Arrays.sol is generated).uint256[]of length 256 (including sorted + reversed cases).Tested:
npm run test:generationnpx hardhat test test/utils/Arrays.test.js --grep sortnpm run lint:solCloses #6289.