false
false
0
The new Blockscout UI is now open source! Learn how to deploy it here
- We're indexing this chain right now. Some of the counts may be inaccurate.

Contract Address Details

0xfF83F6335d8930cBad1c0D439A841f01888D9f69

Contract Name
SafeToL2Migration
Creator
Balance
0 ETH
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
5602094
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
Contract name:
SafeToL2Migration




Optimization enabled
false
Compiler version
v0.7.6+commit.7338295f




EVM Version
default




Verified at
2026-01-28T16:06:09.959838Z

contracts/libraries/SafeToL2Migration.sol

// SPDX-License-Identifier: LGPL-3.0-only
/* solhint-disable one-contract-per-file */
pragma solidity >=0.7.0 <0.9.0;

import {SafeStorage} from "../libraries/SafeStorage.sol";
import {Enum} from "../common/Enum.sol";

interface ISafe {
    // solhint-disable-next-line
    function VERSION() external view returns (string memory);

    function setFallbackHandler(address handler) external;
}

/**
 * @title Migration Contract for updating a Safe from 1.1.1/1.3.0/1.4.1 versions to a L2 version. Useful when replaying a Safe from a non L2 network in a L2 network.
 * @notice This contract facilitates the migration of a Safe contract from version 1.1.1 to 1.3.0/1.4.1 L2, 1.3.0 to 1.3.0L2 or from 1.4.1 to 1.4.1L2
 *         Other versions are not supported
 * @dev IMPORTANT: The migration will only work with proxies that store the implementation address in the storage slot 0.
 */
