Bird
Raised Fist0
Blockchain / Solidityprogramming~20 mins

Minimal proxy (clone) pattern in Blockchain / Solidity - Practice Problems & Coding Challenges

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
Challenge - 5 Problems
🎖️
Minimal Proxy Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of deploying a minimal proxy contract

Consider the following Solidity code snippet that deploys a minimal proxy contract using the create opcode. What will be the output of the deployProxy function?

Blockchain / Solidity
contract ProxyFactory {
    address public implementation;

    constructor(address _implementation) {
        implementation = _implementation;
    }

    function deployProxy() external returns (address proxy) {
        bytes20 targetBytes = bytes20(implementation);
        assembly {
            let clone := mload(0x40)
            mstore(clone, 0x3d602d80600a3d3981f3) // part 1
            mstore(add(clone, 0x14), shl(0x60, targetBytes)) // target address
            mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf3) // part 2
            proxy := create(0, clone, 0x37)
        }
        require(proxy != address(0), "Create failed");
    }
}
AReturns the address of the newly deployed minimal proxy contract
BReturns the address of the implementation contract
CReturns zero address (0x0000000000000000000000000000000000000000)
DReverts with "Create failed" error
Attempts:
2 left
💡 Hint

The create opcode returns the address of the new contract or zero on failure.

🧠 Conceptual
intermediate
1:30remaining
Purpose of the minimal proxy pattern

What is the main purpose of using the minimal proxy (clone) pattern in smart contract development?

ATo increase contract size for better security
BTo reduce gas costs by deploying lightweight proxy contracts that delegate calls to a shared implementation
CTo create multiple independent full copies of a contract with separate storage
DTo prevent any upgrades to the contract logic
Attempts:
2 left
💡 Hint

Think about how proxies save deployment costs by sharing code.

🔧 Debug
advanced
2:30remaining
Identify the error in this minimal proxy deployment code

Examine the following Solidity assembly snippet intended to deploy a minimal proxy. What error will occur when this code runs?

Blockchain / Solidity
assembly {
    let clone := mload(0x40)
    mstore(clone, 0x3d602d80600a3d3981f3)
    mstore(add(clone, 0x14), shl(0x60, implementation))
    mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf3)
    let proxy := create(0, clone, 0x36)
    if iszero(proxy) { revert(0, 0) }
}
AThe implementation address is not converted to bytes20, causing wrong memory layout
BThe revert call uses zero length, causing an invalid opcode error
CThe create call will fail because the code size is incorrect (0x36 instead of 0x37)
DThe mload(0x40) pointer is not updated after storing, causing memory corruption
Attempts:
2 left
💡 Hint

Check the length of the deployed code passed to create.

📝 Syntax
advanced
1:30remaining
Identify the syntax error in this minimal proxy factory function

Which option contains the syntax error in this Solidity function that deploys a minimal proxy?

Blockchain / Solidity
function clone(address implementation) external returns (address proxy) {
    bytes20 targetBytes = bytes20(implementation);
    assembly {
        let clone := mload(0x40)
        mstore(clone, 0x3d602d80600a3d3981f3)
        mstore(add(clone, 0x14), shl(0x60, targetBytes))
        mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf3)
        proxy := create(0, clone, 0x37)
    }
    require(proxy != address(0), "Create failed");
}
ANo syntax error; the code is correct
BIncorrect use of bytes20 conversion outside assembly
CUsing 'let' keyword outside assembly block
DMissing semicolon after assembly block
Attempts:
2 left
💡 Hint

Remember that let is only valid inside assembly blocks.

🚀 Application
expert
2:00remaining
Calculate the number of minimal proxies deployed

A factory contract deploys minimal proxy clones in a loop as follows:

for (uint i = 0; i < 5; i++) {
    deployProxy();
}

After this loop completes, how many minimal proxy contracts exist on the blockchain?

A5 proxies but all share the same address
B1 minimal proxy contract reused 5 times
C0, because the loop does not store the deployed addresses
D5 minimal proxy contracts, each with its own address
Attempts:
2 left
💡 Hint

Each call to deployProxy() creates a new contract.

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