Bird
Raised Fist0
Blockchain / Solidityprogramming~10 mins

Minimal proxy (clone) pattern in Blockchain / Solidity - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Concept Flow - Minimal proxy (clone) pattern
Deploy Implementation Contract
Deploy Minimal Proxy Contract
Proxy forwards calls
Delegatecall to Implementation
Return result to caller
End
The minimal proxy pattern deploys a small proxy contract that forwards calls to a shared implementation contract using delegatecall.
Execution Sample
Blockchain / Solidity
contract Implementation {
    uint public value;
    function setValue(uint _value) external {
        value = _value;
    }
}

// Minimal Proxy forwards calls to Implementation
This code shows a simple implementation contract with a setter, and a minimal proxy that forwards calls to it.
Execution Table
StepActionContractCall DataDelegatecall TargetState ChangeOutput
1Deploy ImplementationImplementation--Implementation code stored-
2Deploy Minimal ProxyProxy-Implementation addressProxy code stored with target address-
3Call setValue(42)ProxysetValue(42)Delegatecall to ImplementationProxy storage value set to 42-
4Read valueProxyvalue()Delegatecall to ImplementationNo state change42
5Call unknown functionProxyunknown()Delegatecall to ImplementationNo state changeFallback or error
6End----Execution complete
💡 Execution stops after calls are forwarded and results returned by delegatecall.
Variable Tracker
VariableStartAfter Step 3After Step 4Final
value (in Proxy storage)0424242
Implementation codeDeployedDeployedDeployedDeployed
Proxy codeDeployedDeployedDeployedDeployed
Key Moments - 3 Insights
Why does the proxy's storage change even though the code runs in the implementation?
Because delegatecall runs the implementation code in the proxy's context, so storage changes affect the proxy contract (see Step 3 in execution_table).
What happens if the proxy receives a call to a function not in the implementation?
The call is forwarded via delegatecall; if the implementation has no matching function, it triggers fallback or error (see Step 5).
Why deploy a minimal proxy instead of multiple full contracts?
Minimal proxies save gas by sharing one implementation contract and only storing a small forwarding code (see Steps 1 and 2).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what value does the proxy's storage variable 'value' have after Step 3?
A42
B0
CUndefined
DImplementation's value
💡 Hint
Check the 'State Change' column in Step 3 and variable_tracker for 'value'.
At which step does the proxy forward a call to the implementation contract?
AStep 1
BStep 2
CStep 3
DStep 6
💡 Hint
Look for 'Delegatecall to Implementation' in the 'Delegatecall Target' column.
If the implementation contract is upgraded, how does it affect the proxy's behavior?
AProxy forwards calls to new implementation address
BProxy still forwards calls to old implementation address
CProxy code changes automatically
DProxy stops working
💡 Hint
Minimal proxies store the implementation address at deployment (see Step 2), so changing implementation requires deploying new proxies.
Concept Snapshot
Minimal proxy pattern deploys a small proxy contract that forwards calls via delegatecall to a shared implementation.
Proxy storage is used, but code runs in implementation.
Saves gas by reusing code.
Calls unknown to proxy are forwarded.
State changes affect proxy storage.
Implementation upgrades require new proxies.
Full Transcript
The minimal proxy pattern involves deploying one implementation contract with full logic. Then, small proxy contracts are deployed that forward calls to this implementation using delegatecall. Delegatecall runs the implementation code but uses the proxy's storage, so state changes affect the proxy contract. This saves gas because proxies are minimal and share one implementation. When a call is made to the proxy, it forwards the call data to the implementation. If the function exists, it executes and updates proxy storage. If not, fallback or error occurs. Upgrading the implementation requires deploying new proxies pointing to the new implementation address.

Practice

(1/5)
1. What is the main purpose of the Minimal proxy (clone) pattern in blockchain development?
easy
A. To replace the original contract with a new one
B. To increase the size of deployed contracts
C. To create cheap copies of contracts by forwarding calls
D. To store large amounts of data on-chain

Solution

  1. Step 1: Understand the pattern's goal

    The minimal proxy pattern is designed to save gas and storage by creating lightweight copies of a contract.
  2. Step 2: Identify the correct purpose

    It achieves this by forwarding calls to the original contract instead of duplicating all code.
  3. Final Answer:

    To create cheap copies of contracts by forwarding calls -> Option C
  4. Quick Check:

    Minimal proxy pattern = cheap contract copies [OK]
Hint: Minimal proxy means cheap clones forwarding calls [OK]
Common Mistakes:
  • Thinking it increases contract size
  • Confusing it with data storage methods
  • Assuming it replaces original contracts
