0
0
Blockchain / Solidityprogramming~20 mins

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

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