Skip to main content
Try out the RareSkills ZK AI Tutor!
Book of Proxy Patterns and Delegatecall

The Fallback Extension Pattern

Last updated on Nov 12, 2026

The fallback-extension pattern is a simple way to circumvent the 24 KB smart contract size limit.

Suppose we have functions foo() and bar() in our primary contract and wish to add baz() but cannot due to a lack of space.

We add a fallback function to our primary smart contract that delegates unknown function calls to an extension contract similar to how a proxy works.

We put baz() in the extension contract. When we call baz() on the main contract, it will not match any of the function selectors in the primary contract, and thus trigger the fallback function. Then, baz() will be delegatecalled in the extension contract.

Ensuring an identical storage layout

For this pattern to work, both the primary contract and the extension contract need an identical storage layout. A simple way to accomplish this is to put all the storage variables (no exceptions!) into a single contract. Then both the primary contract and the extension contract inherit from that. Here is an example:

An image of a pattern

Changing the extension

In the example above, the address of the extension contract is stored in an immutable variable. We could add an additional storage variable to the storage contract which holds the address to the extension, then update the extension address when we want to change some of the functionality of the contract.

This approach is not recommended — if upgradeability is needed, then it’s better to use an established proxy pattern. Additionally, reading that extension address variable from storage will cost an extra 2,100 gas.

Care must be taken to avoid function selector collisions

There is an approximately 1 in 4 million chance two random functions will have the same selector. However, due to the birthday paradox, this probability increases rapidly when we have n function selectors and only one collision is needed to cause unwanted behavior. There are no tools for this, the developer must manually check the function selectors.

Gas Considerations

The extension itself can follow this pattern and send it to another delegate. In fact, there is no in principal limit to how many times we do this.

However, each “hop” adds an extra 2,600 gas (the minimum gas required to issue a CALL or DELEGATECALL to a new address), so the cost can be substantial if the chain is long.

Because functions in the extension cost an extra 2,600 gas, we want to put rarely-used functions in the extension, or functions that are intended to be mostly called from off-chain where gas doesn’t matter.

Use EIP 2930 in combination with this pattern

Using access list transactions with this pattern will save 100 gas when calling functions in the extension. In general, if an Ethereum transaction contains a cross-contract call or delegatecall, an access list transaction should be used.

Using a fallback-extension as an implementation contract for upgradeable proxies

This pattern can be used with regular proxies. That is, a proxy contract can delegate to an implementation contract which then delegates to an extension. Keep in mind that tooling for upgrades (like Openzeppelin upgrade tools) are not designed to work with the extension fallback pattern and might not catch upgrade related issues.

Learn More with RareSkills

Please see our Solidity Bootcamp to learn more.

Originally Published December 28, 2023

Related posts

7 min read

EIP-2930 - Ethereum access list

An Ethereum access list transaction enables saving gas on cross-contract calls by declaring in advance which contract and storage slots will be accessed.

Last updated onNov 12, 2026
Read Article

5 min read

Function Selector in Solidity: How It Is Computed

The function selector is the first 4 bytes of the keccak256 hash of a function signature. See how Solidity computes it, how to get it, and collision odds.

Last updated onNov 12, 2026
Read Article

9 min read

Solana Token-2022 and Token Extensions Explained

Token-2022 is the backward-compatible successor to Solana's SPL Token program, with built-in extensions. See how it works and build a token with extensions.

Last updated onNov 7, 2026
Read Article

10 min read

Introduction to Proxies

Proxy contracts enable smart contracts to retain their state while allowing their logic to be upgraded.

Last updated onNov 12, 2026
Read Article