{
    "Function": "slitherConstructorConstantVariables",
    "File": "src/RecoverySpell.sol",
    "Parent Contracts": [
        "lib/openzeppelin-contracts/contracts/utils/cryptography/EIP712.sol",
        "lib/openzeppelin-contracts/contracts/interfaces/IERC5267.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [
        "keccak256(bytes)"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract RecoverySpell is EIP712(\"Recovery Spell\", \"0.1.0\") {\n    /// -------------------------------------------------------\n    /// -------------------------------------------------------\n    /// ------------------ STORAGE VARIABLES ------------------\n    /// -------------------------------------------------------\n    /// -------------------------------------------------------\n\n    /// @notice the new owners of the contract once the spell is cast\n    /// @dev starts off with non zero array if created by factory\n    /// and then is deleted after recovery execution\n    address[] public owners;\n\n    /// @notice the time the recovery was initiated\n    /// @dev value can only go from 0 to non zero when owner calls\n    /// goes from block.timestamp (always lt type(uint32).max)\n    /// to type(uint256).max\n    /// value can only ever increase\n    uint256 public recoveryInitiated;\n\n    /// -------------------------------------------------------\n    /// -------------------------------------------------------\n    /// ---------------------- IMMUTABLES ---------------------\n    /// -------------------------------------------------------\n    /// -------------------------------------------------------\n\n    /// @notice the address to recover\n    Safe public immutable safe;\n\n    /// @notice the threshold of owners required to execute transactions\n    /// after the recovery is executed\n    /// threshold must be lte the number of owners\n    uint256 public immutable threshold;\n\n    /// @notice the number of new owner signatures required to execute the\n    /// recovery process. This is to prevent a single owner from initiating\n    /// the recovery process without the consent of the other owners\n    uint256 public immutable recoveryThreshold;\n\n    /// @notice the time delay required before the recovery transaction\n    /// can be executed\n    uint256 public immutable delay;\n\n    /// -------------------------------------------------------\n    /// -------------------------------------------------------\n    /// ---------------------- CONSTANTS ----------------------\n    /// -------------------------------------------------------\n    /// -------------------------------------------------------\n\n    /// @notice the multicall3 contract address\n    address public constant MULTICALL3 =\n        0xcA11bde05977b3631167028862bE2a173976CA11;\n\n    /// @notice the sentinel address that all linked lists start with\n    address public constant SENTINEL = address(0x1);\n\n    /// @notice the recovery type hash for the EIP712 domain separator\n    bytes32 public constant RECOVERY_TYPEHASH = keccak256(\n        \"Recovery(address safe,uint256 newSafeThreshold,uint256 newRecoveryThreshold,uint256 delay)\"\n    );\n\n    /// -------------------------------------------------------\n    /// -------------------------------------------------------\n    /// ------------------------ EVENTS -----------------------\n    /// -------------------------------------------------------\n    /// -------------------------------------------------------\n\n    /// @notice event emitted when the recovery is initiated\n    /// @param time the time the recovery was initiated\n    /// @param caller the address that initiated the recovery\n    event RecoveryInitiated(uint256 indexed time, address indexed caller);\n\n    /// @notice event emitted when the recovery is executed\n    /// @param time the time the recovery was executed\n    event SafeRecovered(uint256 indexed time);\n\n    /// @notice it is of critical importance that the delay is shorter\n    /// than the timelock delay so that a recovery action can be executed\n    /// before the timelock delay expires if need be. There is no way to enforce\n    /// this in the contract, so it is up to the deployer to ensure that the\n    /// delay is shorter than the timelock delay\n    /// @param _owners the new owners of the contract if recovery is executed\n    /// @param _safe the address to recover\n    /// @param _safeThreshold number of owners required to execute transactions on the safe\n    /// @param _recoveryThreshold number of signers required to execute recovery transaction\n    /// @param _delay time required before the recovery transaction can be executed\n    constructor(\n        address[] memory _owners,\n        address _safe,\n        uint256 _safeThreshold,\n        uint256 _recoveryThreshold,\n        uint256 _delay\n    ) {\n        /// no checks on parameters as all valid recovery spells are\n        /// deployed from the factory which will not allow a recovery\n        /// spell to be created that does not have valid parameters.\n        /// A recovery spell can only be created by the factory if the Safe has\n        /// already been created on the chain the RecoverySpell is being\n        /// deployed on.\n        owners = _owners;\n        safe = Safe(payable(_safe));\n        threshold = _safeThreshold;\n        recoveryThreshold = _recoveryThreshold;\n        delay = _delay;\n\n        recoveryInitiated = block.timestamp;\n\n        emit RecoveryInitiated(block.timestamp, msg.sender);\n    }\n\n    /// @notice get the owners of the contract\n    function getOwners() external view returns (address[] memory) {\n        return owners;\n    }\n\n    /// @notice get the digest for the EIP712 domain separator\n    /// @return the digest for the EIP712 domain separator\n    function getDigest() public view returns (bytes32) {\n        return keccak256(\n            abi.encodePacked(\n                \"\\x19\\x01\",\n                _domainSeparatorV4(),\n                keccak256(\n                    abi.encode(\n                        RECOVERY_TYPEHASH,\n                        safe,\n                        threshold,\n                        recoveryThreshold,\n                        delay\n                    )\n                )\n            )\n        );\n    }\n\n    /// @notice execute the recovery process, can only be called\n    /// after the recovery delay has passed. Callable by any address\n    /// @param previousModule the address of the previous module\n    /// if the previous module is incorrect, this function will fail\n    ///\n    /// this function executes actions in the following order:\n    ///   1). remove all but final existing owner, sets owner threshold to 1\n    ///   2). swap final existing owner for the first new owner\n    ///   3). add the remaining new owners to the safe\n    ///   4). update the quorum to the new value\n    ///   4). remove the recovery module from the safe\n    function executeRecovery(\n        address previousModule,\n        uint8[] calldata v,\n        bytes32[] calldata r,\n        bytes32[] calldata s\n    ) external {\n        /// checks\n        require(\n            recoveryInitiated != type(uint256).max,\n            \"RecoverySpell: Already recovered\"\n        );\n\n        /// fails if recovery already executed due to math overflow\n        /// even if delay is 0, uint256.max + 1 will always revert\n        /// recovery initiated will always be lte block timestamp before the recovery is executed\n        require(\n            block.timestamp > recoveryInitiated + delay,\n            \"RecoverySpell: Recovery not ready\"\n        );\n        require(\n            v.length == r.length && r.length == s.length,\n            \"RecoverySpell: Invalid signature parameters\"\n        );\n        /// if there are not enough signers, even if all signatures are\n        /// valid and not duplicated, there is no possibility of this being\n        /// enough to execute the recovery.\n        require(\n            recoveryThreshold <= v.length,\n            \"RecoverySpell: Not enough signatures\"\n        );\n\n        for (uint256 i = 0; i < owners.length; i++) {\n            address owner = owners[i];\n            assembly (\"memory-safe\") {\n                tstore(owner, 1)\n            }\n        }\n\n        /// duplication and validity checks\n        /// ensure the signatures are\n        /// 1. valid signatures\n        /// 2. unique signers\n        /// 3. recovery owners about to be added to the safe\n\n        /// check if an address that provided a signature is an owner\n        /// in storage, then remove that address from used addresses\n        /// to prevent the same owner passing multiple signatures.\n\n        bytes32 digest = getDigest();\n        for (uint256 i = 0; i < v.length; i++) {\n            address recoveredAddress = ECDSA.recover(digest, v[i], r[i], s[i]);\n            bool valid;\n\n            assembly (\"memory-safe\") {\n                valid := tload(recoveredAddress)\n                if eq(valid, 1) { tstore(recoveredAddress, 0) }\n            }\n\n            /// if the address of the signer was not in storage, the value will\n            /// be 0 and the require will fail.\n            /// if the address of the signer duplicated signatures, the value\n            /// will be 0 on the second retrieval and the require will fail.\n            require(\n                valid && recoveredAddress != address(0),\n                \"RecoverySpell: Invalid signature\"\n            );\n        }\n\n        /// @notice execute the recovery process, can only be called\n        /// after the recovery delay has passed. Callable by any address\n\n        /// @param previousModule the address of the previous module\n        /// if the previous module is incorrect, this function will fail\n        ///\n        /// this function executes actions in the following order:\n        ///   1). remove all but final existing owner, set owner threshold to 1\n        ///   2). swap final existing owner for the first new owner\n        ///   3). add the remaining new owners to the safe, with the\n        ///   last owner being added updating the threshold to the new value\n        ///   4). remove the recovery module from the safe\n        address[] memory existingOwners = safe.getOwners();\n        uint256 existingOwnersLength = existingOwners.length;\n\n        /// + 1 is for the module removal\n        /// new owner length = 1\n        /// existing owner length = 1\n        IMulticall3.Call3[] memory calls3 =\n            new IMulticall3.Call3[](owners.length + existingOwnersLength + 1);\n\n        uint256 index = 0;\n\n        /// build interactions\n\n        /// remove all existing owners except the last one\n        for (uint256 i = 0; i < existingOwnersLength - 1; i++) {\n            calls3[index++].callData = abi.encodeWithSelector(\n                OwnerManager.removeOwner.selector,\n                SENTINEL,\n                existingOwners[i],\n                1\n            );\n        }\n\n        calls3[index++].callData = abi.encodeWithSelector(\n            OwnerManager.swapOwner.selector,\n            SENTINEL,\n            existingOwners[existingOwnersLength - 1],\n            owners[0]\n        );\n\n        /// only cover indexes 1 through new owners length\n        for (uint256 i = 1; i < owners.length; i++) {\n            calls3[index++].callData = abi.encodeWithSelector(\n                OwnerManager.addOwnerWithThreshold.selector, owners[i], 1\n            );\n        }\n\n        /// add new owner with the updated threshold\n        calls3[index++].callData = abi.encodeWithSelector(\n            OwnerManager.changeThreshold.selector, threshold\n        );\n\n        calls3[index].callData = abi.encodeWithSelector(\n            ModuleManager.disableModule.selector, previousModule, address(this)\n        );\n\n        for (uint256 i = 0; i < calls3.length; i++) {\n            calls3[i].allowFailure = false;\n            calls3[i].target = address(safe);\n        }\n\n        /// effects\n        /// now impossible to call initiate recovery as owners array is empty\n        delete owners;\n\n        /// array length is set to 0 impossible for executeRecovery to be\n        /// callable again as the require check will always revert\n        recoveryInitiated = type(uint256).max;\n\n        /// interactions\n\n        require(\n            safe.execTransactionFromModule(\n                MULTICALL3,\n                0,\n                abi.encodeWithSelector(IMulticall3.aggregate3.selector, calls3),\n                Enum.Operation.DelegateCall\n            ),\n            \"RecoverySpell: Recovery failed\"\n        );\n\n        emit SafeRecovered(block.timestamp);\n    }\n}"
}