ETH Price: $1,585.23 (-0.61%)

Contract Diff Checker

Contract Name:
Proxy

Contract Source Code:

<i class='far fa-question-circle text-muted ms-2' data-bs-trigger='hover' data-bs-toggle='tooltip' data-bs-html='true' data-bs-title='Click on the check box to select individual contract to compare. Only 1 contract can be selected from each side.'></i>

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

/**
 * @title Minimal Proxy Contract
 * @dev Enhanced proxy implementation compatible with EIP-1967
 */
contract Proxy {
    // EIP-1967 storage slots
    bytes32 private constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    constructor(address _impl) {
        require(_impl != address(0), "Invalid implementation");
    
        assembly {
            sstore(IMPLEMENTATION_SLOT, _impl)
        }
    }

    /**
     * @dev Receive function to accept ETH
     */
    receive() external payable {
        _fallback();
    }

    /**
     * @dev Fallback function for all other calls
     */
    fallback() external payable {
        _fallback();
    }

    /**
     * @dev Returns the current implementation address
     */
    function _implementation() internal view returns (address impl) {
        assembly {
            impl := sload(IMPLEMENTATION_SLOT)
        }
    }

    /**
     * @dev Core delegation function
     */
    function _fallback() internal {
        address _impl = _implementation();
        require(_impl != address(0), "Implementation not set");

        assembly {
            // The pointer to the free memory slot
            let ptr := mload(0x40)
            // Copy function signature and arguments from calldata
            calldatacopy(ptr, 0, calldatasize())
            // Delegate call to the implementation contract
            let result := delegatecall(gas(), _impl, ptr, calldatasize(), 0, 0)
            // Get the size of the last return data
            let size := returndatasize()
            // Copy the return data
            returndatacopy(ptr, 0, size)
            
            switch result
            case 0 {
                revert(ptr, size)
            }
            default {
                return(ptr, size)
            }
        }
    }
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):