contract SafeToL2Migration is SafeStorage {
    // Address of this contract
    address public immutable MIGRATION_SINGLETON;

    /**
     * @notice Constructor
     * @dev Initializes the migrationSingleton with the contract's own address.
     */
    constructor() {
        MIGRATION_SINGLETON = address(this);
    }

    /**
     * @notice Event indicating a change of master copy address.
     * @param singleton New master copy address
     */
    event ChangedMasterCopy(address singleton);

    event SafeSetup(address indexed initiator, address[] owners, uint256 threshold, address initializer, address fallbackHandler);

    event SafeMultiSigTransaction(
        address to,
        uint256 value,
        bytes data,
        Enum.Operation operation,
        uint256 safeTxGas,
        uint256 baseGas,
        uint256 gasPrice,
        address gasToken,
        address payable refundReceiver,
        bytes signatures,
        // We combine nonce, sender and threshold into one to avoid stack too deep
        // Dev note: additionalInfo should not contain `bytes`, as this complicates decoding
        bytes additionalInfo
    );

    /**
     * @notice Modifier to make a function callable via delegatecall only.
     * If the function is called via a regular call, it will revert.
     */
    modifier onlyDelegateCall() {
        require(address(this) != MIGRATION_SINGLETON, "Migration should only be called via delegatecall");
        _;
    }

    /**
     * @notice Modifier to prevent using initialized Safes.
     * If Safe has a nonce higher than 0, it will revert
     */
    modifier onlyNonceZero() {
        // Nonce is increased before executing a tx, so first executed tx will have nonce=1
        require(nonce == 1, "Safe must have not executed any tx");
        _;
    }

    /**
     * @dev Internal function with common migration steps, changes the singleton and emits SafeMultiSigTransaction event
     */
    function migrate(address l2Singleton, bytes memory functionData) private {
        singleton = l2Singleton;

        // Encode nonce, sender, threshold
        bytes memory additionalInfo = abi.encode(0, msg.sender, threshold);

        // Simulate a L2 transaction so Safe Tx Service indexer picks up the Safe
        emit SafeMultiSigTransaction(
            MIGRATION_SINGLETON,
            0,
            functionData,
            Enum.Operation.DelegateCall,
            0,
            0,
            0,
            address(0),
            payable(address(0)),
            "", // We cannot detect signatures
            additionalInfo
        );
        emit ChangedMasterCopy(l2Singleton);
    }

    /**
     * @notice Migrate from Safe 1.3.0/1.4.1 Singleton (L1) to the same version provided L2 singleton
     * Safe is required to have nonce 0 so backend can support it after the migration
     * @dev This function should only be called via a delegatecall to perform the upgrade.
     * Singletons versions will be compared, so it implies that contracts exist
     */
    function migrateToL2(address l2Singleton) external onlyDelegateCall onlyNonceZero {
        address _singleton = singleton;
        require(_singleton != l2Singleton, "Safe is already using the singleton");
        bytes32 oldSingletonVersion = keccak256(abi.encodePacked(ISafe(_singleton).VERSION()));
        bytes32 newSingletonVersion = keccak256(abi.encodePacked(ISafe(l2Singleton).VERSION()));

        require(oldSingletonVersion == newSingletonVersion, "L2 singleton must match current version singleton");
        // There's no way to make sure if address is a valid singleton, unless we configure the contract for every chain
        require(
            newSingletonVersion == keccak256(abi.encodePacked("1.3.0")) || newSingletonVersion == keccak256(abi.encodePacked("1.4.1")),
            "Provided singleton version is not supported"
        );

        // 0xef2624ae - bytes4(keccak256("migrateToL2(address)"))
        bytes memory functionData = abi.encodeWithSelector(0xef2624ae, l2Singleton);
        migrate(l2Singleton, functionData);
    }

    /**
     * @notice Migrate from Safe 1.1.1 Singleton to 1.3.0 or 1.4.1 L2
     * Safe is required to have nonce 0 so backend can support it after the migration
     * @dev This function should only be called via a delegatecall to perform the upgrade.
     * Singletons version will be checked, so it implies that contracts exist.
     * A valid and compatible fallbackHandler needs to be provided, only existence will be checked.
     */
    function migrateFromV111(address l2Singleton, address fallbackHandler) external onlyDelegateCall onlyNonceZero {
        require(isContract(fallbackHandler), "fallbackHandler is not a contract");

        bytes32 oldSingletonVersion = keccak256(abi.encodePacked(ISafe(singleton).VERSION()));
        require(oldSingletonVersion == keccak256(abi.encodePacked("1.1.1")), "Provided singleton version is not supported");

        bytes32 newSingletonVersion = keccak256(abi.encodePacked(ISafe(l2Singleton).VERSION()));
        require(
            newSingletonVersion == keccak256(abi.encodePacked("1.3.0")) || newSingletonVersion == keccak256(abi.encodePacked("1.4.1")),
            "Provided singleton version is not supported"
        );

        ISafe safe = ISafe(address(this));
        safe.setFallbackHandler(fallbackHandler);

        // Safes < 1.3.0 did not emit SafeSetup, so Safe Tx Service backend needs the event to index the Safe
        emit SafeSetup(MIGRATION_SINGLETON, getOwners(), threshold, address(0), fallbackHandler);

        // 0xd9a20812 - bytes4(keccak256("migrateFromV111(address,address)"))
        bytes memory functionData = abi.encodeWithSelector(0xd9a20812, l2Singleton, fallbackHandler);
        migrate(l2Singleton, functionData);
    }

    /**
     * @notice Checks whether an Ethereum address corresponds to a contract or an externally owned account (EOA).
     * @param account The Ethereum address to be checked.
     * @return A boolean value indicating whether the address is associated with a contract (true) or an EOA (false).
     * @dev This function relies on the `extcodesize` assembly opcode to determine whether an address is a contract.
     * It may return incorrect results in some edge cases (see documentation for details).
     * Developers should use caution when relying on the results of this function for critical decision-making.
     */
    function isContract(address account) internal view returns (bool) {
        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            size := extcodesize(account)
        }

        // If the code size is greater than 0, it is a contract; otherwise, it is an EOA.
        return size > 0;
    }

    /**
     * @notice Returns a list of Safe owners.
     * @dev This function is copied from `OwnerManager.sol` and takes advantage of the fact that
     * migration happens with a `DELEGATECALL` in the context of the migrating account, which allows
     * us to read the owners directly from storage and avoid the additional overhead of a `CALL`
     * into the account implementation. Note that we can rely on the memory layout of the {owners}
     * @return Array of Safe owners.
     */
    function getOwners() internal view returns (address[] memory) {
        address[] memory array = new address[](ownerCount);
        address sentinelOwners = address(0x1);
        // populate return array
        uint256 index = 0;
        address currentOwner = owners[sentinelOwners];
        while (currentOwner != sentinelOwners) {
            array[index] = currentOwner;
            currentOwner = owners[currentOwner];
            index++;
        }
        return array;
    }
}
        

