Skip to content

HybridProxy: handle implementations with a non-reverting fallback - #323

Open
debojyoti10CC wants to merge 1 commit into
OpenZeppelin:masterfrom
debojyoti10CC:fix/hybrid-proxy-fallback
Open

debojyoti10CC wants to merge 1 commit into
OpenZeppelin:masterfrom
debojyoti10CC:fix/hybrid-proxy-fallback

Conversation

@debojyoti10CC

@debojyoti10CC debojyoti10CC commented Nov 16, 2026 •

Copy link
Copy Markdown

Fixes #320

What's wrong

HybridProxy._implementation() uses try/catch to work out whether the implementation slot holds a beacon. The catch is that try/catch only handles reverts from the call itself. It doesn't cover failures to decode the return data.

So if the implementation has a fallback that doesn't revert (e.g. fallback() external payable {}), the implementation() call succeeds and returns no data. Decoding that empty data then reverts inside the proxy, and every call to the proxy fails, including upgradeToAndCall. Once a proxy is upgraded to an implementation like that, there's no way back, and any funds it holds are stuck.

The fix

I replaced the try/catch with a low-level staticcall. The proxy now treats the implementation as a beacon only when the call succeeds and returns at least 32 bytes that decode to a valid address. In every other case it falls back to using the implementation directly, which matches the existing behaviour for implementations that revert.

Testing

I added a small UpgradeableImplementationWithFallbackMock and a test that:

  1. upgrades the proxy to an implementation with a non-reverting fallback,
  2. checks that calls through the proxy still work,
  3. upgrades back to the beacon to confirm the proxy can still be upgraded.

Without the fix, the test fails with function returned an unexpected amount of data. With it, the full HybridProxy suite passes.

🤖 Generated with Claude Code

`try`/`catch` does not catch failures to decode the return data of a
successful call. If the implementation had a fallback that returns less
than 32 bytes, `IBeacon(implementation).implementation()` succeeded with
empty data, decoding reverted, and every call to the proxy reverted,
including `upgradeToAndCall`. The proxy could not be recovered.

Use a low-level `staticcall` and treat the implementation as a beacon only
when the call succeeds and returns a valid address.

Fixes OpenZeppelin#320

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@debojyoti10CC
debojyoti10CC requested a review from a team as a code owner November 16, 2026 18:22
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c90db5a3-e4a2-4c2c-819f-1734ac296ba1
Commits

Reviewing files that changed from the base of the PR and between 13921f5 and 6553d15.

Files selected for processing: 4

  • CHANGELOG.md
  • contracts/mocks/UpgradeableImplementation.sol
  • contracts/proxy/HybridProxy.sol
  • test/proxy/HybridProxy.test.js
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@debojyoti10CC

Copy link
Copy Markdown
Author

Quick note: I used Claude Code to help write this fix and the test, but I went through it myself to make sure I understood it.

What I found interesting is that try/catch looks like it covers every failure, but it doesn’t. A call that succeeds and returns nothing still blows up when the proxy decodes the result. With a do-nothing fallback, that happens on every call, so the proxy can’t even be upgraded out of it.

One thing I wasn’t sure about: if an implementation’s fallback returns 32+ bytes that happen to look like an address, the proxy will still treat it as a beacon. That’s the same risk the existing IMPORTANT note describes, so I left it alone, but I can add a line to the NatSpec if you think it’s worth mentioning.

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.

HybridProxy: implementation with a non-reverting fallback bricks the proxy (try/catch does not catch return-data decoding)

1 participant