0
0
Blockchain / Solidityprogramming~10 mins

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

Choose your learning style9 modes available
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.