Skip to content

Build simulator from .yul source - #6799

Merged
james-toussaint merged 15 commits into
OpenZeppelin:masterfrom
james-toussaint:yul/call-simulator
Oct 15, 2026
Merged

james-toussaint merged 15 commits into
OpenZeppelin:masterfrom
james-toussaint:yul/call-simulator

Conversation

@james-toussaint

@james-toussaint james-toussaint commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

The call simulator used by SimulateCall was hand-written EVM bytecode, documented with an opcode table and pasted into both getSimulator() and the tests. This PR replaces it with a Yul source, contracts/utils/SimulateCall.yul, that is compiled as part of the regular build, and checks that the embedded bytecode matches it.

Changes

  • contracts/utils/SimulateCall.yul: new Yul source for the simulator (SimulationRelayer object). It forwards the call described by target[0x00:0x14] | value[0x14:0x34] | data[0x34:] and inverts the outcome: it reverts on success (undoing state changes) and returns on failure, forwarding the return data in both cases.
  • contracts/utils/SimulateCall.sol: getSimulator() embeds the initcode compiled from the Yul source. The opcode table is replaced by a pointer to the source.
  • hardhat/hardhat-yul: new Hardhat plugin. A solidity.build hook compiles every .yul file in the sources directories with the configured solc and emits regular Hardhat artifacts (e.g. contracts/utils/SimulateCall.yul:SimulationRelayer).
  • Tests: the simulator address is derived from the compiled artifact instead of a hardcoded bytecode string. A new test checks that the code deployed by getSimulator() equals the artifact's deployedBytecode, so the embedded bytecode can't drift from the source.
  • Slither: new slither Foundry profile that skips *.yul, used by the Slither CI job.

Behavior change

The simulator bytecode changes, so its CREATE2 address changes (changeset included). The new code is smaller: 47 bytes of initcode instead of 58, and 37 bytes of runtime instead of 49.

The explicit calldata length check is removed. Calldata shorter than 0x34 bytes is now undefined behavior, documented in the Yul source: the length computation underflows and calldatacopy runs out of gas. SimulateCall always sends well-formed calldata, so this only affects direct calls to the simulator.

@changeset-bot

changeset-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4a0cc67

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 Patch

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 Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 1be3f8e5-4ea2-4016-8434-2317a300189f

📥 Commits

Reviewing files that changed from the base of the PR and between 40a51f7 and 1726033.


📒 Files selected for processing (6)
  • contracts/utils/SimulateCall.sol
  • package.json
  • scripts/yul/CallSimulator.yul
  • scripts/yul/compile-yul.js
  • scripts/yul/yul-compile.js
  • test/utils/SimulatedCall.test.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.



Walkthrough

The simulator runtime now reads an encoded target, value, and call data, then calls the target with that value. It reverts with return data when the call succeeds and returns data when the call fails. The change adds Yul source and compilation scripts, embeds the resulting bytecode, and adds tests for deployed runtime and compiled bytecode.

Priority: ⬇️ Low

Change: Refactor

Merge Risk: ⚪ Minimal · up to 17260

No actionable issue is established. Merge readiness remains subject to the normal test run in an environment with Forge.

Pre-merge checks | Passed 3 | Failed 1 | Inconclusive 1

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. (3 skipped: 3… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check Inconclusive No pull request description was provided, so the description check cannot assess whether it relates to the changes. Add a brief description of the simulator build changes.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check Passed The title clearly and concisely describes the main change: building the simulator from Yul source. This matches the updated simulator implementation, Yul source, compilation tooling, and tests.

Full details: Docstring Coverage

Explanation

Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. (3 skipped: 3 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@james-toussaint
james-toussaint requested a review from Amxx October 5, 2026 14:57
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor
view gas comparison

Changes to gas costs

Contract Method Min (+/-) % Max (+/-) % Median (+/-) % Avg (+/-) %
$SimulateCall [constructor] - - - - - - - - - 319450 -2376 -0.74% ✔️
$SimulateCall $getSimulator 4194 0 0.00% ➖ 43667 -2400 -5.21% ✔️ 43667 +18536 +73.76% ❌ 30509 +5378 +21.40% ❌
$SimulateCall $simulateCall(address,bytes) 50673 -2422 -4.56% ✔️ 51898 -2422 -4.46% ✔️ 51286 -2422 -4.51% ✔️ 51286 -2422 -4.51% ✔️
$SimulateCall $simulateCall(address,uint256,bytes) 57495 -2422 -4.04% ✔️ 58295 -2422 -3.99% ✔️ 57895 -2422 -4.02% ✔️ 57895 -2422 -4.02% ✔️

james-toussaint and others added 7 commits October 5, 2026 18:53
Replace the build task override and compile-yul task with a solidity.build hook
that compiles .yul files found in the sources directories and emits regular
Hardhat artifacts, so tests can use artifacts.readArtifact('CallSimulator').

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Amxx

Amxx commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

@james-toussaint I pushed 05f1b90, which integrates the Yul plugin more directly into the Hardhat build:

  • The build task override and the compile-yul task are replaced by a solidity.build hook. It compiles every .yul file in the sources directories (or passed explicitly to hardhat build) and writes standard Hardhat artifacts to artifacts/<sourceName>/<ObjectName>.json.
  • artifacts-yul/ (and its .gitignore entry) is gone. The test now uses artifacts.readArtifact('CallSimulator') and derives the expected CREATE2 address and runtime code from the artifact, so the hardcoded bytecode constants and the separate sync test are removed.

The Foundry slither profile is unchanged, since that one is about Forge picking up .yul files.

@Amxx Amxx mentioned this pull request Oct 9, 2026
2 of 3 tasks
Amxx and others added 2 commits October 9, 2026 18:00
Hardhat's Solidity test runner requires every artifact in artifacts/ to have a
buildInfoId it can parse the solc version from. No build info file is written,
so EDR never sees a Yul build info.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The upgradeable build also compiles lib/openzeppelin-contracts/contracts/utils/CallSimulator.yul,
making the bare name ambiguous.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Yul source was rewritten in the previous commit but the initcode embedded
in getSimulator() still matched the old version, so the deployed simulator
landed at a different CREATE2 address than the compiled artifact predicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread contracts/utils/SimulateCall.yul Resolved
Comment thread contracts/utils/SimulateCall.yul Resolved
Amxx and others added 3 commits October 12, 2026 18:38
Short calldata is now documented as undefined behavior: the length computation
underflows and calldatacopy runs out of gas. Also inline datasize("runtime") in
the constructor (no bytecode change) and update the embedded initcode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Amxx
Amxx requested a review from ernestognw October 14, 2026 12:06
@james-toussaint
james-toussaint merged commit 598d390 into OpenZeppelin:master Oct 15, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants