Skip to content

Conversation

ernestognw
Copy link
Member

Fixes #????

PR Checklist

  • Tests
  • Documentation
  • Changeset entry (run npx changeset add)

@ernestognw ernestognw requested a review from a team as a code owner October 15, 2025 23:28
Copy link

changeset-bot bot commented Oct 15, 2025

🦋 Changeset detected

Latest commit: 6a571ca

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

Copy link

coderabbitai bot commented Oct 15, 2025

Walkthrough

The PR adds in-place splice-with-replacement functionality. In Arrays.sol, internal overloads for address[], bytes32[], and uint256[] support splice(array, replacement) and splice(array, start, replacement), performing sanitized bounds and memory copy. In Bytes.sol, new internal functions splice(bytes, bytes) and splice(bytes, uint256, bytes) replace segments within a buffer with truncation as needed. Script templates (Arrays.js) are updated to generate these overloads. Comprehensive Solidity and JavaScript tests are added for Arrays and Bytes. Changeset entries document the minor OpenZeppelin upgrade and the new splice variants.

Possibly related PRs

Suggested labels

ignore-changeset

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description Check ❓ Inconclusive The pull request description consists solely of a template scaffold with no substantive details about the actual changes or context, making it too generic to convey any meaningful information about the patch. Please update the pull request description to include a concise summary of the changes, their purpose, and any relevant context or issue numbers to help reviewers understand the PR at a glance.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly describes the primary change introduced by the pull request, namely the addition of a new splice variant that replaces a portion of the input array or buffer, and it does so concisely and specifically without extraneous details.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
contracts/utils/Bytes.sol (1)

131-139: Documentation may mislead users about behavior.

The NatSpec comment states this "replicates the behavior of Javascript's Array.splice", but JavaScript's Array.splice can insert/delete elements and change array length. This implementation only replaces elements in-place without changing the buffer length, which is a more limited behavior. Consider clarifying the documentation to explicitly state that the buffer length remains unchanged and replacement is truncated to fit.

Apply this diff to clarify the documentation:

     /**
-     * @dev Replaces the content of `buffer` with the content of `replacement`. The replacement is truncated to fit within the bounds of the buffer.
+     * @dev Replaces the content of `buffer` with the content of `replacement` starting at position 0. 
+     * The buffer length remains unchanged, and the replacement is truncated to fit within the buffer bounds.
      *
      * NOTE: This function modifies the provided buffer in place. If you need to preserve the original buffer, use {slice} instead
-     * NOTE: replicates the behavior of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice[Javascript's `Array.splice`]
+     * NOTE: Similar to Javascript's `Array.splice` but with fixed-length, in-place semantics
      */
test/utils/Bytes.test.js (1)

94-94: Document explicit uint256 casts for overload resolution

The use of ethers.Typed.uint256(start/end) is applied consistently across indexOf, lastIndexOf, slice, and splice tests to disambiguate overloads—add a note in the PR description explaining this requirement.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1cf1377 and 6a571ca.

📒 Files selected for processing (9)
  • .changeset/fluffy-facts-brake.md (1 hunks)
  • .changeset/forty-ads-design.md (1 hunks)
  • contracts/utils/Arrays.sol (3 hunks)
  • contracts/utils/Bytes.sol (1 hunks)
  • scripts/generate/templates/Arrays.js (1 hunks)
  • test/utils/Arrays.t.sol (1 hunks)
  • test/utils/Arrays.test.js (1 hunks)
  • test/utils/Bytes.t.sol (1 hunks)
  • test/utils/Bytes.test.js (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
test/utils/Arrays.test.js (1)
test/helpers/random.js (1)
  • generators (3-10)
test/utils/Bytes.test.js (1)
test/utils/Arrays.test.js (27)
  • start (187-187)
  • start (195-195)
  • start (214-214)
  • start (312-312)
  • start (322-322)
  • start (332-332)
  • start (342-342)
  • start (348-348)
  • start (362-362)
  • start (383-383)
  • replacement (238-238)
  • replacement (299-299)
  • replacement (308-308)
  • longReplacement (253-253)
  • longReplacement (347-347)
  • longReplacement (370-370)
  • shortReplacement (265-265)
  • emptyReplacement (276-276)
  • emptyReplacement (361-361)
  • sameSize (283-283)
  • copyLength (243-243)
  • copyLength (255-255)
  • copyLength (314-314)
  • copyLength (324-324)
  • copyLength (334-334)
  • copyLength (350-350)
  • copyLength (372-372)
🪛 LanguageTool
.changeset/forty-ads-design.md

[grammar] ~5-~5: There might be a mistake here.
Context: ... fits within the original buffer bounds.

(QB_NEW_EN)

.changeset/fluffy-facts-brake.md

[grammar] ~5-~5: There might be a mistake here.
Context: ...ace array modification with new content.

(QB_NEW_EN)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: tests
  • GitHub Check: slither
  • GitHub Check: tests-foundry
  • GitHub Check: coverage
  • GitHub Check: tests-upgradeable
  • GitHub Check: halmos
🔇 Additional comments (4)
contracts/utils/Bytes.sol (1)

148-159: LGTM! Boundary handling is correct.

The implementation properly sanitizes start and computes copyLength to prevent buffer overflow. The mcopy operation is memory-safe and correctly handles all edge cases including empty buffers, empty replacements, and out-of-bounds start positions.

test/utils/Bytes.test.js (1)

115-281: Excellent test coverage for the new splice variants.

The test suites comprehensively cover edge cases including:

  • Replacements longer/shorter than buffer
  • Empty replacements and empty buffers
  • Boundary conditions (start at 0, middle, end, out-of-bounds)
  • Single-byte operations

The expected value computation using Uint8Array operations correctly mirrors the Solidity implementation's truncation behavior.

test/utils/Bytes.t.sol (1)

158-210: LGTM! Comprehensive fuzz tests for splice-with-replacement.

The two new test functions properly verify:

  • In-place modification semantics (same object returned)
  • Buffer length preservation
  • Correct sanitization of start position
  • Accurate copying of replacement content
  • Preservation of unchanged content before and after the replacement region

The tests follow the established pattern in the file and provide strong property-based validation through fuzzing.

test/utils/Arrays.t.sol (1)

185-366: LGTM! Comprehensive test coverage for all array types.

The new test functions provide thorough validation of splice-with-replacement for address[], bytes32[], and uint256[] arrays. Each test suite properly verifies:

  • In-place modification
  • Length preservation
  • Sanitized bounds
  • Correct replacement content
  • Unchanged content outside the replacement region

The tests follow consistent patterns and provide strong fuzz-based validation across all supported array element types.

@ernestognw ernestognw added this to the 5.6 milestone Oct 15, 2025
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.

1 participant