2. Which of the following Solidity code snippets correctly declares a minimal proxy clone using the create opcode?
easy
A. address clone = create(0, bytecode, bytecode.length);
B. address clone = new Contract();
C. address clone = create2(0, bytecode, bytecode.length);
D. address clone = delegatecall(bytecode);

Solution

  1. Step 1: Identify the correct opcode for minimal proxy creation

    The create opcode is used to deploy a new contract with given bytecode.
  2. Step 2: Match the syntax

    The syntax create(0, bytecode, bytecode.length) correctly uses create with zero value and bytecode parameters.
  3. Final Answer:

    address clone = create(0, bytecode, bytecode.length); -> Option A
  4. Quick Check:

    Minimal proxy uses create opcode like address clone = create(0, bytecode, bytecode.length); [OK]
Hint: Minimal proxy uses create, not new or delegatecall [OK]
Common Mistakes:
  • Using new keyword which deploys full contract
  • Confusing create2 with create
  • Using delegatecall which does not deploy
3. Given the following Solidity code snippet for deploying a minimal proxy clone, what will be the output of clone.owner() if the original contract's owner is set to address 0x1234...?
address clone = Clones.clone(original);
// original.owner() returns 0x1234...
// clone forwards calls to original
medium
A. 0x1234... (same owner as original)
B. 0x0000... (zero address)
C. Revert error due to missing owner variable
D. Address of the clone contract

Solution

  1. Step 1: Understand call forwarding in minimal proxy

    The clone forwards calls to the original contract, but storage is separate, so state variables like owner are not shared.
  2. Step 2: Determine owner value returned

    Since owner() reads from the clone's storage which is uninitialized, it returns 0x0000... (zero address).
  3. Final Answer:

    0x0000... (zero address) -> Option B
  4. Quick Check:

    Clone forwards calls but has separate storage, owner = zero address [OK]
Hint: Clone has separate storage, owner defaults to zero [OK]
Common Mistakes:
  • Assuming clone shares storage with original
  • Expecting original owner to be returned
  • Thinking clone address is returned
4. Identify the error in this minimal proxy deployment code snippet:
function clone(address implementation) external returns (address instance) {
    bytes20 targetBytes = bytes20(implementation);
    assembly {
        let clone_code := mload(0x40)
        mstore(clone_code, 0x3d602d80600a3d3981f3)
        mstore(add(clone_code, 0x14), targetBytes)
        instance := create(0, clone_code, 0x37)
    }
    require(instance != address(0), "Create failed");
}
medium
A. No error, code is correct
B. Missing delegatecall opcode in assembly
C. Using bytes20 instead of bytes32 for target address
D. Incorrect length passed to create (0x37 instead of 0x2d)

Solution

  1. Step 1: Check the length parameter for create

    The minimal proxy bytecode length is typically 0x2d (45 bytes), but 0x37 (55 bytes) is passed incorrectly.
  2. Step 2: Understand impact of wrong length

    Passing wrong length causes deployment of invalid bytecode, leading to failure or unexpected behavior.
  3. Final Answer:

    Incorrect length passed to create (0x37 instead of 0x2d) -> Option D
  4. Quick Check:

    Create length must match bytecode size [OK]
Hint: Check create length matches bytecode size [OK]
Common Mistakes:
  • Ignoring bytecode length mismatch
  • Confusing bytes20 and bytes32 usage
  • Assuming delegatecall needed in deployment
5. You want to deploy 1000 instances of a contract cheaply using the minimal proxy pattern. Which approach best reduces gas and storage costs while allowing each clone to have its own owner?
hard
A. Use minimal proxies forwarding to one implementation and store owner in each clone's storage
B. Deploy 1000 full contracts separately with unique owners
C. Use minimal proxies forwarding to one implementation and store owner in the implementation contract
D. Deploy one contract and share the same owner for all clones

Solution

  1. Step 1: Understand minimal proxy benefits

    Minimal proxies save gas by sharing code but have separate storage for each clone.
  2. Step 2: Assign unique owners per clone

    Storing owner in each clone's storage allows unique ownership while sharing logic.
  3. Step 3: Evaluate options

    Use minimal proxies forwarding to one implementation and store owner in each clone's storage uses minimal proxies with per-clone storage, reducing gas and allowing unique owners.
  4. Final Answer:

    Use minimal proxies forwarding to one implementation and store owner in each clone's storage -> Option A
  5. Quick Check:

    Minimal proxy + per-clone storage = cheap unique owners [OK]
Hint: Store owner in clone storage, share code via proxy [OK]
Common Mistakes:
  • Storing owner only in implementation (shared state)
  • Deploying full contracts wastes gas
  • Sharing one owner for all clones