Repository navigation
HybridProxy: handle implementations with a non-reverting fallback - #323
debojyoti10CC wants to merge 1 commit into
Conversation
`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>
|
Warning Review limit reachedYou'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. View limit details
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. |
|
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. |
Fixes #320
What's wrong
HybridProxy._implementation()usestry/catchto work out whether the implementation slot holds a beacon. The catch is thattry/catchonly 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 {}), theimplementation()call succeeds and returns no data. Decoding that empty data then reverts inside the proxy, and every call to the proxy fails, includingupgradeToAndCall. 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/catchwith a low-levelstaticcall. 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
UpgradeableImplementationWithFallbackMockand a test that:Without the fix, the test fails with
function returned an unexpected amount of data. With it, the fullHybridProxysuite passes.🤖 Generated with Claude Code