🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Advanced Solidity Patterns

Blockchain DevelopmentđŸŸĸ Free Lesson

Advanced Solidity Patterns

Overview

Advanced Solidity development requires understanding complex design patterns, low-level assembly, and optimization techniques that enable scalable and gas-efficient smart contracts.

âš ī¸

Advanced patterns introduce complexity. Always balance between pattern usage and code simplicity. Over-engineering can lead to bugs and higher maintenance costs.

Design Patterns Overview

Advanced Solidity PatternsDesignPatternsProxyFactoryRegistryDiamondObserverStrategyState MachineCommit-Reveal

Proxy Pattern

Transparent Proxy Implementation

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract TransparentProxy {
    address public admin;
    address public implementation;
    
    // Admin selector mapping for admin-only functions
    mapping(bytes4 => bool) public adminSelectors;
    
    // Events
    event Upgraded(address indexed implementation);
    event AdminChanged(address previousAdmin, address newAdmin);
    
    modifier ifAdmin() {
        if (msg.sender == admin) {
            _;
        } else {
            _fallback();
        }
    }
    
    constructor(address _implementation, address _admin) payable {
        admin = _admin;
        implementation = _implementation;
        
        // Set admin function selectors
        adminSelectors[this.upgrade.selector] = true;
        adminSelectors[this.changeAdmin.selector] = true;
    }
    
    fallback() external payable ifAdmin {
        // Delegate to implementation
        address impl = implementation;
        assembly {
            calldatacopy(0, 0, calldatasize())
            let result := delegatecall(gas(), impl, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch result
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }
    
    receive() external payable {}
    
    function upgrade(address newImplementation) external {
        require(msg.sender == admin, "Not admin");
        require(newImplementation != address(0), "Zero address");
        
        implementation = newImplementation;
        emit Upgraded(newImplementation);
    }
    
    function changeAdmin(address newAdmin) external {
        require(msg.sender == admin, "Not admin");
        require(newAdmin != address(0), "Zero address");
        
        emit AdminChanged(admin, newAdmin);
        admin = newAdmin;
    }
}

UUPS Proxy Pattern

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

abstract contract UUPSUpgradeable {
    address public _implementation;
    
    function upgradeTo(address newImplementation) public virtual {
        require(msg.sender == owner(), "Not authorized");
        
        _authorizeUpgrade(newImplementation);
        _setImplementation(newImplementation);
    }
    
    function _authorizeUpgrade(address) internal virtual {
        require(msg.sender == owner(), "Not authorized");
    }
    
    function _setImplementation(address newImplementation) internal {
        require(newImplementation != address(0), "Zero address");
        _implementation = newImplementation;
    }
    
    function _delegate(address implementation) internal {
        assembly {
            calldatacopy(0, 0, calldatasize())
            let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch result
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }
    
    function owner() public view virtual returns (address);
}

Proxy Pattern Comparison

PatternStorage LocationUpgrade ControlGas Overhead
Transparent ProxySeparate contractAdmin-onlyMedium (external call)
UUPSImplementationImplementationLow (self-contained)
BeaconShared beaconBeacon controllerMedium
DiamondShared facetsOwnerHigh (multiple calls)

Factory Pattern

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract TokenFactory {
    // Tracking created tokens
    address[] public createdTokens;
    mapping(address => bool) public isCreatedToken;
    
    // Token template
    struct TokenTemplate {
        string name;
        string symbol;
        uint8 decimals;
        uint256 initialSupply;
    }
    
    event TokenCreated(address tokenAddress, string name, string symbol);
    
    function createToken(
        string calldata name,
        string calldata symbol,
        uint8 decimals,
        uint256 initialSupply
    ) external returns (address) {
        // Deploy new token contract
        ERC20 token = new ERC20(name, symbol, decimals);
        
        // Mint initial supply to creator
        token.mint(msg.sender, initialSupply);
        
        // Track created token
        createdTokens.push(address(token));
        isCreatedToken[address(token)] = true;
        
        emit TokenCreated(address(token), name, symbol);
        
        return address(token);
    }
    
    // CREATE2 for deterministic addresses
    function createTokenDeterministic(
        string calldata name,
        string calldata symbol,
        uint8 decimals,
        uint256 initialSupply,
        bytes32 salt
    ) external returns (address) {
        bytes memory bytecode = abi.encodePacked(
            type(ERC20).creationCode,
            abi.encode(name, symbol, decimals)
        );
        
        address token;
        assembly {
            token := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
        }
        
        require(token != address(0), "Deployment failed");
        
        ERC20(token).mint(msg.sender, initialSupply);
        
        createdTokens.push(token);
        isCreatedToken[token] = true;
        
        emit TokenCreated(token, name, symbol);
        
        return token;
    }
    
    // Predict CREATE2 address
    function predictTokenAddress(
        string calldata name,
        string calldata symbol,
        uint8 decimals,
        bytes32 salt
    ) external view returns (address) {
        bytes memory bytecode = abi.encodePacked(
            type(ERC20).creationCode,
            abi.encode(name, symbol, decimals)
        );
        
        bytes32 bytecodeHash = keccak256(bytecode);
        
        return address(uint160(uint256(keccak256(abi.encodePacked(
            bytes1(0xff),
            address(this),
            salt,
            bytecodeHash
        )))));
    }
    
    function getTokenCount() external view returns (uint256) {
        return createdTokens.length;
    }
    
    function getTokens(uint256 start, uint256 count) external view returns (address[] memory) {
        uint256 end = start + count;
        if (end > createdTokens.length) {
            end = createdTokens.length;
        }
        
        address[] memory tokens = new address[](end - start);
        for (uint256 i = start; i < end; i++) {
            tokens[i - start] = createdTokens[i];
        }
        
        return tokens;
    }
}

Registry Pattern

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract ContractRegistry {
    // Registry storage
    mapping(bytes32 => address) private _contracts;
    mapping(address => bytes32) private _reverseRegistry;
    
    address public owner;
    
    event ContractRegistered(bytes32 indexed name, address indexed addr);
    event ContractRemoved(bytes32 indexed name);
    
    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }
    
    constructor() {
        owner = msg.sender;
    }
    
    // Register a contract
    function register(string calldata name, address addr) external onlyOwner {
        bytes32 nameHash = keccak256(abi.encodePacked(name));
        require(addr != address(0), "Zero address");
        require(_contracts[nameHash] == address(0), "Already registered");
        
        _contracts[nameHash] = addr;
        _reverseRegistry[addr] = nameHash;
        
        emit ContractRegistered(nameHash, addr);
    }
    
    // Update a contract
    function update(string calldata name, address newAddr) external onlyOwner {
        bytes32 nameHash = keccak256(abi.encodePacked(name));
        require(_contracts[nameHash] != address(0), "Not registered");
        require(newAddr != address(0), "Zero address");
        
        // Clean up old reverse registry
        address oldAddr = _contracts[nameHash];
        delete _reverseRegistry[oldAddr];
        
        _contracts[nameHash] = newAddr;
        _reverseRegistry[newAddr] = nameHash;
        
        emit ContractRegistered(nameHash, newAddr);
    }
    
    // Remove a contract
    function remove(string calldata name) external onlyOwner {
        bytes32 nameHash = keccak256(abi.encodePacked(name));
        address addr = _contracts[nameHash];
        require(addr != address(0), "Not registered");
        
        delete _contracts[nameHash];
        delete _reverseRegistry[addr];
        
        emit ContractRemoved(nameHash);
    }
    
    // Get a contract
    function getContract(string calldata name) external view returns (address) {
        bytes32 nameHash = keccak256(abi.encodePacked(name));
        address addr = _contracts[nameHash];
        require(addr != address(0), "Not registered");
        return addr;
    }
    
    // Check if contract is registered
    function isRegistered(string calldata name) external view returns (bool) {
        bytes32 nameHash = keccak256(abi.encodePacked(name));
        return _contracts[nameHash] != address(0);
    }
}

Diamond Pattern (EIP-2535)

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract Diamond {
    struct Facet {
        address facetAddress;
        bytes4[] functionSelectors;
    }
    
    struct FacetFunctionSelectors {
        bytes4[] facetFunctionSelectors;
        uint256 facetAddressPosition;
    }
    
    // Mapping from function selector to facet
    mapping(bytes4 => address) public selectorToFacet;
    
    // Facet addresses and their function selectors
    Facet[] public facets;
    
    // All function selectors
    bytes4[] public facetFunctionSelectors;
    
    // Mapping from selector to position in facetFunctionSelectors
    mapping(bytes4 => uint256) public selectorPosition;
    
    address public owner;
    
    event FacetAdded(address indexed facet, bytes4[] selectors);
    event FacetRemoved(address indexed facet);
    event FacetUpdated(address indexed facet, bytes4[] selectors);
    
    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }
    
    constructor(address _owner, Facet[] memory _facets) {
        owner = _owner;
        
        for (uint256 i = 0; i < _facets.length; i++) {
            _addFacet(_facets[i]);
        }
    }
    
    fallback() external payable {
        address facet = selectorToFacet[msg.sig];
        require(facet != address(0), "Function not found");
        
        assembly {
            calldatacopy(0, 0, calldatasize())
            let result := delegatecall(gas(), facet, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch result
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }
    
    receive() external payable {}
    
    function _addFacet(Facet memory _facet) internal {
        require(_facet.facetAddress != address(0), "Zero address");
        require(_facet.functionSelectors.length > 0, "No selectors");
        
        uint256 position = facets.length;
        facets.push(_facet);
        
        for (uint256 i = 0; i < _facet.functionSelectors.length; i++) {
            bytes4 selector = _facet.functionSelectors[i];
            require(selectorToFacet[selector] == address(0), "Selector exists");
            
            selectorToFacet[selector] = _facet.facetAddress;
            selectorPosition[selector] = facetFunctionSelectors.length;
            facetFunctionSelectors.push(selector);
        }
        
        emit FacetAdded(_facet.facetAddress, _facet.functionSelectors);
    }
    
    function addFacet(address _facetAddress, bytes4[] calldata _functionSelectors) external onlyOwner {
        require(_facetAddress != address(0), "Zero address");
        require(_functionSelectors.length > 0, "No selectors");
        
        for (uint256 i = 0; i < _functionSelectors.length; i++) {
            bytes4 selector = _functionSelectors[i];
            require(selectorToFacet[selector] == address(0), "Selector exists");
            
            selectorToFacet[selector] = _facetAddress;
            selectorPosition[selector] = facetFunctionSelectors.length;
            facetFunctionSelectors.push(selector);
        }
        
        emit FacetAdded(_facetAddress, _functionSelectors);
    }
    
    function replaceFacet(address _oldFacet, address _newFacet) external onlyOwner {
        require(_newFacet != address(0), "Zero address");
        require(_oldFacet != _newFacet, "Same address");
        
        for (uint256 i = 0; i < facetFunctionSelectors.length; i++) {
            if (selectorToFacet[facetFunctionSelectors[i]] == _oldFacet) {
                selectorToFacet[facetFunctionSelectors[i]] = _newFacet;
            }
        }
    }
    
    function removeFacet(address _facetAddress) external onlyOwner {
        require(_facetAddress != address(0), "Zero address");
        
        for (uint256 i = 0; i < facetFunctionSelectors.length; i++) {
            if (selectorToFacet[facetFunctionSelectors[i]] == _facetAddress) {
                delete selectorToFacet[facetFunctionSelectors[i]];
            }
        }
    }
}

Yul / Inline Assembly

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract YulExamples {
    // Gas-efficient array length
    function getArrayLength(uint256[] storage arr) public view returns (uint256) {
        assembly {
            mstore(0, arr.slot)
            let length := sload(keccak256(0, 32))
            mstore(0x20, length)
            return(0x20, 0x20)
        }
    }
    
    // Efficient storage access
    function packedStorage() public pure returns (uint256) {
        assembly {
            // Store multiple values in single slot
            let packed := 0
            packed := add(packed, shl(0, 1))      // First 8 bits
            packed := add(packed, shl(8, 2))      // Next 8 bits
            packed := add(packed, shl(16, 3))     // Next 8 bits
            packed := add(packed, shl(24, 4))     // Next 8 bits
            
            mstore(0, packed)
            return(0, 0x20)
        }
    }
    
    // Safe addition with overflow check
    function safeAdd(uint256 a, uint256 b) public pure returns (uint256) {
        assembly {
            let result := add(a, b)
            if lt(result, a) {
                revert(0, 0)
            }
            mstore(0, result)
            return(0, 0x20)
        }
    }
    
    // Hash computation
    function computeHash(bytes memory data) public pure returns (bytes32) {
        assembly {
            let dataLength := mload(data)
            let dataStart := add(data, 0x20)
            
            // Use keccak256 precompile
            let hash := keccak256(dataStart, dataLength)
            
            mstore(0, hash)
            return(0, 0x20)
        }
    }
    
    // Memory allocation
    function allocateMemory(uint256 size) public pure returns (bytes memory) {
        assembly {
            // Round up to next 32-byte boundary
            let paddedSize := and(add(size, 31), not(31))
            
            // Allocate memory
            let ptr := mload(0x40)
            mstore(ptr, size)
            
            // Update free memory pointer
            mstore(0x40, add(add(ptr, 0x20), paddedSize))
            
            mstore(0, ptr)
            return(0, 0x20)
        }
    }
    
    // Delegatecall
    function executeDelegatecall(address target, bytes memory data) public returns (bool, bytes memory) {
        assembly {
            let success := delegatecall(gas(), target, add(data, 0x20), mload(data), 0, 0)
            
            // Copy return data
            let returnDataSize := returndatasize()
            let returnData := mload(0x40)
            returndatacopy(returnData, 0, returnDataSize)
            
            // Update free memory pointer
            mstore(0x40, add(returnData, and(add(returnDataSize, 31), not(31))))
            
            // Return result
            mstore(0, success)
            mstore(0x20, returnDataSize)
            mstore(0x40, add(0x40, returnDataSize))
            return(0, 0x60)
        }
    }
}

Yul Gas Optimization

OperationSolidityYulSavings
Storage read2100 gas2100 gasNone
Memory alloc~50 gas~30 gas~40%
Array access~100 gas~50 gas~50%
Hash computation~30 gas~10 gas~67%

Storage Layout Optimization

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract StorageLayout {
    // BAD: Wasteful layout (5 slots)
    // bool a;      // Slot 0
    // uint256 b;   // Slot 1
    // bool c;      // Slot 2
    // uint256 d;   // Slot 3
    // bool e;      // Slot 4
    
    // GOOD: Optimized layout (2 slots)
    struct PackedStruct {
        uint128 value1;    // Slot 0: 128 bits
        uint128 value2;    // Slot 0: 128 bits (packed)
        uint64 counter1;   // Slot 1: 64 bits
        uint64 counter2;   // Slot 1: 64 bits (packed)
        bool flag1;        // Slot 1: 8 bits (packed)
        bool flag2;        // Slot 1: 8 bits (packed)
        bool flag3;        // Slot 1: 8 bits (packed)
        bool flag4;        // Slot 1: 8 bits (packed)
    }
    
    PackedStruct public packed;
    
    // Mapping layout
    mapping(address => uint256) public balances;  // Slot 2
    mapping(address => mapping(address => uint256)) public allowances;  // Slot 3
    
    // Dynamic array
    uint256[] public data;  // Slot 4 (length), keccak256(slot) (elements)
    
    // Struct with mapping (complex layout)
    struct ComplexStruct {
        uint256 id;
        string name;
        mapping(address => uint256) balances;
    }
    
    ComplexStruct[] public complexData;
    
    // Gas-efficient storage access pattern
    function efficientTransfer(address to, uint256 amount) public {
        // Cache storage in memory
        uint256 senderBalance = balances[msg.sender];
        
        require(senderBalance >= amount, "Insufficient balance");
        
        // Update storage once (saves ~5000 gas)
        unchecked {
            balances[msg.sender] = senderBalance - amount;
        }
        balances[to] += amount;
    }
    
    // Storage slot calculation for mappings
    function getMappingSlot(address key, uint256 mappingSlot) internal pure returns (bytes32) {
        return keccak256(abi.encode(key, mappingSlot));
    }
}

Storage Slot Layout

TypeSlot SizeLayout
uint25632 bytesFull slot
uint12816 bytesPacked with another uint128
bool1 bytePacked with adjacent small types
address20 bytesPacked with 12 bytes
mapping32 bytesSlot = hash(key, slot)
dynamic array32 bytesLength in slot, data at keccak256(slot)

Meta-Transactions

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract MetaTransaction {
    // EIP-712 domain separator
    bytes32 public constant DOMAIN_TYPEHASH = keccak256(
        "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
    );
    
    bytes32 public constant DOMAIN_NAME = keccak256("MetaTransaction");
    bytes32 public constant DOMAIN_VERSION = keccak256("1");
    
    // Message type hash
    bytes32 public constant TRANSFER_TYPEHASH = keccak256(
        "Transfer(address to,uint256 amount,uint256 nonce)"
    );
    
    mapping(address => uint256) public nonces;
    mapping(bytes32 => bool) public executed;
    
    event MetaTransfer(
        address indexed signer,
        address indexed to,
        uint256 amount,
        uint256 nonce
    );
    
    constructor() {}
    
    function getDomainSeparator() public view returns (bytes32) {
        return keccak256(abi.encode(
            DOMAIN_TYPEHASH,
            DOMAIN_NAME,
            DOMAIN_VERSION,
            block.chainid,
            address(this)
        ));
    }
    
    function getNonce(address signer) public view returns (uint256) {
        return nonces[signer];
    }
    
    function executeMetaTransfer(
        address signer,
        address to,
        uint256 amount,
        uint256 nonce,
        bytes memory signature
    ) public returns (bool) {
        require(nonce == nonces[signer], "Invalid nonce");
        
        bytes32 structHash = keccak256(abi.encode(
            TRANSFER_TYPEHASH,
            to,
            amount,
            nonce
        ));
        
        bytes32 digest = keccak256(abi.encodePacked(
            "\x19\x01",
            getDomainSeparator(),
            structHash
        ));
        
        address recoveredSigner = _recoverSigner(digest, signature);
        require(recoveredSigner == signer, "Invalid signature");
        
        nonces[signer]++;
        executed[structHash] = true;
        
        emit MetaTransfer(signer, to, amount, nonce);
        
        return true;
    }
    
    function _recoverSigner(bytes32 digest, bytes memory signature) internal pure returns (address) {
        require(signature.length == 65, "Invalid signature length");
        
        bytes32 r;
        bytes32 s;
        uint8 v;
        
        assembly {
            r := calldataload(signature.offset)
            s := calldataload(add(signature.offset, 32))
            v := byte(0, calldataload(add(signature.offset, 64)))
        }
        
        if (v < 27) v += 27;
        require(v == 27 || v == 28, "Invalid v");
        
        return ecrecover(digest, v, r, s);
    }
    
    // Nonce management
    function useNonce() public returns (uint256) {
        uint256 currentNonce = nonces[msg.sender];
        nonces[msg.sender]++;
        return currentNonce;
    }
    
    // Batch execution
    function executeBatchMetaTransfers(
        address signer,
        address[] calldata recipients,
        uint256[] calldata amounts,
        uint256 nonce,
        bytes calldata signature
    ) public returns (bool) {
        require(recipients.length == amounts.length, "Length mismatch");
        require(nonce == nonces[signer], "Invalid nonce");
        
        bytes32 structHash = keccak256(abi.encode(
            TRANSFER_TYPEHASH,
            keccak256(abi.encode(recipients, amounts)),
            nonce
        ));
        
        bytes32 digest = keccak256(abi.encodePacked(
            "\x19\x01",
            getDomainSeparator(),
            structHash
        ));
        
        address recoveredSigner = _recoverSigner(digest, signature);
        require(recoveredSigner == signer, "Invalid signature");
        
        nonces[signer]++;
        
        for (uint256 i = 0; i < recipients.length; i++) {
            emit MetaTransfer(signer, recipients[i], amounts[i], nonce + i);
        }
        
        return true;
    }
}

Meta-Transaction Gas Comparison

MethodGas CostUser Experience
Direct Transaction~21,000 + gasRequires ETH
Meta-Transaction~50,000 (relayer)No ETH required
Gasless (EIP-2771)Relayer paysBest UX

Real-World Example: Uniswap V3 Factory

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

abstract contract UniswapV3Factory {
    address public owner;
    address public feeFactory;
    address public tickFactory;
    
    mapping(address => mapping(address => mapping(uint24 => address))) public pools;
    mapping(address => uint8) public poolFees;
    
    event PoolCreated(
        address indexed token0,
        address indexed token1,
        uint24 indexed fee,
        address pool
    );
    
    function createPool(
        address tokenA,
        address tokenB,
        uint24 fee
    ) external returns (address pool) {
        require(tokenA != tokenB, "Identical tokens");
        (address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
        require(token0 != address(0), "Zero address");
        require(fee >= 100 && fee <= 1000000, "Invalid fee");
        
        require(pools[token0][token1][fee] == address(0), "Pool exists");
        
        bytes memory bytecode = type(UniswapV3Pool).creationCode;
        bytes32 salt = keccak256(abi.encodePacked(token0, token1, fee));
        
        assembly {
            pool := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
        }
        
        require(pool != address(0), "Deployment failed");
        
        pools[token0][token1][fee] = pool;
        pools[token1][token0][fee] = pool;
        
        emit PoolCreated(token0, token1, fee, pool);
    }
}

Trade-offs

PatternComplexityGas CostFlexibilityUse Case
ProxyHighMediumHighUpgradeable protocols
FactoryMediumMediumMediumToken deployment
RegistryLowLowLowService discovery
DiamondVery HighHighVery HighComplex systems

Interview Questions

  1. Compare and contrast the Proxy and Diamond patterns. When would you choose one over the other?

    The Proxy pattern is simpler with lower gas overhead but limited to one implementation. The Diamond pattern allows multiple facets, enabling unlimited contract size but at higher complexity and gas cost. Choose Proxy for simple upgradeability, Diamond for complex modular systems.

  2. Explain how CREATE2 enables counterfactual instantiation. What are its use cases?

    CREATE2 uses a deterministic address formula based on deployer address, salt, and bytecode hash. This allows predicting the contract address before deployment, enabling use cases like counterfactual wallets, contract factories with predictable addresses, and layer-2 solutions.

  3. How does the UUPS pattern differ from the Transparent Proxy pattern in terms of upgrade authority?

    In Transparent Proxy, the admin (separate account) controls upgrades externally. In UUPS, the upgrade logic is in the implementation contract itself, meaning the contract's own governance controls upgrades. UUPS is more gas-efficient and self-contained but requires careful implementation.

Quiz Questions

  1. What is the maximum contract size limit after EIP-170?

    • A) 32KB
    • B) 24KB
    • C) 16KB
    • D) 48KB

    Answer: B - 24,576 bytes (24KB) is the maximum contract code size.

  2. Which pattern allows splitting a contract into multiple facets?

    • A) Proxy Pattern
    • B) Factory Pattern
    • C) Diamond Pattern
    • D) Registry Pattern

    Answer: C - The Diamond pattern (EIP-2535) splits contracts into facets, each handling specific functionality.

  3. What is the primary benefit of using Yul/inline assembly?

    • A) Better readability
    • B) Gas optimization
    • C) Type safety
    • D) Code simplicity

    Answer: B - Inline assembly provides direct EVM access for gas optimization, at the cost of readability and safety.

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-09-22

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Blockchain Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement