Skip to content

Add fetchCloneArgs variants that read a slice of the immutable args - #6626

Open
Amxx wants to merge 3 commits into
masterfrom
clones-fetch-args-slice
Open

Amxx wants to merge 3 commits into
masterfrom
clones-fetch-args-slice

Conversation

@Amxx

@Amxx Amxx commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Adds two overloads of Clones.fetchCloneArgs that read only part of the immutable args attached to a clone, avoiding allocation/copy of the full array when only a portion is needed:

  • fetchCloneArgs(address instance, uint256 start) — copies from start (included) to the end.
  • fetchCloneArgs(address instance, uint256 start, uint256 length) — copies at most length bytes starting at start.

Out-of-range arguments are truncated to the length of the immutable args (the returned array may be shorter than requested, or empty), matching the capping semantics of Bytes.slice/Bytes.splice rather than reverting. The existing fetchCloneArgs(address) is refactored to delegate to the new slicing overload, so all three share a single implementation.

PR Checklist

  • Tests (Hardhat + Foundry fuzz, covering in-range and truncated reads)
  • Documentation (NatSpec)
  • Changeset entry

@Amxx
Amxx requested a review from a team as a code owner July 22, 2026 13:03
Copilot AI review requested due to automatic review settings July 22, 2026 13:03
@changeset-bot

changeset-bot Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d45215b

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the Clones library with two new fetchCloneArgs overloads that return a slice of the immutable args appended to a clone’s runtime code, allowing callers to avoid allocating/copying the full args when only a subset is needed.

Changes:

  • Added Clones.fetchCloneArgs(address,uint256) (slice from start to end) and Clones.fetchCloneArgs(address,uint256,uint256) (slice of at most length bytes from start), with truncation semantics instead of reverting on out-of-range.
  • Refactored the existing fetchCloneArgs(address) implementation to delegate to the new slicing overload for a single shared implementation.
  • Added Hardhat + Foundry coverage for in-range slicing and truncation behavior, and introduced a changeset entry for the new API.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
contracts/proxy/Clones.sol Adds the two slicing overloads and refactors the original fetchCloneArgs(address) to reuse the shared slicing implementation.
test/proxy/Clones.test.js Updates overload invocation syntax and adds tests covering slice reads, “slice to end”, and truncation behavior.
test/proxy/Clones.t.sol Adds fuzz tests validating truncation semantics for both new overloads.
.changeset/clones-fetch-slice.md Documents the new overloads as a minor change in the release notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Clones.fetchCloneArgs now provides full, bounded, and start-to-end immutable-argument retrieval. Slice offsets and lengths are constrained to the available argument bytes before copying. Solidity and JavaScript tests cover normal slices, truncation, out-of-range starts, and overloaded calls. A minor Changesets entry documents the new variants.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: new fetchCloneArgs variants for slicing immutable args.
Description check ✅ Passed The description directly matches the changeset by explaining the new overloads, truncation semantics, tests, and docs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch clones-fetch-args-slice

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/proxy/Clones.t.sol`:
- Around line 88-90: Update both fuzz-test assumptions surrounding
Clones.cloneDeterministicWithImmutableArgs to bound args.length by the
deployable 0x5fd3 maximum instead of 0xbfd3, ensuring generated inputs cannot
cause deployment to revert before the slice assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1d58fdca-c2fe-41a8-9008-b854e9ba28ff

📥 Commits

Reviewing files that changed from the base of the PR and between b4f9524 and f920335.

📒 Files selected for processing (4)
  • .changeset/clones-fetch-slice.md
  • contracts/proxy/Clones.sol
  • test/proxy/Clones.t.sol
  • test/proxy/Clones.test.js

Comment thread test/proxy/Clones.t.sol
Copilot AI review requested due to automatic review settings July 22, 2026 13:17
@Amxx
Amxx force-pushed the clones-fetch-args-slice branch from f920335 to 6c04982 Compare July 22, 2026 13:17
@Amxx
Amxx requested a review from arr00 July 22, 2026 13:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread test/proxy/Clones.t.sol
Comment thread test/proxy/Clones.t.sol
Copilot AI review requested due to automatic review settings July 22, 2026 13:22
@Amxx Amxx added this to the 5.8 milestone Jul 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

test/proxy/Clones.t.sol:88

  • The clone helpers revert with CloneArgumentsTooLong() when args.length > 0x5fd3 (see Clones._cloneCodeWithImmutableArgs). Using 0xbfd3 here doesn't exclude those reverting cases and can make the fuzz test fragile if Foundry’s generated bytes lengths increase in the future. Consider constraining the assume to the actual maximum supported args length.
        vm.assume(args.length < 0xbfd3);

test/proxy/Clones.t.sol:104

  • Same as above: Clones reverts for args.length > 0x5fd3, so the fuzz precondition should cap to that limit to avoid generating reverting deployments.
        vm.assume(args.length < 0xbfd3);

Comment thread contracts/proxy/Clones.sol Outdated
Comment thread contracts/proxy/Clones.sol

This branch has not been deployed

No deployments
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.

4 participants