contracts/libraries/SafeStorage.sol

// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

/**
 * @title SafeStorage - Storage layout of the Safe contracts to be used in libraries.
 * @dev Should be always the first base contract of a library that is used with a Safe.
 * @author Richard Meissner - @rmeissner
 */
contract SafeStorage {
    // From /common/Singleton.sol
    address internal singleton;
    // From /common/ModuleManager.sol
    mapping(address => address) internal modules;
    // From /common/OwnerManager.sol
    mapping(address => address) internal owners;
    uint256 internal ownerCount;
    uint256 internal threshold;

    // From /Safe.sol
    uint256 internal nonce;
    bytes32 internal _deprecatedDomainSeparator;
    mapping(bytes32 => uint256) internal signedMessages;
    mapping(address => mapping(bytes32 => uint256)) internal approvedHashes;
}
          

contracts/common/Enum.sol

// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

/**
 * @title Enum - Collection of enums used in Safe contracts.
 * @author Richard Meissner - @rmeissner
 */
abstract contract Enum {
    enum Operation {
        Call,
        DelegateCall
    }
}
          

Compiler Settings

{"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":200,"enabled":false},"metadata":{"useLiteralContent":true},"libraries":{}}
              

Contract ABI

[{"type":"constructor","stateMutability":"nonpayable","inputs":[]},{"type":"event","name":"ChangedMasterCopy","inputs":[{"type":"address","name":"singleton","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"SafeMultiSigTransaction","inputs":[{"type":"address","name":"to","internalType":"address","indexed":false},{"type":"uint256","name":"value","internalType":"uint256","indexed":false},{"type":"bytes","name":"data","internalType":"bytes","indexed":false},{"type":"uint8","name":"operation","internalType":"enum Enum.Operation","indexed":false},{"type":"uint256","name":"safeTxGas","internalType":"uint256","indexed":false},{"type":"uint256","name":"baseGas","internalType":"uint256","indexed":false},{"type":"uint256","name":"gasPrice","internalType":"uint256","indexed":false},{"type":"address","name":"gasToken","internalType":"address","indexed":false},{"type":"address","name":"refundReceiver","internalType":"address payable","indexed":false},{"type":"bytes","name":"signatures","internalType":"bytes","indexed":false},{"type":"bytes","name":"additionalInfo","internalType":"bytes","indexed":false}],"anonymous":false},{"type":"event","name":"SafeSetup","inputs":[{"type":"address","name":"initiator","internalType":"address","indexed":true},{"type":"address[]","name":"owners","internalType":"address[]","indexed":false},{"type":"uint256","name":"threshold","internalType":"uint256","indexed":false},{"type":"address","name":"initializer","internalType":"address","indexed":false},{"type":"address","name":"fallbackHandler","internalType":"address","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"MIGRATION_SINGLETON","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"migrateFromV111","inputs":[{"type":"address","name":"l2Singleton","internalType":"address"},{"type":"address","name":"fallbackHandler","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"migrateToL2","inputs":[{"type":"address","name":"l2Singleton","internalType":"address"}]}]
              

Deployed ByteCode

0x608060405234801561001057600080fd5b50600436106100415760003560e01c806372f7a95614610046578063d9a208121461007a578063ef2624ae146100de575b600080fd5b61004e610122565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6100dc6004803603604081101561009057600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610146565b005b610120600480360360208110156100f457600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506109dd565b005b7f000000000000000000000000ff83f6335d8930cbad1c0d439a841f01888d9f6981565b7f000000000000000000000000ff83f6335d8930cbad1c0d439a841f01888d9f6973ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff1614156101eb576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260308152602001806115476030913960400191505060405180910390fd5b600160055414610246576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806115f46022913960400191505060405180910390fd5b61024f816110b8565b6102a4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806115776021913960400191505060405180910390fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ffa1ad746040518163ffffffff1660e01b815260040160006040518083038186803b15801561030d57600080fd5b505afa158015610321573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250602081101561034b57600080fd5b810190808051604051939291908464010000000082111561036b57600080fd5b8382019150602082018581111561038157600080fd5b825186600182028301116401000000008211171561039e57600080fd5b8083526020830192505050908051906020019080838360005b838110156103d25780820151818401526020810190506103b7565b50505050905090810190601f1680156103ff5780820380516001836020036101000a031916815260200191505b506040525050506040516020018082805190602001908083835b6020831061043c5780518252602082019150602081019050602083039250610419565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405160208183030381529060405280519060200120905060405160200180807f312e312e310000000000000000000000000000000000000000000000000000008152506005019050604051602081830303815290604052805190602001208114610517576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602b815260200180611598602b913960400191505060405180910390fd5b60008373ffffffffffffffffffffffffffffffffffffffff1663ffa1ad746040518163ffffffff1660e01b815260040160006040518083038186803b15801561055f57600080fd5b505afa158015610573573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250602081101561059d57600080fd5b81019080805160405193929190846401000000008211156105bd57600080fd5b838201915060208201858111156105d357600080fd5b82518660018202830111640100000000821117156105f057600080fd5b8083526020830192505050908051906020019080838360005b83811015610624578082015181840152602081019050610609565b50505050905090810190601f1680156106515780820380516001836020036101000a031916815260200191505b506040525050506040516020018082805190602001908083835b6020831061068e578051825260208201915060208101905060208303925061066b565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405160208183030381529060405280519060200120905060405160200180807f312e332e30000000000000000000000000000000000000000000000000000000815250600501905060405160208183030381529060405280519060200120811480610764575060405160200180807f312e342e3100000000000000000000000000000000000000000000000000000081525060050190506040516020818303038152906040528051906020012081145b6107b9576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602b815260200180611598602b913960400191505060405180910390fd5b60003090508073ffffffffffffffffffffffffffffffffffffffff1663f08a0323856040518263ffffffff1660e01b8152600401808273ffffffffffffffffffffffffffffffffffffffff168152602001915050600060405180830381600087803b15801561082757600080fd5b505af115801561083b573d6000803e3d6000fd5b505050507f000000000000000000000000ff83f6335d8930cbad1c0d439a841f01888d9f6973ffffffffffffffffffffffffffffffffffffffff167f141df868a6331af528e38c83b7aa03edc19be66e37ae67f9285bf4f8e3c6a1a861089f6110cb565b60045460008860405180806020018581526020018473ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff168152602001828103825286818151815260200191508051906020019060200280838360005b8381101561092657808201518184015260208101905061090b565b505050509050019550505050505060405180910390a2600063d9a208128686604051602401808373ffffffffffffffffffffffffffffffffffffffff1681526020018273ffffffffffffffffffffffffffffffffffffffff168152602001925050506040516020818303038152906040529060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090506109d58682611279565b505050505050565b7f000000000000000000000000ff83f6335d8930cbad1c0d439a841f01888d9f6973ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff161415610a82576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260308152602001806115476030913960400191505060405180910390fd5b600160055414610add576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806115f46022913960400191505060405180910390fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161415610b88576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260238152602001806115246023913960400191505060405180910390fd5b60008173ffffffffffffffffffffffffffffffffffffffff1663ffa1ad746040518163ffffffff1660e01b815260040160006040518083038186803b158015610bd057600080fd5b505afa158015610be4573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052506020811015610c0e57600080fd5b8101908080516040519392919084640100000000821115610c2e57600080fd5b83820191506020820185811115610c4457600080fd5b8251866001820283011164010000000082111715610c6157600080fd5b8083526020830192505050908051906020019080838360005b83811015610c95578082015181840152602081019050610c7a565b50505050905090810190601f168015610cc25780820380516001836020036101000a031916815260200191505b506040525050506040516020018082805190602001908083835b60208310610cff5780518252602082019150602081019050602083039250610cdc565b6001836020036101000a03801982511681845116808217855250505050505090500191505060405160208183030381529060405280519060200120905060008373ffffffffffffffffffffffffffffffffffffffff1663ffa1ad746040518163ffffffff1660e01b815260040160006040518083038186803b158015610d8457600080fd5b505afa158015610d98573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f820116820180604052506020811015610dc257600080fd5b8101908080516040519392919084640100000000821115610de257600080fd5b83820191506020820185811115610df857600080fd5b8251866001820283011164010000000082111715610e1557600080fd5b8083526020830192505050908051906020019080838360005b83811015610e49578082015181840152602081019050610e2e565b50505050905090810190601f168015610e765780820380516001836020036101000a031916815260200191505b506040525050506040516020018082805190602001908083835b60208310610eb35780518252602082019150602081019050602083039250610e90565b6001836020036101000a038019825116818451168082178552505050505050905001915050604051602081830303815290604052805190602001209050808214610f48576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260318152602001806115c36031913960400191505060405180910390fd5b60405160200180807f312e332e30000000000000000000000000000000000000000000000000000000815250600501905060405160208183030381529060405280519060200120811480610fe1575060405160200180807f312e342e3100000000000000000000000000000000000000000000000000000081525060050190506040516020818303038152906040528051906020012081145b611036576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602b815260200180611598602b913960400191505060405180910390fd5b600063ef2624ae85604051602401808273ffffffffffffffffffffffffffffffffffffffff1681526020019150506040516020818303038152906040529060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505090506110b18582611279565b5050505050565b600080823b905060008111915050919050565b6060600060035467ffffffffffffffff811180156110e857600080fd5b506040519080825280602002602001820160405280156111175781602001602082028036833780820191505090505b509050600060019050600080600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690505b8273ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161461126f57808483815181106111c657fe5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508180600101925050611186565b8394505050505090565b816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060008033600454604051602001808481526020018373ffffffffffffffffffffffffffffffffffffffff168152602001828152602001935050505060405160208183030381529060405290507f66753cd2356569ee081232e3be8909b950e0a76c1f8460c3a5e3c2be32b11bed7f000000000000000000000000ff83f6335d8930cbad1c0d439a841f01888d9f69600084600160008060008060008a604051808b73ffffffffffffffffffffffffffffffffffffffff1681526020018a81526020018060200189600181111561138b57fe5b81526020018881526020018781526020018681526020018573ffffffffffffffffffffffffffffffffffffffff1681526020018473ffffffffffffffffffffffffffffffffffffffff168152602001806020018060200184810384528c818151815260200191508051906020019080838360005b8381101561141a5780820151818401526020810190506113ff565b50505050905090810190601f1680156114475780820380516001836020036101000a031916815260200191505b50848103835260008152602001848103825285818151815260200191508051906020019080838360005b8381101561148c578082015181840152602081019050611471565b50505050905090810190601f1680156114b95780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a17f75e41bc35ff1bf14d81d1d2f649c0084a0f974f9289c803ec9898eeec4c8d0b883604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a150505056fe5361666520697320616c7265616479207573696e67207468652073696e676c65746f6e4d6967726174696f6e2073686f756c64206f6e6c792062652063616c6c6564207669612064656c656761746563616c6c66616c6c6261636b48616e646c6572206973206e6f74206120636f6e747261637450726f76696465642073696e676c65746f6e2076657273696f6e206973206e6f7420737570706f727465644c322073696e676c65746f6e206d757374206d617463682063757272656e742076657273696f6e2073696e676c65746f6e53616665206d7573742068617665206e6f7420657865637574656420616e79207478a2646970667358221220d914c30647fc923b19a050a72872aeedb4f96d94ca6646a06297dff0c83f728564736f6c63430007060033