{"file_path":"AppProxyUpgradeable.sol","creation_status":"success","source_code":"/**\r\n *Submitted for verification at Etherscan.io on 2019-09-06\r\n*/\r\n\r\n// File: contracts/acl/IACL.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\ninterface IACL {\r\n    function initialize(address permissionsCreator) external;\r\n\r\n    // TODO: this should be external\r\n    // See https://github.com/ethereum/solidity/issues/4832\r\n    function hasPermission(address who, address where, bytes32 what, bytes how) public view returns (bool);\r\n}\r\n\r\n// File: contracts/common/IVaultRecoverable.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\ninterface IVaultRecoverable {\r\n    event RecoverToVault(address indexed vault, address indexed token, uint256 amount);\r\n\r\n    function transferToVault(address token) external;\r\n\r\n    function allowRecoverability(address token) external view returns (bool);\r\n    function getRecoveryVault() external view returns (address);\r\n}\r\n\r\n// File: contracts/kernel/IKernel.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n\r\n\r\ninterface IKernelEvents {\r\n    event SetApp(bytes32 indexed namespace, bytes32 indexed appId, address app);\r\n}\r\n\r\n\r\n// This should be an interface, but interfaces can't inherit yet :(\r\ncontract IKernel is IKernelEvents, IVaultRecoverable {\r\n    function acl() public view returns (IACL);\r\n    function hasPermission(address who, address where, bytes32 what, bytes how) public view returns (bool);\r\n\r\n    function setApp(bytes32 namespace, bytes32 appId, address app) public;\r\n    function getApp(bytes32 namespace, bytes32 appId) public view returns (address);\r\n}\r\n\r\n// File: contracts/kernel/KernelConstants.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\ncontract KernelAppIds {\r\n    /* Hardcoded constants to save gas\r\n    bytes32 internal constant KERNEL_CORE_APP_ID = apmNamehash(\"kernel\");\r\n    bytes32 internal constant KERNEL_DEFAULT_ACL_APP_ID = apmNamehash(\"acl\");\r\n    bytes32 internal constant KERNEL_DEFAULT_VAULT_APP_ID = apmNamehash(\"vault\");\r\n    */\r\n    bytes32 internal constant KERNEL_CORE_APP_ID = 0x3b4bf6bf3ad5000ecf0f989d5befde585c6860fea3e574a4fab4c49d1c177d9c;\r\n    bytes32 internal constant KERNEL_DEFAULT_ACL_APP_ID = 0xe3262375f45a6e2026b7e7b18c2b807434f2508fe1a2a3dfb493c7df8f4aad6a;\r\n    bytes32 internal constant KERNEL_DEFAULT_VAULT_APP_ID = 0x7e852e0fcfce6551c13800f1e7476f982525c2b5277ba14b24339c68416336d1;\r\n}\r\n\r\n\r\ncontract KernelNamespaceConstants {\r\n    /* Hardcoded constants to save gas\r\n    bytes32 internal constant KERNEL_CORE_NAMESPACE = keccak256(\"core\");\r\n    bytes32 internal constant KERNEL_APP_BASES_NAMESPACE = keccak256(\"base\");\r\n    bytes32 internal constant KERNEL_APP_ADDR_NAMESPACE = keccak256(\"app\");\r\n    */\r\n    bytes32 internal constant KERNEL_CORE_NAMESPACE = 0xc681a85306374a5ab27f0bbc385296a54bcd314a1948b6cf61c4ea1bc44bb9f8;\r\n    bytes32 internal constant KERNEL_APP_BASES_NAMESPACE = 0xf1f3eb40f5bc1ad1344716ced8b8a0431d840b5783aea1fd01786bc26f35ac0f;\r\n    bytes32 internal constant KERNEL_APP_ADDR_NAMESPACE = 0xd6f028ca0e8edb4a8c9757ca4fdccab25fa1e0317da1188108f7d2dee14902fb;\r\n}\r\n\r\n// File: contracts/kernel/KernelStorage.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\ncontract KernelStorage {\r\n    // namespace => app id => address\r\n    mapping (bytes32 => mapping (bytes32 => address)) public apps;\r\n    bytes32 public recoveryVaultAppId;\r\n}\r\n\r\n// File: contracts/acl/ACLSyntaxSugar.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\ncontract ACLSyntaxSugar {\r\n    function arr() internal pure returns (uint256[]) {\r\n        return new uint256[](0);\r\n    }\r\n\r\n    function arr(bytes32 _a) internal pure returns (uint256[] r) {\r\n        return arr(uint256(_a));\r\n    }\r\n\r\n    function arr(bytes32 _a, bytes32 _b) internal pure returns (uint256[] r) {\r\n        return arr(uint256(_a), uint256(_b));\r\n    }\r\n\r\n    function arr(address _a) internal pure returns (uint256[] r) {\r\n        return arr(uint256(_a));\r\n    }\r\n\r\n    function arr(address _a, address _b) internal pure returns (uint256[] r) {\r\n        return arr(uint256(_a), uint256(_b));\r\n    }\r\n\r\n    function arr(address _a, uint256 _b, uint256 _c) internal pure returns (uint256[] r) {\r\n        return arr(uint256(_a), _b, _c);\r\n    }\r\n\r\n    function arr(address _a, uint256 _b, uint256 _c, uint256 _d) internal pure returns (uint256[] r) {\r\n        return arr(uint256(_a), _b, _c, _d);\r\n    }\r\n\r\n    function arr(address _a, uint256 _b) internal pure returns (uint256[] r) {\r\n        return arr(uint256(_a), uint256(_b));\r\n    }\r\n\r\n    function arr(address _a, address _b, uint256 _c, uint256 _d, uint256 _e) internal pure returns (uint256[] r) {\r\n        return arr(uint256(_a), uint256(_b), _c, _d, _e);\r\n    }\r\n\r\n    function arr(address _a, address _b, address _c) internal pure returns (uint256[] r) {\r\n        return arr(uint256(_a), uint256(_b), uint256(_c));\r\n    }\r\n\r\n    function arr(address _a, address _b, uint256 _c) internal pure returns (uint256[] r) {\r\n        return arr(uint256(_a), uint256(_b), uint256(_c));\r\n    }\r\n\r\n    function arr(uint256 _a) internal pure returns (uint256[] r) {\r\n        r = new uint256[](1);\r\n        r[0] = _a;\r\n    }\r\n\r\n    function arr(uint256 _a, uint256 _b) internal pure returns (uint256[] r) {\r\n        r = new uint256[](2);\r\n        r[0] = _a;\r\n        r[1] = _b;\r\n    }\r\n\r\n    function arr(uint256 _a, uint256 _b, uint256 _c) internal pure returns (uint256[] r) {\r\n        r = new uint256[](3);\r\n        r[0] = _a;\r\n        r[1] = _b;\r\n        r[2] = _c;\r\n    }\r\n\r\n    function arr(uint256 _a, uint256 _b, uint256 _c, uint256 _d) internal pure returns (uint256[] r) {\r\n        r = new uint256[](4);\r\n        r[0] = _a;\r\n        r[1] = _b;\r\n        r[2] = _c;\r\n        r[3] = _d;\r\n    }\r\n\r\n    function arr(uint256 _a, uint256 _b, uint256 _c, uint256 _d, uint256 _e) internal pure returns (uint256[] r) {\r\n        r = new uint256[](5);\r\n        r[0] = _a;\r\n        r[1] = _b;\r\n        r[2] = _c;\r\n        r[3] = _d;\r\n        r[4] = _e;\r\n    }\r\n}\r\n\r\n\r\ncontract ACLHelpers {\r\n    function decodeParamOp(uint256 _x) internal pure returns (uint8 b) {\r\n        return uint8(_x >> (8 * 30));\r\n    }\r\n\r\n    function decodeParamId(uint256 _x) internal pure returns (uint8 b) {\r\n        return uint8(_x >> (8 * 31));\r\n    }\r\n\r\n    function decodeParamsList(uint256 _x) internal pure returns (uint32 a, uint32 b, uint32 c) {\r\n        a = uint32(_x);\r\n        b = uint32(_x >> (8 * 4));\r\n        c = uint32(_x >> (8 * 8));\r\n    }\r\n}\r\n\r\n// File: contracts/common/ConversionHelpers.sol\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\nlibrary ConversionHelpers {\r\n    string private constant ERROR_IMPROPER_LENGTH = \"CONVERSION_IMPROPER_LENGTH\";\r\n\r\n    function dangerouslyCastUintArrayToBytes(uint256[] memory _input) internal pure returns (bytes memory output) {\r\n        // Force cast the uint256[] into a bytes array, by overwriting its length\r\n        // Note that the bytes array doesn't need to be initialized as we immediately overwrite it\r\n        // with the input and a new length. The input becomes invalid from this point forward.\r\n        uint256 byteLength = _input.length * 32;\r\n        assembly {\r\n            output := _input\r\n            mstore(output, byteLength)\r\n        }\r\n    }\r\n\r\n    function dangerouslyCastBytesToUintArray(bytes memory _input) internal pure returns (uint256[] memory output) {\r\n        // Force cast the bytes array into a uint256[], by overwriting its length\r\n        // Note that the uint256[] doesn't need to be initialized as we immediately overwrite it\r\n        // with the input and a new length. The input becomes invalid from this point forward.\r\n        uint256 intsLength = _input.length / 32;\r\n        require(_input.length == intsLength * 32, ERROR_IMPROPER_LENGTH);\r\n\r\n        assembly {\r\n            output := _input\r\n            mstore(output, intsLength)\r\n        }\r\n    }\r\n}\r\n\r\n// File: contracts/common/IsContract.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\ncontract IsContract {\r\n    /*\r\n    * NOTE: this should NEVER be used for authentication\r\n    * (see pitfalls: https://github.com/fergarrui/ethereum-security/tree/master/contracts/extcodesize).\r\n    *\r\n    * This is only intended to be used as a sanity check that an address is actually a contract,\r\n    * RATHER THAN an address not being a contract.\r\n    */\r\n    function isContract(address _target) internal view returns (bool) {\r\n        if (_target == address(0)) {\r\n            return false;\r\n        }\r\n\r\n        uint256 size;\r\n        assembly { size := extcodesize(_target) }\r\n        return size > 0;\r\n    }\r\n}\r\n\r\n// File: contracts/common/Uint256Helpers.sol\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\nlibrary Uint256Helpers {\r\n    uint256 private constant MAX_UINT64 = uint64(-1);\r\n\r\n    string private constant ERROR_NUMBER_TOO_BIG = \"UINT64_NUMBER_TOO_BIG\";\r\n\r\n    function toUint64(uint256 a) internal pure returns (uint64) {\r\n        require(a <= MAX_UINT64, ERROR_NUMBER_TOO_BIG);\r\n        return uint64(a);\r\n    }\r\n}\r\n\r\n// File: contracts/common/TimeHelpers.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n\r\ncontract TimeHelpers {\r\n    using Uint256Helpers for uint256;\r\n\r\n    /**\r\n    * @dev Returns the current block number.\r\n    *      Using a function rather than `block.number` allows us to easily mock the block number in\r\n    *      tests.\r\n    */\r\n    function getBlockNumber() internal view returns (uint256) {\r\n        return block.number;\r\n    }\r\n\r\n    /**\r\n    * @dev Returns the current block number, converted to uint64.\r\n    *      Using a function rather than `block.number` allows us to easily mock the block number in\r\n    *      tests.\r\n    */\r\n    function getBlockNumber64() internal view returns (uint64) {\r\n        return getBlockNumber().toUint64();\r\n    }\r\n\r\n    /**\r\n    * @dev Returns the current timestamp.\r\n    *      Using a function rather than `block.timestamp` allows us to easily mock it in\r\n    *      tests.\r\n    */\r\n    function getTimestamp() internal view returns (uint256) {\r\n        return block.timestamp; // solium-disable-line security/no-block-members\r\n    }\r\n\r\n    /**\r\n    * @dev Returns the current timestamp, converted to uint64.\r\n    *      Using a function rather than `block.timestamp` allows us to easily mock it in\r\n    *      tests.\r\n    */\r\n    function getTimestamp64() internal view returns (uint64) {\r\n        return getTimestamp().toUint64();\r\n    }\r\n}\r\n\r\n// File: contracts/common/UnstructuredStorage.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\nlibrary UnstructuredStorage {\r\n    function getStorageBool(bytes32 position) internal view returns (bool data) {\r\n        assembly { data := sload(position) }\r\n    }\r\n\r\n    function getStorageAddress(bytes32 position) internal view returns (address data) {\r\n        assembly { data := sload(position) }\r\n    }\r\n\r\n    function getStorageBytes32(bytes32 position) internal view returns (bytes32 data) {\r\n        assembly { data := sload(position) }\r\n    }\r\n\r\n    function getStorageUint256(bytes32 position) internal view returns (uint256 data) {\r\n        assembly { data := sload(position) }\r\n    }\r\n\r\n    function setStorageBool(bytes32 position, bool data) internal {\r\n        assembly { sstore(position, data) }\r\n    }\r\n\r\n    function setStorageAddress(bytes32 position, address data) internal {\r\n        assembly { sstore(position, data) }\r\n    }\r\n\r\n    function setStorageBytes32(bytes32 position, bytes32 data) internal {\r\n        assembly { sstore(position, data) }\r\n    }\r\n\r\n    function setStorageUint256(bytes32 position, uint256 data) internal {\r\n        assembly { sstore(position, data) }\r\n    }\r\n}\r\n\r\n// File: contracts/common/Initializable.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n\r\n\r\ncontract Initializable is TimeHelpers {\r\n    using UnstructuredStorage for bytes32;\r\n\r\n    // keccak256(\"aragonOS.initializable.initializationBlock\")\r\n    bytes32 internal constant INITIALIZATION_BLOCK_POSITION = 0xebb05b386a8d34882b8711d156f463690983dc47815980fb82aeeff1aa43579e;\r\n\r\n    string private constant ERROR_ALREADY_INITIALIZED = \"INIT_ALREADY_INITIALIZED\";\r\n    string private constant ERROR_NOT_INITIALIZED = \"INIT_NOT_INITIALIZED\";\r\n\r\n    modifier onlyInit {\r\n        require(getInitializationBlock() == 0, ERROR_ALREADY_INITIALIZED);\r\n        _;\r\n    }\r\n\r\n    modifier isInitialized {\r\n        require(hasInitialized(), ERROR_NOT_INITIALIZED);\r\n        _;\r\n    }\r\n\r\n    /**\r\n    * @return Block number in which the contract was initialized\r\n    */\r\n    function getInitializationBlock() public view returns (uint256) {\r\n        return INITIALIZATION_BLOCK_POSITION.getStorageUint256();\r\n    }\r\n\r\n    /**\r\n    * @return Whether the contract has been initialized by the time of the current block\r\n    */\r\n    function hasInitialized() public view returns (bool) {\r\n        uint256 initializationBlock = getInitializationBlock();\r\n        return initializationBlock != 0 && getBlockNumber() >= initializationBlock;\r\n    }\r\n\r\n    /**\r\n    * @dev Function to be called by top level contract after initialization has finished.\r\n    */\r\n    function initialized() internal onlyInit {\r\n        INITIALIZATION_BLOCK_POSITION.setStorageUint256(getBlockNumber());\r\n    }\r\n\r\n    /**\r\n    * @dev Function to be called by top level contract after initialization to enable the contract\r\n    *      at a future block number rather than immediately.\r\n    */\r\n    function initializedAt(uint256 _blockNumber) internal onlyInit {\r\n        INITIALIZATION_BLOCK_POSITION.setStorageUint256(_blockNumber);\r\n    }\r\n}\r\n\r\n// File: contracts/common/Petrifiable.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n\r\ncontract Petrifiable is Initializable {\r\n    // Use block UINT256_MAX (which should be never) as the initializable date\r\n    uint256 internal constant PETRIFIED_BLOCK = uint256(-1);\r\n\r\n    function isPetrified() public view returns (bool) {\r\n        return getInitializationBlock() == PETRIFIED_BLOCK;\r\n    }\r\n\r\n    /**\r\n    * @dev Function to be called by top level contract to prevent being initialized.\r\n    *      Useful for freezing base contracts when they're used behind proxies.\r\n    */\r\n    function petrify() internal onlyInit {\r\n        initializedAt(PETRIFIED_BLOCK);\r\n    }\r\n}\r\n\r\n// File: contracts/lib/token/ERC20.sol\r\n\r\n// See https://github.com/OpenZeppelin/openzeppelin-solidity/blob/a9f910d34f0ab33a1ae5e714f69f9596a02b4d91/contracts/token/ERC20/ERC20.sol\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n/**\r\n * @title ERC20 interface\r\n * @dev see https://github.com/ethereum/EIPs/issues/20\r\n */\r\ncontract ERC20 {\r\n    function totalSupply() public view returns (uint256);\r\n\r\n    function balanceOf(address _who) public view returns (uint256);\r\n\r\n    function allowance(address _owner, address _spender)\r\n        public view returns (uint256);\r\n\r\n    function transfer(address _to, uint256 _value) public returns (bool);\r\n\r\n    function approve(address _spender, uint256 _value)\r\n        public returns (bool);\r\n\r\n    function transferFrom(address _from, address _to, uint256 _value)\r\n        public returns (bool);\r\n\r\n    event Transfer(\r\n        address indexed from,\r\n        address indexed to,\r\n        uint256 value\r\n    );\r\n\r\n    event Approval(\r\n        address indexed owner,\r\n        address indexed spender,\r\n        uint256 value\r\n    );\r\n}\r\n\r\n// File: contracts/common/EtherTokenConstant.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n// aragonOS and aragon-apps rely on address(0) to denote native ETH, in\r\n// contracts where both tokens and ETH are accepted\r\ncontract EtherTokenConstant {\r\n    address internal constant ETH = address(0);\r\n}\r\n\r\n// File: contracts/common/SafeERC20.sol\r\n\r\n// Inspired by AdEx (https://github.com/AdExNetwork/adex-protocol-eth/blob/b9df617829661a7518ee10f4cb6c4108659dd6d5/contracts/libs/SafeERC20.sol)\r\n// and 0x (https://github.com/0xProject/0x-monorepo/blob/737d1dc54d72872e24abce5a1dbe1b66d35fa21a/contracts/protocol/contracts/protocol/AssetProxy/ERC20Proxy.sol#L143)\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n\r\nlibrary SafeERC20 {\r\n    // Before 0.5, solidity has a mismatch between `address.transfer()` and `token.transfer()`:\r\n    // https://github.com/ethereum/solidity/issues/3544\r\n    bytes4 private constant TRANSFER_SELECTOR = 0xa9059cbb;\r\n\r\n    string private constant ERROR_TOKEN_BALANCE_REVERTED = \"SAFE_ERC_20_BALANCE_REVERTED\";\r\n    string private constant ERROR_TOKEN_ALLOWANCE_REVERTED = \"SAFE_ERC_20_ALLOWANCE_REVERTED\";\r\n\r\n    function invokeAndCheckSuccess(address _addr, bytes memory _calldata)\r\n        private\r\n        returns (bool)\r\n    {\r\n        bool ret;\r\n        assembly {\r\n            let ptr := mload(0x40)    // free memory pointer\r\n\r\n            let success := call(\r\n                gas,                  // forward all gas\r\n                _addr,                // address\r\n                0,                    // no value\r\n                add(_calldata, 0x20), // calldata start\r\n                mload(_calldata),     // calldata length\r\n                ptr,                  // write output over free memory\r\n                0x20                  // uint256 return\r\n            )\r\n\r\n            if gt(success, 0) {\r\n                // Check number of bytes returned from last function call\r\n                switch returndatasize\r\n\r\n                // No bytes returned: assume success\r\n                case 0 {\r\n                    ret := 1\r\n                }\r\n\r\n                // 32 bytes returned: check if non-zero\r\n                case 0x20 {\r\n                    // Only return success if returned data was true\r\n                    // Already have output in ptr\r\n                    ret := eq(mload(ptr), 1)\r\n                }\r\n\r\n                // Not sure what was returned: don't mark as success\r\n                default { }\r\n            }\r\n        }\r\n        return ret;\r\n    }\r\n\r\n    function staticInvoke(address _addr, bytes memory _calldata)\r\n        private\r\n        view\r\n        returns (bool, uint256)\r\n    {\r\n        bool success;\r\n        uint256 ret;\r\n        assembly {\r\n            let ptr := mload(0x40)    // free memory pointer\r\n\r\n            success := staticcall(\r\n                gas,                  // forward all gas\r\n                _addr,                // address\r\n                add(_calldata, 0x20), // calldata start\r\n                mload(_calldata),     // calldata length\r\n                ptr,                  // write output over free memory\r\n                0x20                  // uint256 return\r\n            )\r\n\r\n            if gt(success, 0) {\r\n                ret := mload(ptr)\r\n            }\r\n        }\r\n        return (success, ret);\r\n    }\r\n\r\n    /**\r\n    * @dev Same as a standards-compliant ERC20.transfer() that never reverts (returns false).\r\n    *      Note that this makes an external call to the token.\r\n    */\r\n    function safeTransfer(ERC20 _token, address _to, uint256 _amount) internal returns (bool) {\r\n        bytes memory transferCallData = abi.encodeWithSelector(\r\n            TRANSFER_SELECTOR,\r\n            _to,\r\n            _amount\r\n        );\r\n        return invokeAndCheckSuccess(_token, transferCallData);\r\n    }\r\n\r\n    /**\r\n    * @dev Same as a standards-compliant ERC20.transferFrom() that never reverts (returns false).\r\n    *      Note that this makes an external call to the token.\r\n    */\r\n    function safeTransferFrom(ERC20 _token, address _from, address _to, uint256 _amount) internal returns (bool) {\r\n        bytes memory transferFromCallData = abi.encodeWithSelector(\r\n            _token.transferFrom.selector,\r\n            _from,\r\n            _to,\r\n            _amount\r\n        );\r\n        return invokeAndCheckSuccess(_token, transferFromCallData);\r\n    }\r\n\r\n    /**\r\n    * @dev Same as a standards-compliant ERC20.approve() that never reverts (returns false).\r\n    *      Note that this makes an external call to the token.\r\n    */\r\n    function safeApprove(ERC20 _token, address _spender, uint256 _amount) internal returns (bool) {\r\n        bytes memory approveCallData = abi.encodeWithSelector(\r\n            _token.approve.selector,\r\n            _spender,\r\n            _amount\r\n        );\r\n        return invokeAndCheckSuccess(_token, approveCallData);\r\n    }\r\n\r\n    /**\r\n    * @dev Static call into ERC20.balanceOf().\r\n    * Reverts if the call fails for some reason (should never fail).\r\n    */\r\n    function staticBalanceOf(ERC20 _token, address _owner) internal view returns (uint256) {\r\n        bytes memory balanceOfCallData = abi.encodeWithSelector(\r\n            _token.balanceOf.selector,\r\n            _owner\r\n        );\r\n\r\n        (bool success, uint256 tokenBalance) = staticInvoke(_token, balanceOfCallData);\r\n        require(success, ERROR_TOKEN_BALANCE_REVERTED);\r\n\r\n        return tokenBalance;\r\n    }\r\n\r\n    /**\r\n    * @dev Static call into ERC20.allowance().\r\n    * Reverts if the call fails for some reason (should never fail).\r\n    */\r\n    function staticAllowance(ERC20 _token, address _owner, address _spender) internal view returns (uint256) {\r\n        bytes memory allowanceCallData = abi.encodeWithSelector(\r\n            _token.allowance.selector,\r\n            _owner,\r\n            _spender\r\n        );\r\n\r\n        (bool success, uint256 allowance) = staticInvoke(_token, allowanceCallData);\r\n        require(success, ERROR_TOKEN_ALLOWANCE_REVERTED);\r\n\r\n        return allowance;\r\n    }\r\n\r\n    /**\r\n    * @dev Static call into ERC20.totalSupply().\r\n    * Reverts if the call fails for some reason (should never fail).\r\n    */\r\n    function staticTotalSupply(ERC20 _token) internal view returns (uint256) {\r\n        bytes memory totalSupplyCallData = abi.encodeWithSelector(_token.totalSupply.selector);\r\n\r\n        (bool success, uint256 totalSupply) = staticInvoke(_token, totalSupplyCallData);\r\n        require(success, ERROR_TOKEN_ALLOWANCE_REVERTED);\r\n\r\n        return totalSupply;\r\n    }\r\n}\r\n\r\n// File: contracts/common/VaultRecoverable.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\ncontract VaultRecoverable is IVaultRecoverable, EtherTokenConstant, IsContract {\r\n    using SafeERC20 for ERC20;\r\n\r\n    string private constant ERROR_DISALLOWED = \"RECOVER_DISALLOWED\";\r\n    string private constant ERROR_VAULT_NOT_CONTRACT = \"RECOVER_VAULT_NOT_CONTRACT\";\r\n    string private constant ERROR_TOKEN_TRANSFER_FAILED = \"RECOVER_TOKEN_TRANSFER_FAILED\";\r\n\r\n    /**\r\n     * @notice Send funds to recovery Vault. This contract should never receive funds,\r\n     *         but in case it does, this function allows one to recover them.\r\n     * @param _token Token balance to be sent to recovery vault.\r\n     */\r\n    function transferToVault(address _token) external {\r\n        require(allowRecoverability(_token), ERROR_DISALLOWED);\r\n        address vault = getRecoveryVault();\r\n        require(isContract(vault), ERROR_VAULT_NOT_CONTRACT);\r\n\r\n        uint256 balance;\r\n        if (_token == ETH) {\r\n            balance = address(this).balance;\r\n            vault.transfer(balance);\r\n        } else {\r\n            ERC20 token = ERC20(_token);\r\n            balance = token.staticBalanceOf(this);\r\n            require(token.safeTransfer(vault, balance), ERROR_TOKEN_TRANSFER_FAILED);\r\n        }\r\n\r\n        emit RecoverToVault(vault, _token, balance);\r\n    }\r\n\r\n    /**\r\n    * @dev By default deriving from AragonApp makes it recoverable\r\n    * @param token Token address that would be recovered\r\n    * @return bool whether the app allows the recovery\r\n    */\r\n    function allowRecoverability(address token) public view returns (bool) {\r\n        return true;\r\n    }\r\n\r\n    // Cast non-implemented interface to be public so we can use it internally\r\n    function getRecoveryVault() public view returns (address);\r\n}\r\n\r\n// File: contracts/apps/AppStorage.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n\r\n\r\ncontract AppStorage {\r\n    using UnstructuredStorage for bytes32;\r\n\r\n    /* Hardcoded constants to save gas\r\n    bytes32 internal constant KERNEL_POSITION = keccak256(\"aragonOS.appStorage.kernel\");\r\n    bytes32 internal constant APP_ID_POSITION = keccak256(\"aragonOS.appStorage.appId\");\r\n    */\r\n    bytes32 internal constant KERNEL_POSITION = 0x4172f0f7d2289153072b0a6ca36959e0cbe2efc3afe50fc81636caa96338137b;\r\n    bytes32 internal constant APP_ID_POSITION = 0xd625496217aa6a3453eecb9c3489dc5a53e6c67b444329ea2b2cbc9ff547639b;\r\n\r\n    function kernel() public view returns (IKernel) {\r\n        return IKernel(KERNEL_POSITION.getStorageAddress());\r\n    }\r\n\r\n    function appId() public view returns (bytes32) {\r\n        return APP_ID_POSITION.getStorageBytes32();\r\n    }\r\n\r\n    function setKernel(IKernel _kernel) internal {\r\n        KERNEL_POSITION.setStorageAddress(address(_kernel));\r\n    }\r\n\r\n    function setAppId(bytes32 _appId) internal {\r\n        APP_ID_POSITION.setStorageBytes32(_appId);\r\n    }\r\n}\r\n\r\n// File: contracts/lib/misc/ERCProxy.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\ncontract ERCProxy {\r\n    uint256 internal constant FORWARDING = 1;\r\n    uint256 internal constant UPGRADEABLE = 2;\r\n\r\n    function proxyType() public pure returns (uint256 proxyTypeId);\r\n    function implementation() public view returns (address codeAddr);\r\n}\r\n\r\n// File: contracts/common/DelegateProxy.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\n\r\n\r\ncontract DelegateProxy is ERCProxy, IsContract {\r\n    uint256 internal constant FWD_GAS_LIMIT = 10000;\r\n\r\n    /**\r\n    * @dev Performs a delegatecall and returns whatever the delegatecall returned (entire context execution will return!)\r\n    * @param _dst Destination address to perform the delegatecall\r\n    * @param _calldata Calldata for the delegatecall\r\n    */\r\n    function delegatedFwd(address _dst, bytes _calldata) internal {\r\n        require(isContract(_dst));\r\n        uint256 fwdGasLimit = FWD_GAS_LIMIT;\r\n\r\n        assembly {\r\n            let result := delegatecall(sub(gas, fwdGasLimit), _dst, add(_calldata, 0x20), mload(_calldata), 0, 0)\r\n            let size := returndatasize\r\n            let ptr := mload(0x40)\r\n            returndatacopy(ptr, 0, size)\r\n\r\n            // revert instead of invalid() bc if the underlying call failed with invalid() it already wasted gas.\r\n            // if the call returned error data, forward it\r\n            switch result case 0 { revert(ptr, size) }\r\n            default { return(ptr, size) }\r\n        }\r\n    }\r\n}\r\n\r\n// File: contracts/common/DepositableStorage.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\n\r\ncontract DepositableStorage {\r\n    using UnstructuredStorage for bytes32;\r\n\r\n    // keccak256(\"aragonOS.depositableStorage.depositable\")\r\n    bytes32 internal constant DEPOSITABLE_POSITION = 0x665fd576fbbe6f247aff98f5c94a561e3f71ec2d3c988d56f12d342396c50cea;\r\n\r\n    function isDepositable() public view returns (bool) {\r\n        return DEPOSITABLE_POSITION.getStorageBool();\r\n    }\r\n\r\n    function setDepositable(bool _depositable) internal {\r\n        DEPOSITABLE_POSITION.setStorageBool(_depositable);\r\n    }\r\n}\r\n\r\n// File: contracts/common/DepositableDelegateProxy.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\n\r\n\r\ncontract DepositableDelegateProxy is DepositableStorage, DelegateProxy {\r\n    event ProxyDeposit(address sender, uint256 value);\r\n\r\n    function () external payable {\r\n        uint256 forwardGasThreshold = FWD_GAS_LIMIT;\r\n        bytes32 isDepositablePosition = DEPOSITABLE_POSITION;\r\n\r\n        // Optimized assembly implementation to prevent EIP-1884 from breaking deposits, reference code in Solidity:\r\n        // https://github.com/aragon/aragonOS/blob/v4.2.1/contracts/common/DepositableDelegateProxy.sol#L10-L20\r\n        assembly {\r\n            // Continue only if the gas left is lower than the threshold for forwarding to the implementation code,\r\n            // otherwise continue outside of the assembly block.\r\n            if lt(gas, forwardGasThreshold) {\r\n                // Only accept the deposit and emit an event if all of the following are true:\r\n                // the proxy accepts deposits (isDepositable), msg.data.length == 0, and msg.value > 0\r\n                if and(and(sload(isDepositablePosition), iszero(calldatasize)), gt(callvalue, 0)) {\r\n                    // Equivalent Solidity code for emitting the event:\r\n                    // emit ProxyDeposit(msg.sender, msg.value);\r\n\r\n                    let logData := mload(0x40) // free memory pointer\r\n                    mstore(logData, caller) // add 'msg.sender' to the log data (first event param)\r\n                    mstore(add(logData, 0x20), callvalue) // add 'msg.value' to the log data (second event param)\r\n\r\n                    // Emit an event with one topic to identify the event: keccak256('ProxyDeposit(address,uint256)') = 0x15ee...dee1\r\n                    log1(logData, 0x40, 0x15eeaa57c7bd188c1388020bcadc2c436ec60d647d36ef5b9eb3c742217ddee1)\r\n\r\n                    stop() // Stop. Exits execution context\r\n                }\r\n\r\n                // If any of above checks failed, revert the execution (if ETH was sent, it is returned to the sender)\r\n                revert(0, 0)\r\n            }\r\n        }\r\n\r\n        address target = implementation();\r\n        delegatedFwd(target, msg.data);\r\n    }\r\n}\r\n\r\n// File: contracts/apps/AppProxyBase.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\n\r\n\r\n\r\n\r\ncontract AppProxyBase is AppStorage, DepositableDelegateProxy, KernelNamespaceConstants {\r\n    /**\r\n    * @dev Initialize AppProxy\r\n    * @param _kernel Reference to organization kernel for the app\r\n    * @param _appId Identifier for app\r\n    * @param _initializePayload Payload for call to be made after setup to initialize\r\n    */\r\n    constructor(IKernel _kernel, bytes32 _appId, bytes _initializePayload) public {\r\n        setKernel(_kernel);\r\n        setAppId(_appId);\r\n\r\n        // Implicit check that kernel is actually a Kernel\r\n        // The EVM doesn't actually provide a way for us to make sure, but we can force a revert to\r\n        // occur if the kernel is set to 0x0 or a non-code address when we try to call a method on\r\n        // it.\r\n        address appCode = getAppBase(_appId);\r\n\r\n        // If initialize payload is provided, it will be executed\r\n        if (_initializePayload.length > 0) {\r\n            require(isContract(appCode));\r\n            // Cannot make delegatecall as a delegateproxy.delegatedFwd as it\r\n            // returns ending execution context and halts contract deployment\r\n            require(appCode.delegatecall(_initializePayload));\r\n        }\r\n    }\r\n\r\n    function getAppBase(bytes32 _appId) internal view returns (address) {\r\n        return kernel().getApp(KERNEL_APP_BASES_NAMESPACE, _appId);\r\n    }\r\n}\r\n\r\n// File: contracts/apps/AppProxyUpgradeable.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\n\r\ncontract AppProxyUpgradeable is AppProxyBase {\r\n    /**\r\n    * @dev Initialize AppProxyUpgradeable (makes it an upgradeable Aragon app)\r\n    * @param _kernel Reference to organization kernel for the app\r\n    * @param _appId Identifier for app\r\n    * @param _initializePayload Payload for call to be made after setup to initialize\r\n    */\r\n    constructor(IKernel _kernel, bytes32 _appId, bytes _initializePayload)\r\n        AppProxyBase(_kernel, _appId, _initializePayload)\r\n        public // solium-disable-line visibility-first\r\n    {\r\n        // solium-disable-previous-line no-empty-blocks\r\n    }\r\n\r\n    /**\r\n     * @dev ERC897, the address the proxy would delegate calls to\r\n     */\r\n    function implementation() public view returns (address) {\r\n        return getAppBase(appId());\r\n    }\r\n\r\n    /**\r\n     * @dev ERC897, whether it is a forwarding (1) or an upgradeable (2) proxy\r\n     */\r\n    function proxyType() public pure returns (uint256 proxyTypeId) {\r\n        return UPGRADEABLE;\r\n    }\r\n}\r\n\r\n// File: contracts/apps/AppProxyPinned.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\n\r\n\r\n\r\ncontract AppProxyPinned is IsContract, AppProxyBase {\r\n    using UnstructuredStorage for bytes32;\r\n\r\n    // keccak256(\"aragonOS.appStorage.pinnedCode\")\r\n    bytes32 internal constant PINNED_CODE_POSITION = 0xdee64df20d65e53d7f51cb6ab6d921a0a6a638a91e942e1d8d02df28e31c038e;\r\n\r\n    /**\r\n    * @dev Initialize AppProxyPinned (makes it an un-upgradeable Aragon app)\r\n    * @param _kernel Reference to organization kernel for the app\r\n    * @param _appId Identifier for app\r\n    * @param _initializePayload Payload for call to be made after setup to initialize\r\n    */\r\n    constructor(IKernel _kernel, bytes32 _appId, bytes _initializePayload)\r\n        AppProxyBase(_kernel, _appId, _initializePayload)\r\n        public // solium-disable-line visibility-first\r\n    {\r\n        setPinnedCode(getAppBase(_appId));\r\n        require(isContract(pinnedCode()));\r\n    }\r\n\r\n    /**\r\n     * @dev ERC897, the address the proxy would delegate calls to\r\n     */\r\n    function implementation() public view returns (address) {\r\n        return pinnedCode();\r\n    }\r\n\r\n    /**\r\n     * @dev ERC897, whether it is a forwarding (1) or an upgradeable (2) proxy\r\n     */\r\n    function proxyType() public pure returns (uint256 proxyTypeId) {\r\n        return FORWARDING;\r\n    }\r\n\r\n    function setPinnedCode(address _pinnedCode) internal {\r\n        PINNED_CODE_POSITION.setStorageAddress(_pinnedCode);\r\n    }\r\n\r\n    function pinnedCode() internal view returns (address) {\r\n        return PINNED_CODE_POSITION.getStorageAddress();\r\n    }\r\n}\r\n\r\n// File: contracts/factory/AppProxyFactory.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\n\r\n\r\ncontract AppProxyFactory {\r\n    event NewAppProxy(address proxy, bool isUpgradeable, bytes32 appId);\r\n\r\n    /**\r\n    * @notice Create a new upgradeable app instance on `_kernel` with identifier `_appId`\r\n    * @param _kernel App's Kernel reference\r\n    * @param _appId Identifier for app\r\n    * @return AppProxyUpgradeable\r\n    */\r\n    function newAppProxy(IKernel _kernel, bytes32 _appId) public returns (AppProxyUpgradeable) {\r\n        return newAppProxy(_kernel, _appId, new bytes(0));\r\n    }\r\n\r\n    /**\r\n    * @notice Create a new upgradeable app instance on `_kernel` with identifier `_appId` and initialization payload `_initializePayload`\r\n    * @param _kernel App's Kernel reference\r\n    * @param _appId Identifier for app\r\n    * @return AppProxyUpgradeable\r\n    */\r\n    function newAppProxy(IKernel _kernel, bytes32 _appId, bytes _initializePayload) public returns (AppProxyUpgradeable) {\r\n        AppProxyUpgradeable proxy = new AppProxyUpgradeable(_kernel, _appId, _initializePayload);\r\n        emit NewAppProxy(address(proxy), true, _appId);\r\n        return proxy;\r\n    }\r\n\r\n    /**\r\n    * @notice Create a new pinned app instance on `_kernel` with identifier `_appId`\r\n    * @param _kernel App's Kernel reference\r\n    * @param _appId Identifier for app\r\n    * @return AppProxyPinned\r\n    */\r\n    function newAppProxyPinned(IKernel _kernel, bytes32 _appId) public returns (AppProxyPinned) {\r\n        return newAppProxyPinned(_kernel, _appId, new bytes(0));\r\n    }\r\n\r\n    /**\r\n    * @notice Create a new pinned app instance on `_kernel` with identifier `_appId` and initialization payload `_initializePayload`\r\n    * @param _kernel App's Kernel reference\r\n    * @param _appId Identifier for app\r\n    * @param _initializePayload Proxy initialization payload\r\n    * @return AppProxyPinned\r\n    */\r\n    function newAppProxyPinned(IKernel _kernel, bytes32 _appId, bytes _initializePayload) public returns (AppProxyPinned) {\r\n        AppProxyPinned proxy = new AppProxyPinned(_kernel, _appId, _initializePayload);\r\n        emit NewAppProxy(address(proxy), false, _appId);\r\n        return proxy;\r\n    }\r\n}\r\n\r\n// File: contracts/kernel/Kernel.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n// solium-disable-next-line max-len\r\ncontract Kernel is IKernel, KernelStorage, KernelAppIds, KernelNamespaceConstants, Petrifiable, IsContract, VaultRecoverable, AppProxyFactory, ACLSyntaxSugar {\r\n    /* Hardcoded constants to save gas\r\n    bytes32 public constant APP_MANAGER_ROLE = keccak256(\"APP_MANAGER_ROLE\");\r\n    */\r\n    bytes32 public constant APP_MANAGER_ROLE = 0xb6d92708f3d4817afc106147d969e229ced5c46e65e0a5002a0d391287762bd0;\r\n\r\n    string private constant ERROR_APP_NOT_CONTRACT = \"KERNEL_APP_NOT_CONTRACT\";\r\n    string private constant ERROR_INVALID_APP_CHANGE = \"KERNEL_INVALID_APP_CHANGE\";\r\n    string private constant ERROR_AUTH_FAILED = \"KERNEL_AUTH_FAILED\";\r\n\r\n    /**\r\n    * @dev Constructor that allows the deployer to choose if the base instance should be petrified immediately.\r\n    * @param _shouldPetrify Immediately petrify this instance so that it can never be initialized\r\n    */\r\n    constructor(bool _shouldPetrify) public {\r\n        if (_shouldPetrify) {\r\n            petrify();\r\n        }\r\n    }\r\n\r\n    /**\r\n    * @dev Initialize can only be called once. It saves the block number in which it was initialized.\r\n    * @notice Initialize this kernel instance along with its ACL and set `_permissionsCreator` as the entity that can create other permissions\r\n    * @param _baseAcl Address of base ACL app\r\n    * @param _permissionsCreator Entity that will be given permission over createPermission\r\n    */\r\n    function initialize(IACL _baseAcl, address _permissionsCreator) public onlyInit {\r\n        initialized();\r\n\r\n        // Set ACL base\r\n        _setApp(KERNEL_APP_BASES_NAMESPACE, KERNEL_DEFAULT_ACL_APP_ID, _baseAcl);\r\n\r\n        // Create ACL instance and attach it as the default ACL app\r\n        IACL acl = IACL(newAppProxy(this, KERNEL_DEFAULT_ACL_APP_ID));\r\n        acl.initialize(_permissionsCreator);\r\n        _setApp(KERNEL_APP_ADDR_NAMESPACE, KERNEL_DEFAULT_ACL_APP_ID, acl);\r\n\r\n        recoveryVaultAppId = KERNEL_DEFAULT_VAULT_APP_ID;\r\n    }\r\n\r\n    /**\r\n    * @dev Create a new instance of an app linked to this kernel\r\n    * @notice Create a new upgradeable instance of `_appId` app linked to the Kernel, setting its code to `_appBase`\r\n    * @param _appId Identifier for app\r\n    * @param _appBase Address of the app's base implementation\r\n    * @return AppProxy instance\r\n    */\r\n    function newAppInstance(bytes32 _appId, address _appBase)\r\n        public\r\n        auth(APP_MANAGER_ROLE, arr(KERNEL_APP_BASES_NAMESPACE, _appId))\r\n        returns (ERCProxy appProxy)\r\n    {\r\n        return newAppInstance(_appId, _appBase, new bytes(0), false);\r\n    }\r\n\r\n    /**\r\n    * @dev Create a new instance of an app linked to this kernel and set its base\r\n    *      implementation if it was not already set\r\n    * @notice Create a new upgradeable instance of `_appId` app linked to the Kernel, setting its code to `_appBase`. `_setDefault ? 'Also sets it as the default app instance.':''`\r\n    * @param _appId Identifier for app\r\n    * @param _appBase Address of the app's base implementation\r\n    * @param _initializePayload Payload for call made by the proxy during its construction to initialize\r\n    * @param _setDefault Whether the app proxy app is the default one.\r\n    *        Useful when the Kernel needs to know of an instance of a particular app,\r\n    *        like Vault for escape hatch mechanism.\r\n    * @return AppProxy instance\r\n    */\r\n    function newAppInstance(bytes32 _appId, address _appBase, bytes _initializePayload, bool _setDefault)\r\n        public\r\n        auth(APP_MANAGER_ROLE, arr(KERNEL_APP_BASES_NAMESPACE, _appId))\r\n        returns (ERCProxy appProxy)\r\n    {\r\n        _setAppIfNew(KERNEL_APP_BASES_NAMESPACE, _appId, _appBase);\r\n        appProxy = newAppProxy(this, _appId, _initializePayload);\r\n        // By calling setApp directly and not the internal functions, we make sure the params are checked\r\n        // and it will only succeed if sender has permissions to set something to the namespace.\r\n        if (_setDefault) {\r\n            setApp(KERNEL_APP_ADDR_NAMESPACE, _appId, appProxy);\r\n        }\r\n    }\r\n\r\n    /**\r\n    * @dev Create a new pinned instance of an app linked to this kernel\r\n    * @notice Create a new non-upgradeable instance of `_appId` app linked to the Kernel, setting its code to `_appBase`.\r\n    * @param _appId Identifier for app\r\n    * @param _appBase Address of the app's base implementation\r\n    * @return AppProxy instance\r\n    */\r\n    function newPinnedAppInstance(bytes32 _appId, address _appBase)\r\n        public\r\n        auth(APP_MANAGER_ROLE, arr(KERNEL_APP_BASES_NAMESPACE, _appId))\r\n        returns (ERCProxy appProxy)\r\n    {\r\n        return newPinnedAppInstance(_appId, _appBase, new bytes(0), false);\r\n    }\r\n\r\n    /**\r\n    * @dev Create a new pinned instance of an app linked to this kernel and set\r\n    *      its base implementation if it was not already set\r\n    * @notice Create a new non-upgradeable instance of `_appId` app linked to the Kernel, setting its code to `_appBase`. `_setDefault ? 'Also sets it as the default app instance.':''`\r\n    * @param _appId Identifier for app\r\n    * @param _appBase Address of the app's base implementation\r\n    * @param _initializePayload Payload for call made by the proxy during its construction to initialize\r\n    * @param _setDefault Whether the app proxy app is the default one.\r\n    *        Useful when the Kernel needs to know of an instance of a particular app,\r\n    *        like Vault for escape hatch mechanism.\r\n    * @return AppProxy instance\r\n    */\r\n    function newPinnedAppInstance(bytes32 _appId, address _appBase, bytes _initializePayload, bool _setDefault)\r\n        public\r\n        auth(APP_MANAGER_ROLE, arr(KERNEL_APP_BASES_NAMESPACE, _appId))\r\n        returns (ERCProxy appProxy)\r\n    {\r\n        _setAppIfNew(KERNEL_APP_BASES_NAMESPACE, _appId, _appBase);\r\n        appProxy = newAppProxyPinned(this, _appId, _initializePayload);\r\n        // By calling setApp directly and not the internal functions, we make sure the params are checked\r\n        // and it will only succeed if sender has permissions to set something to the namespace.\r\n        if (_setDefault) {\r\n            setApp(KERNEL_APP_ADDR_NAMESPACE, _appId, appProxy);\r\n        }\r\n    }\r\n\r\n    /**\r\n    * @dev Set the resolving address of an app instance or base implementation\r\n    * @notice Set the resolving address of `_appId` in namespace `_namespace` to `_app`\r\n    * @param _namespace App namespace to use\r\n    * @param _appId Identifier for app\r\n    * @param _app Address of the app instance or base implementation\r\n    * @return ID of app\r\n    */\r\n    function setApp(bytes32 _namespace, bytes32 _appId, address _app)\r\n        public\r\n        auth(APP_MANAGER_ROLE, arr(_namespace, _appId))\r\n    {\r\n        _setApp(_namespace, _appId, _app);\r\n    }\r\n\r\n    /**\r\n    * @dev Set the default vault id for the escape hatch mechanism\r\n    * @param _recoveryVaultAppId Identifier of the recovery vault app\r\n    */\r\n    function setRecoveryVaultAppId(bytes32 _recoveryVaultAppId)\r\n        public\r\n        auth(APP_MANAGER_ROLE, arr(KERNEL_APP_ADDR_NAMESPACE, _recoveryVaultAppId))\r\n    {\r\n        recoveryVaultAppId = _recoveryVaultAppId;\r\n    }\r\n\r\n    // External access to default app id and namespace constants to mimic default getters for constants\r\n    /* solium-disable function-order, mixedcase */\r\n    function CORE_NAMESPACE() external pure returns (bytes32) { return KERNEL_CORE_NAMESPACE; }\r\n    function APP_BASES_NAMESPACE() external pure returns (bytes32) { return KERNEL_APP_BASES_NAMESPACE; }\r\n    function APP_ADDR_NAMESPACE() external pure returns (bytes32) { return KERNEL_APP_ADDR_NAMESPACE; }\r\n    function KERNEL_APP_ID() external pure returns (bytes32) { return KERNEL_CORE_APP_ID; }\r\n    function DEFAULT_ACL_APP_ID() external pure returns (bytes32) { return KERNEL_DEFAULT_ACL_APP_ID; }\r\n    /* solium-enable function-order, mixedcase */\r\n\r\n    /**\r\n    * @dev Get the address of an app instance or base implementation\r\n    * @param _namespace App namespace to use\r\n    * @param _appId Identifier for app\r\n    * @return Address of the app\r\n    */\r\n    function getApp(bytes32 _namespace, bytes32 _appId) public view returns (address) {\r\n        return apps[_namespace][_appId];\r\n    }\r\n\r\n    /**\r\n    * @dev Get the address of the recovery Vault instance (to recover funds)\r\n    * @return Address of the Vault\r\n    */\r\n    function getRecoveryVault() public view returns (address) {\r\n        return apps[KERNEL_APP_ADDR_NAMESPACE][recoveryVaultAppId];\r\n    }\r\n\r\n    /**\r\n    * @dev Get the installed ACL app\r\n    * @return ACL app\r\n    */\r\n    function acl() public view returns (IACL) {\r\n        return IACL(getApp(KERNEL_APP_ADDR_NAMESPACE, KERNEL_DEFAULT_ACL_APP_ID));\r\n    }\r\n\r\n    /**\r\n    * @dev Function called by apps to check ACL on kernel or to check permission status\r\n    * @param _who Sender of the original call\r\n    * @param _where Address of the app\r\n    * @param _what Identifier for a group of actions in app\r\n    * @param _how Extra data for ACL auth\r\n    * @return Boolean indicating whether the ACL allows the role or not.\r\n    *         Always returns false if the kernel hasn't been initialized yet.\r\n    */\r\n    function hasPermission(address _who, address _where, bytes32 _what, bytes _how) public view returns (bool) {\r\n        IACL defaultAcl = acl();\r\n        return address(defaultAcl) != address(0) && // Poor man's initialization check (saves gas)\r\n            defaultAcl.hasPermission(_who, _where, _what, _how);\r\n    }\r\n\r\n    function _setApp(bytes32 _namespace, bytes32 _appId, address _app) internal {\r\n        require(isContract(_app), ERROR_APP_NOT_CONTRACT);\r\n        apps[_namespace][_appId] = _app;\r\n        emit SetApp(_namespace, _appId, _app);\r\n    }\r\n\r\n    function _setAppIfNew(bytes32 _namespace, bytes32 _appId, address _app) internal {\r\n        address app = getApp(_namespace, _appId);\r\n        if (app != address(0)) {\r\n            // The only way to set an app is if it passes the isContract check, so no need to check it again\r\n            require(app == _app, ERROR_INVALID_APP_CHANGE);\r\n        } else {\r\n            _setApp(_namespace, _appId, _app);\r\n        }\r\n    }\r\n\r\n    modifier auth(bytes32 _role, uint256[] memory _params) {\r\n        require(\r\n            hasPermission(msg.sender, address(this), _role, ConversionHelpers.dangerouslyCastUintArrayToBytes(_params)),\r\n            ERROR_AUTH_FAILED\r\n        );\r\n        _;\r\n    }\r\n}\r\n\r\n// File: contracts/kernel/KernelProxy.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\ncontract KernelProxy is IKernelEvents, KernelStorage, KernelAppIds, KernelNamespaceConstants, IsContract, DepositableDelegateProxy {\r\n    /**\r\n    * @dev KernelProxy is a proxy contract to a kernel implementation. The implementation\r\n    *      can update the reference, which effectively upgrades the contract\r\n    * @param _kernelImpl Address of the contract used as implementation for kernel\r\n    */\r\n    constructor(IKernel _kernelImpl) public {\r\n        require(isContract(address(_kernelImpl)));\r\n        apps[KERNEL_CORE_NAMESPACE][KERNEL_CORE_APP_ID] = _kernelImpl;\r\n\r\n        // Note that emitting this event is important for verifying that a KernelProxy instance\r\n        // was never upgraded to a malicious Kernel logic contract over its lifespan.\r\n        // This starts the \"chain of trust\", that can be followed through later SetApp() events\r\n        // emitted during kernel upgrades.\r\n        emit SetApp(KERNEL_CORE_NAMESPACE, KERNEL_CORE_APP_ID, _kernelImpl);\r\n    }\r\n\r\n    /**\r\n     * @dev ERC897, whether it is a forwarding (1) or an upgradeable (2) proxy\r\n     */\r\n    function proxyType() public pure returns (uint256 proxyTypeId) {\r\n        return UPGRADEABLE;\r\n    }\r\n\r\n    /**\r\n    * @dev ERC897, the address the proxy would delegate calls to\r\n    */\r\n    function implementation() public view returns (address) {\r\n        return apps[KERNEL_CORE_NAMESPACE][KERNEL_CORE_APP_ID];\r\n    }\r\n}\r\n\r\n// File: contracts/common/Autopetrified.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n\r\ncontract Autopetrified is Petrifiable {\r\n    constructor() public {\r\n        // Immediately petrify base (non-proxy) instances of inherited contracts on deploy.\r\n        // This renders them uninitializable (and unusable without a proxy).\r\n        petrify();\r\n    }\r\n}\r\n\r\n// File: contracts/common/ReentrancyGuard.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n\r\ncontract ReentrancyGuard {\r\n    using UnstructuredStorage for bytes32;\r\n\r\n    /* Hardcoded constants to save gas\r\n    bytes32 internal constant REENTRANCY_MUTEX_POSITION = keccak256(\"aragonOS.reentrancyGuard.mutex\");\r\n    */\r\n    bytes32 private constant REENTRANCY_MUTEX_POSITION = 0xe855346402235fdd185c890e68d2c4ecad599b88587635ee285bce2fda58dacb;\r\n\r\n    string private constant ERROR_REENTRANT = \"REENTRANCY_REENTRANT_CALL\";\r\n\r\n    modifier nonReentrant() {\r\n        // Ensure mutex is unlocked\r\n        require(!REENTRANCY_MUTEX_POSITION.getStorageBool(), ERROR_REENTRANT);\r\n\r\n        // Lock mutex before function call\r\n        REENTRANCY_MUTEX_POSITION.setStorageBool(true);\r\n\r\n        // Perform function call\r\n        _;\r\n\r\n        // Unlock mutex after function call\r\n        REENTRANCY_MUTEX_POSITION.setStorageBool(false);\r\n    }\r\n}\r\n\r\n// File: contracts/evmscript/IEVMScriptExecutor.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\ninterface IEVMScriptExecutor {\r\n    function execScript(bytes script, bytes input, address[] blacklist) external returns (bytes);\r\n    function executorType() external pure returns (bytes32);\r\n}\r\n\r\n// File: contracts/evmscript/IEVMScriptRegistry.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n\r\ncontract EVMScriptRegistryConstants {\r\n    /* Hardcoded constants to save gas\r\n    bytes32 internal constant EVMSCRIPT_REGISTRY_APP_ID = apmNamehash(\"evmreg\");\r\n    */\r\n    bytes32 internal constant EVMSCRIPT_REGISTRY_APP_ID = 0xddbcfd564f642ab5627cf68b9b7d374fb4f8a36e941a75d89c87998cef03bd61;\r\n}\r\n\r\n\r\ninterface IEVMScriptRegistry {\r\n    function addScriptExecutor(IEVMScriptExecutor executor) external returns (uint id);\r\n    function disableScriptExecutor(uint256 executorId) external;\r\n\r\n    // TODO: this should be external\r\n    // See https://github.com/ethereum/solidity/issues/4832\r\n    function getScriptExecutor(bytes script) public view returns (IEVMScriptExecutor);\r\n}\r\n\r\n// File: contracts/evmscript/EVMScriptRunner.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\ncontract EVMScriptRunner is AppStorage, Initializable, EVMScriptRegistryConstants, KernelNamespaceConstants {\r\n    string private constant ERROR_EXECUTOR_UNAVAILABLE = \"EVMRUN_EXECUTOR_UNAVAILABLE\";\r\n    string private constant ERROR_PROTECTED_STATE_MODIFIED = \"EVMRUN_PROTECTED_STATE_MODIFIED\";\r\n\r\n    /* This is manually crafted in assembly\r\n    string private constant ERROR_EXECUTOR_INVALID_RETURN = \"EVMRUN_EXECUTOR_INVALID_RETURN\";\r\n    */\r\n\r\n    event ScriptResult(address indexed executor, bytes script, bytes input, bytes returnData);\r\n\r\n    function getEVMScriptExecutor(bytes _script) public view returns (IEVMScriptExecutor) {\r\n        return IEVMScriptExecutor(getEVMScriptRegistry().getScriptExecutor(_script));\r\n    }\r\n\r\n    function getEVMScriptRegistry() public view returns (IEVMScriptRegistry) {\r\n        address registryAddr = kernel().getApp(KERNEL_APP_ADDR_NAMESPACE, EVMSCRIPT_REGISTRY_APP_ID);\r\n        return IEVMScriptRegistry(registryAddr);\r\n    }\r\n\r\n    function runScript(bytes _script, bytes _input, address[] _blacklist)\r\n        internal\r\n        isInitialized\r\n        protectState\r\n        returns (bytes)\r\n    {\r\n        IEVMScriptExecutor executor = getEVMScriptExecutor(_script);\r\n        require(address(executor) != address(0), ERROR_EXECUTOR_UNAVAILABLE);\r\n\r\n        bytes4 sig = executor.execScript.selector;\r\n        bytes memory data = abi.encodeWithSelector(sig, _script, _input, _blacklist);\r\n\r\n        bytes memory output;\r\n        assembly {\r\n            let success := delegatecall(\r\n                gas,                // forward all gas\r\n                executor,           // address\r\n                add(data, 0x20),    // calldata start\r\n                mload(data),        // calldata length\r\n                0,                  // don't write output (we'll handle this ourselves)\r\n                0                   // don't write output\r\n            )\r\n\r\n            output := mload(0x40) // free mem ptr get\r\n\r\n            switch success\r\n            case 0 {\r\n                // If the call errored, forward its full error data\r\n                returndatacopy(output, 0, returndatasize)\r\n                revert(output, returndatasize)\r\n            }\r\n            default {\r\n                switch gt(returndatasize, 0x3f)\r\n                case 0 {\r\n                    // Need at least 0x40 bytes returned for properly ABI-encoded bytes values,\r\n                    // revert with \"EVMRUN_EXECUTOR_INVALID_RETURN\"\r\n                    // See remix: doing a `revert(\"EVMRUN_EXECUTOR_INVALID_RETURN\")` always results in\r\n                    // this memory layout\r\n                    mstore(output, 0x08c379a000000000000000000000000000000000000000000000000000000000)         // error identifier\r\n                    mstore(add(output, 0x04), 0x0000000000000000000000000000000000000000000000000000000000000020) // starting offset\r\n                    mstore(add(output, 0x24), 0x000000000000000000000000000000000000000000000000000000000000001e) // reason length\r\n                    mstore(add(output, 0x44), 0x45564d52554e5f4558454355544f525f494e56414c49445f52455455524e0000) // reason\r\n\r\n                    revert(output, 100) // 100 = 4 + 3 * 32 (error identifier + 3 words for the ABI encoded error)\r\n                }\r\n                default {\r\n                    // Copy result\r\n                    //\r\n                    // Needs to perform an ABI decode for the expected `bytes` return type of\r\n                    // `executor.execScript()` as solidity will automatically ABI encode the returned bytes as:\r\n                    //    [ position of the first dynamic length return value = 0x20 (32 bytes) ]\r\n                    //    [ output length (32 bytes) ]\r\n                    //    [ output content (N bytes) ]\r\n                    //\r\n                    // Perform the ABI decode by ignoring the first 32 bytes of the return data\r\n                    let copysize := sub(returndatasize, 0x20)\r\n                    returndatacopy(output, 0x20, copysize)\r\n\r\n                    mstore(0x40, add(output, copysize)) // free mem ptr set\r\n                }\r\n            }\r\n        }\r\n\r\n        emit ScriptResult(address(executor), _script, _input, output);\r\n\r\n        return output;\r\n    }\r\n\r\n    modifier protectState {\r\n        address preKernel = address(kernel());\r\n        bytes32 preAppId = appId();\r\n        _; // exec\r\n        require(address(kernel()) == preKernel, ERROR_PROTECTED_STATE_MODIFIED);\r\n        require(appId() == preAppId, ERROR_PROTECTED_STATE_MODIFIED);\r\n    }\r\n}\r\n\r\n// File: contracts/apps/AragonApp.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n// Contracts inheriting from AragonApp are, by default, immediately petrified upon deployment so\r\n// that they can never be initialized.\r\n// Unless overriden, this behaviour enforces those contracts to be usable only behind an AppProxy.\r\n// ReentrancyGuard, EVMScriptRunner, and ACLSyntaxSugar are not directly used by this contract, but\r\n// are included so that they are automatically usable by subclassing contracts\r\ncontract AragonApp is AppStorage, Autopetrified, VaultRecoverable, ReentrancyGuard, EVMScriptRunner, ACLSyntaxSugar {\r\n    string private constant ERROR_AUTH_FAILED = \"APP_AUTH_FAILED\";\r\n\r\n    modifier auth(bytes32 _role) {\r\n        require(canPerform(msg.sender, _role, new uint256[](0)), ERROR_AUTH_FAILED);\r\n        _;\r\n    }\r\n\r\n    modifier authP(bytes32 _role, uint256[] _params) {\r\n        require(canPerform(msg.sender, _role, _params), ERROR_AUTH_FAILED);\r\n        _;\r\n    }\r\n\r\n    /**\r\n    * @dev Check whether an action can be performed by a sender for a particular role on this app\r\n    * @param _sender Sender of the call\r\n    * @param _role Role on this app\r\n    * @param _params Permission params for the role\r\n    * @return Boolean indicating whether the sender has the permissions to perform the action.\r\n    *         Always returns false if the app hasn't been initialized yet.\r\n    */\r\n    function canPerform(address _sender, bytes32 _role, uint256[] _params) public view returns (bool) {\r\n        if (!hasInitialized()) {\r\n            return false;\r\n        }\r\n\r\n        IKernel linkedKernel = kernel();\r\n        if (address(linkedKernel) == address(0)) {\r\n            return false;\r\n        }\r\n\r\n        return linkedKernel.hasPermission(\r\n            _sender,\r\n            address(this),\r\n            _role,\r\n            ConversionHelpers.dangerouslyCastUintArrayToBytes(_params)\r\n        );\r\n    }\r\n\r\n    /**\r\n    * @dev Get the recovery vault for the app\r\n    * @return Recovery vault address for the app\r\n    */\r\n    function getRecoveryVault() public view returns (address) {\r\n        // Funds recovery via a vault is only available when used with a kernel\r\n        return kernel().getRecoveryVault(); // if kernel is not set, it will revert\r\n    }\r\n}\r\n\r\n// File: contracts/acl/IACLOracle.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\ninterface IACLOracle {\r\n    function canPerform(address who, address where, bytes32 what, uint256[] how) external view returns (bool);\r\n}\r\n\r\n// File: contracts/acl/ACL.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n/* solium-disable function-order */\r\n// Allow public initialize() to be first\r\ncontract ACL is IACL, TimeHelpers, AragonApp, ACLHelpers {\r\n    /* Hardcoded constants to save gas\r\n    bytes32 public constant CREATE_PERMISSIONS_ROLE = keccak256(\"CREATE_PERMISSIONS_ROLE\");\r\n    */\r\n    bytes32 public constant CREATE_PERMISSIONS_ROLE = 0x0b719b33c83b8e5d300c521cb8b54ae9bd933996a14bef8c2f4e0285d2d2400a;\r\n\r\n    enum Op { NONE, EQ, NEQ, GT, LT, GTE, LTE, RET, NOT, AND, OR, XOR, IF_ELSE } // op types\r\n\r\n    struct Param {\r\n        uint8 id;\r\n        uint8 op;\r\n        uint240 value; // even though value is an uint240 it can store addresses\r\n        // in the case of 32 byte hashes losing 2 bytes precision isn't a huge deal\r\n        // op and id take less than 1 byte each so it can be kept in 1 sstore\r\n    }\r\n\r\n    uint8 internal constant BLOCK_NUMBER_PARAM_ID = 200;\r\n    uint8 internal constant TIMESTAMP_PARAM_ID    = 201;\r\n    // 202 is unused\r\n    uint8 internal constant ORACLE_PARAM_ID       = 203;\r\n    uint8 internal constant LOGIC_OP_PARAM_ID     = 204;\r\n    uint8 internal constant PARAM_VALUE_PARAM_ID  = 205;\r\n    // TODO: Add execution times param type?\r\n\r\n    /* Hardcoded constant to save gas\r\n    bytes32 public constant EMPTY_PARAM_HASH = keccak256(uint256(0));\r\n    */\r\n    bytes32 public constant EMPTY_PARAM_HASH = 0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563;\r\n    bytes32 public constant NO_PERMISSION = bytes32(0);\r\n    address public constant ANY_ENTITY = address(-1);\r\n    address public constant BURN_ENTITY = address(1); // address(0) is already used as \"no permission manager\"\r\n\r\n    uint256 internal constant ORACLE_CHECK_GAS = 30000;\r\n\r\n    string private constant ERROR_AUTH_INIT_KERNEL = \"ACL_AUTH_INIT_KERNEL\";\r\n    string private constant ERROR_AUTH_NO_MANAGER = \"ACL_AUTH_NO_MANAGER\";\r\n    string private constant ERROR_EXISTENT_MANAGER = \"ACL_EXISTENT_MANAGER\";\r\n\r\n    // Whether someone has a permission\r\n    mapping (bytes32 => bytes32) internal permissions; // permissions hash => params hash\r\n    mapping (bytes32 => Param[]) internal permissionParams; // params hash => params\r\n\r\n    // Who is the manager of a permission\r\n    mapping (bytes32 => address) internal permissionManager;\r\n\r\n    event SetPermission(address indexed entity, address indexed app, bytes32 indexed role, bool allowed);\r\n    event SetPermissionParams(address indexed entity, address indexed app, bytes32 indexed role, bytes32 paramsHash);\r\n    event ChangePermissionManager(address indexed app, bytes32 indexed role, address indexed manager);\r\n\r\n    modifier onlyPermissionManager(address _app, bytes32 _role) {\r\n        require(msg.sender == getPermissionManager(_app, _role), ERROR_AUTH_NO_MANAGER);\r\n        _;\r\n    }\r\n\r\n    modifier noPermissionManager(address _app, bytes32 _role) {\r\n        // only allow permission creation (or re-creation) when there is no manager\r\n        require(getPermissionManager(_app, _role) == address(0), ERROR_EXISTENT_MANAGER);\r\n        _;\r\n    }\r\n\r\n    /**\r\n    * @dev Initialize can only be called once. It saves the block number in which it was initialized.\r\n    * @notice Initialize an ACL instance and set `_permissionsCreator` as the entity that can create other permissions\r\n    * @param _permissionsCreator Entity that will be given permission over createPermission\r\n    */\r\n    function initialize(address _permissionsCreator) public onlyInit {\r\n        initialized();\r\n        require(msg.sender == address(kernel()), ERROR_AUTH_INIT_KERNEL);\r\n\r\n        _createPermission(_permissionsCreator, this, CREATE_PERMISSIONS_ROLE, _permissionsCreator);\r\n    }\r\n\r\n    /**\r\n    * @dev Creates a permission that wasn't previously set and managed.\r\n    *      If a created permission is removed it is possible to reset it with createPermission.\r\n    *      This is the **ONLY** way to create permissions and set managers to permissions that don't\r\n    *      have a manager.\r\n    *      In terms of the ACL being initialized, this function implicitly protects all the other\r\n    *      state-changing external functions, as they all require the sender to be a manager.\r\n    * @notice Create a new permission granting `_entity` the ability to perform actions requiring `_role` on `_app`, setting `_manager` as the permission's manager\r\n    * @param _entity Address of the whitelisted entity that will be able to perform the role\r\n    * @param _app Address of the app in which the role will be allowed (requires app to depend on kernel for ACL)\r\n    * @param _role Identifier for the group of actions in app given access to perform\r\n    * @param _manager Address of the entity that will be able to grant and revoke the permission further.\r\n    */\r\n    function createPermission(address _entity, address _app, bytes32 _role, address _manager)\r\n        external\r\n        auth(CREATE_PERMISSIONS_ROLE)\r\n        noPermissionManager(_app, _role)\r\n    {\r\n        _createPermission(_entity, _app, _role, _manager);\r\n    }\r\n\r\n    /**\r\n    * @dev Grants permission if allowed. This requires `msg.sender` to be the permission manager\r\n    * @notice Grant `_entity` the ability to perform actions requiring `_role` on `_app`\r\n    * @param _entity Address of the whitelisted entity that will be able to perform the role\r\n    * @param _app Address of the app in which the role will be allowed (requires app to depend on kernel for ACL)\r\n    * @param _role Identifier for the group of actions in app given access to perform\r\n    */\r\n    function grantPermission(address _entity, address _app, bytes32 _role)\r\n        external\r\n    {\r\n        grantPermissionP(_entity, _app, _role, new uint256[](0));\r\n    }\r\n\r\n    /**\r\n    * @dev Grants a permission with parameters if allowed. This requires `msg.sender` to be the permission manager\r\n    * @notice Grant `_entity` the ability to perform actions requiring `_role` on `_app`\r\n    * @param _entity Address of the whitelisted entity that will be able to perform the role\r\n    * @param _app Address of the app in which the role will be allowed (requires app to depend on kernel for ACL)\r\n    * @param _role Identifier for the group of actions in app given access to perform\r\n    * @param _params Permission parameters\r\n    */\r\n    function grantPermissionP(address _entity, address _app, bytes32 _role, uint256[] _params)\r\n        public\r\n        onlyPermissionManager(_app, _role)\r\n    {\r\n        bytes32 paramsHash = _params.length > 0 ? _saveParams(_params) : EMPTY_PARAM_HASH;\r\n        _setPermission(_entity, _app, _role, paramsHash);\r\n    }\r\n\r\n    /**\r\n    * @dev Revokes permission if allowed. This requires `msg.sender` to be the the permission manager\r\n    * @notice Revoke from `_entity` the ability to perform actions requiring `_role` on `_app`\r\n    * @param _entity Address of the whitelisted entity to revoke access from\r\n    * @param _app Address of the app in which the role will be revoked\r\n    * @param _role Identifier for the group of actions in app being revoked\r\n    */\r\n    function revokePermission(address _entity, address _app, bytes32 _role)\r\n        external\r\n        onlyPermissionManager(_app, _role)\r\n    {\r\n        _setPermission(_entity, _app, _role, NO_PERMISSION);\r\n    }\r\n\r\n    /**\r\n    * @notice Set `_newManager` as the manager of `_role` in `_app`\r\n    * @param _newManager Address for the new manager\r\n    * @param _app Address of the app in which the permission management is being transferred\r\n    * @param _role Identifier for the group of actions being transferred\r\n    */\r\n    function setPermissionManager(address _newManager, address _app, bytes32 _role)\r\n        external\r\n        onlyPermissionManager(_app, _role)\r\n    {\r\n        _setPermissionManager(_newManager, _app, _role);\r\n    }\r\n\r\n    /**\r\n    * @notice Remove the manager of `_role` in `_app`\r\n    * @param _app Address of the app in which the permission is being unmanaged\r\n    * @param _role Identifier for the group of actions being unmanaged\r\n    */\r\n    function removePermissionManager(address _app, bytes32 _role)\r\n        external\r\n        onlyPermissionManager(_app, _role)\r\n    {\r\n        _setPermissionManager(address(0), _app, _role);\r\n    }\r\n\r\n    /**\r\n    * @notice Burn non-existent `_role` in `_app`, so no modification can be made to it (grant, revoke, permission manager)\r\n    * @param _app Address of the app in which the permission is being burned\r\n    * @param _role Identifier for the group of actions being burned\r\n    */\r\n    function createBurnedPermission(address _app, bytes32 _role)\r\n        external\r\n        auth(CREATE_PERMISSIONS_ROLE)\r\n        noPermissionManager(_app, _role)\r\n    {\r\n        _setPermissionManager(BURN_ENTITY, _app, _role);\r\n    }\r\n\r\n    /**\r\n    * @notice Burn `_role` in `_app`, so no modification can be made to it (grant, revoke, permission manager)\r\n    * @param _app Address of the app in which the permission is being burned\r\n    * @param _role Identifier for the group of actions being burned\r\n    */\r\n    function burnPermissionManager(address _app, bytes32 _role)\r\n        external\r\n        onlyPermissionManager(_app, _role)\r\n    {\r\n        _setPermissionManager(BURN_ENTITY, _app, _role);\r\n    }\r\n\r\n    /**\r\n     * @notice Get parameters for permission array length\r\n     * @param _entity Address of the whitelisted entity that will be able to perform the role\r\n     * @param _app Address of the app\r\n     * @param _role Identifier for a group of actions in app\r\n     * @return Length of the array\r\n     */\r\n    function getPermissionParamsLength(address _entity, address _app, bytes32 _role) external view returns (uint) {\r\n        return permissionParams[permissions[permissionHash(_entity, _app, _role)]].length;\r\n    }\r\n\r\n    /**\r\n    * @notice Get parameter for permission\r\n    * @param _entity Address of the whitelisted entity that will be able to perform the role\r\n    * @param _app Address of the app\r\n    * @param _role Identifier for a group of actions in app\r\n    * @param _index Index of parameter in the array\r\n    * @return Parameter (id, op, value)\r\n    */\r\n    function getPermissionParam(address _entity, address _app, bytes32 _role, uint _index)\r\n        external\r\n        view\r\n        returns (uint8, uint8, uint240)\r\n    {\r\n        Param storage param = permissionParams[permissions[permissionHash(_entity, _app, _role)]][_index];\r\n        return (param.id, param.op, param.value);\r\n    }\r\n\r\n    /**\r\n    * @dev Get manager for permission\r\n    * @param _app Address of the app\r\n    * @param _role Identifier for a group of actions in app\r\n    * @return address of the manager for the permission\r\n    */\r\n    function getPermissionManager(address _app, bytes32 _role) public view returns (address) {\r\n        return permissionManager[roleHash(_app, _role)];\r\n    }\r\n\r\n    /**\r\n    * @dev Function called by apps to check ACL on kernel or to check permission statu\r\n    * @param _who Sender of the original call\r\n    * @param _where Address of the app\r\n    * @param _where Identifier for a group of actions in app\r\n    * @param _how Permission parameters\r\n    * @return boolean indicating whether the ACL allows the role or not\r\n    */\r\n    function hasPermission(address _who, address _where, bytes32 _what, bytes memory _how) public view returns (bool) {\r\n        return hasPermission(_who, _where, _what, ConversionHelpers.dangerouslyCastBytesToUintArray(_how));\r\n    }\r\n\r\n    function hasPermission(address _who, address _where, bytes32 _what, uint256[] memory _how) public view returns (bool) {\r\n        bytes32 whoParams = permissions[permissionHash(_who, _where, _what)];\r\n        if (whoParams != NO_PERMISSION && evalParams(whoParams, _who, _where, _what, _how)) {\r\n            return true;\r\n        }\r\n\r\n        bytes32 anyParams = permissions[permissionHash(ANY_ENTITY, _where, _what)];\r\n        if (anyParams != NO_PERMISSION && evalParams(anyParams, ANY_ENTITY, _where, _what, _how)) {\r\n            return true;\r\n        }\r\n\r\n        return false;\r\n    }\r\n\r\n    function hasPermission(address _who, address _where, bytes32 _what) public view returns (bool) {\r\n        uint256[] memory empty = new uint256[](0);\r\n        return hasPermission(_who, _where, _what, empty);\r\n    }\r\n\r\n    function evalParams(\r\n        bytes32 _paramsHash,\r\n        address _who,\r\n        address _where,\r\n        bytes32 _what,\r\n        uint256[] _how\r\n    ) public view returns (bool)\r\n    {\r\n        if (_paramsHash == EMPTY_PARAM_HASH) {\r\n            return true;\r\n        }\r\n\r\n        return _evalParam(_paramsHash, 0, _who, _where, _what, _how);\r\n    }\r\n\r\n    /**\r\n    * @dev Internal createPermission for access inside the kernel (on instantiation)\r\n    */\r\n    function _createPermission(address _entity, address _app, bytes32 _role, address _manager) internal {\r\n        _setPermission(_entity, _app, _role, EMPTY_PARAM_HASH);\r\n        _setPermissionManager(_manager, _app, _role);\r\n    }\r\n\r\n    /**\r\n    * @dev Internal function called to actually save the permission\r\n    */\r\n    function _setPermission(address _entity, address _app, bytes32 _role, bytes32 _paramsHash) internal {\r\n        permissions[permissionHash(_entity, _app, _role)] = _paramsHash;\r\n        bool entityHasPermission = _paramsHash != NO_PERMISSION;\r\n        bool permissionHasParams = entityHasPermission && _paramsHash != EMPTY_PARAM_HASH;\r\n\r\n        emit SetPermission(_entity, _app, _role, entityHasPermission);\r\n        if (permissionHasParams) {\r\n            emit SetPermissionParams(_entity, _app, _role, _paramsHash);\r\n        }\r\n    }\r\n\r\n    function _saveParams(uint256[] _encodedParams) internal returns (bytes32) {\r\n        bytes32 paramHash = keccak256(abi.encodePacked(_encodedParams));\r\n        Param[] storage params = permissionParams[paramHash];\r\n\r\n        if (params.length == 0) { // params not saved before\r\n            for (uint256 i = 0; i < _encodedParams.length; i++) {\r\n                uint256 encodedParam = _encodedParams[i];\r\n                Param memory param = Param(decodeParamId(encodedParam), decodeParamOp(encodedParam), uint240(encodedParam));\r\n                params.push(param);\r\n            }\r\n        }\r\n\r\n        return paramHash;\r\n    }\r\n\r\n    function _evalParam(\r\n        bytes32 _paramsHash,\r\n        uint32 _paramId,\r\n        address _who,\r\n        address _where,\r\n        bytes32 _what,\r\n        uint256[] _how\r\n    ) internal view returns (bool)\r\n    {\r\n        if (_paramId >= permissionParams[_paramsHash].length) {\r\n            return false; // out of bounds\r\n        }\r\n\r\n        Param memory param = permissionParams[_paramsHash][_paramId];\r\n\r\n        if (param.id == LOGIC_OP_PARAM_ID) {\r\n            return _evalLogic(param, _paramsHash, _who, _where, _what, _how);\r\n        }\r\n\r\n        uint256 value;\r\n        uint256 comparedTo = uint256(param.value);\r\n\r\n        // get value\r\n        if (param.id == ORACLE_PARAM_ID) {\r\n            value = checkOracle(IACLOracle(param.value), _who, _where, _what, _how) ? 1 : 0;\r\n            comparedTo = 1;\r\n        } else if (param.id == BLOCK_NUMBER_PARAM_ID) {\r\n            value = getBlockNumber();\r\n        } else if (param.id == TIMESTAMP_PARAM_ID) {\r\n            value = getTimestamp();\r\n        } else if (param.id == PARAM_VALUE_PARAM_ID) {\r\n            value = uint256(param.value);\r\n        } else {\r\n            if (param.id >= _how.length) {\r\n                return false;\r\n            }\r\n            value = uint256(uint240(_how[param.id])); // force lost precision\r\n        }\r\n\r\n        if (Op(param.op) == Op.RET) {\r\n            return uint256(value) > 0;\r\n        }\r\n\r\n        return compare(value, Op(param.op), comparedTo);\r\n    }\r\n\r\n    function _evalLogic(Param _param, bytes32 _paramsHash, address _who, address _where, bytes32 _what, uint256[] _how)\r\n        internal\r\n        view\r\n        returns (bool)\r\n    {\r\n        if (Op(_param.op) == Op.IF_ELSE) {\r\n            uint32 conditionParam;\r\n            uint32 successParam;\r\n            uint32 failureParam;\r\n\r\n            (conditionParam, successParam, failureParam) = decodeParamsList(uint256(_param.value));\r\n            bool result = _evalParam(_paramsHash, conditionParam, _who, _where, _what, _how);\r\n\r\n            return _evalParam(_paramsHash, result ? successParam : failureParam, _who, _where, _what, _how);\r\n        }\r\n\r\n        uint32 param1;\r\n        uint32 param2;\r\n\r\n        (param1, param2,) = decodeParamsList(uint256(_param.value));\r\n        bool r1 = _evalParam(_paramsHash, param1, _who, _where, _what, _how);\r\n\r\n        if (Op(_param.op) == Op.NOT) {\r\n            return !r1;\r\n        }\r\n\r\n        if (r1 && Op(_param.op) == Op.OR) {\r\n            return true;\r\n        }\r\n\r\n        if (!r1 && Op(_param.op) == Op.AND) {\r\n            return false;\r\n        }\r\n\r\n        bool r2 = _evalParam(_paramsHash, param2, _who, _where, _what, _how);\r\n\r\n        if (Op(_param.op) == Op.XOR) {\r\n            return r1 != r2;\r\n        }\r\n\r\n        return r2; // both or and and depend on result of r2 after checks\r\n    }\r\n\r\n    function compare(uint256 _a, Op _op, uint256 _b) internal pure returns (bool) {\r\n        if (_op == Op.EQ)  return _a == _b;                              // solium-disable-line lbrace\r\n        if (_op == Op.NEQ) return _a != _b;                              // solium-disable-line lbrace\r\n        if (_op == Op.GT)  return _a > _b;                               // solium-disable-line lbrace\r\n        if (_op == Op.LT)  return _a < _b;                               // solium-disable-line lbrace\r\n        if (_op == Op.GTE) return _a >= _b;                              // solium-disable-line lbrace\r\n        if (_op == Op.LTE) return _a <= _b;                              // solium-disable-line lbrace\r\n        return false;\r\n    }\r\n\r\n    function checkOracle(IACLOracle _oracleAddr, address _who, address _where, bytes32 _what, uint256[] _how) internal view returns (bool) {\r\n        bytes4 sig = _oracleAddr.canPerform.selector;\r\n\r\n        // a raw call is required so we can return false if the call reverts, rather than reverting\r\n        bytes memory checkCalldata = abi.encodeWithSelector(sig, _who, _where, _what, _how);\r\n        uint256 oracleCheckGas = ORACLE_CHECK_GAS;\r\n\r\n        bool ok;\r\n        assembly {\r\n            ok := staticcall(oracleCheckGas, _oracleAddr, add(checkCalldata, 0x20), mload(checkCalldata), 0, 0)\r\n        }\r\n\r\n        if (!ok) {\r\n            return false;\r\n        }\r\n\r\n        uint256 size;\r\n        assembly { size := returndatasize }\r\n        if (size != 32) {\r\n            return false;\r\n        }\r\n\r\n        bool result;\r\n        assembly {\r\n            let ptr := mload(0x40)       // get next free memory ptr\r\n            returndatacopy(ptr, 0, size) // copy return from above `staticcall`\r\n            result := mload(ptr)         // read data at ptr and set it to result\r\n            mstore(ptr, 0)               // set pointer memory to 0 so it still is the next free ptr\r\n        }\r\n\r\n        return result;\r\n    }\r\n\r\n    /**\r\n    * @dev Internal function that sets management\r\n    */\r\n    function _setPermissionManager(address _newManager, address _app, bytes32 _role) internal {\r\n        permissionManager[roleHash(_app, _role)] = _newManager;\r\n        emit ChangePermissionManager(_app, _role, _newManager);\r\n    }\r\n\r\n    function roleHash(address _where, bytes32 _what) internal pure returns (bytes32) {\r\n        return keccak256(abi.encodePacked(\"ROLE\", _where, _what));\r\n    }\r\n\r\n    function permissionHash(address _who, address _where, bytes32 _what) internal pure returns (bytes32) {\r\n        return keccak256(abi.encodePacked(\"PERMISSION\", _who, _where, _what));\r\n    }\r\n}\r\n\r\n// File: contracts/evmscript/ScriptHelpers.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\nlibrary ScriptHelpers {\r\n    function getSpecId(bytes _script) internal pure returns (uint32) {\r\n        return uint32At(_script, 0);\r\n    }\r\n\r\n    function uint256At(bytes _data, uint256 _location) internal pure returns (uint256 result) {\r\n        assembly {\r\n            result := mload(add(_data, add(0x20, _location)))\r\n        }\r\n    }\r\n\r\n    function addressAt(bytes _data, uint256 _location) internal pure returns (address result) {\r\n        uint256 word = uint256At(_data, _location);\r\n\r\n        assembly {\r\n            result := div(and(word, 0xffffffffffffffffffffffffffffffffffffffff000000000000000000000000),\r\n            0x1000000000000000000000000)\r\n        }\r\n    }\r\n\r\n    function uint32At(bytes _data, uint256 _location) internal pure returns (uint32 result) {\r\n        uint256 word = uint256At(_data, _location);\r\n\r\n        assembly {\r\n            result := div(and(word, 0xffffffff00000000000000000000000000000000000000000000000000000000),\r\n            0x100000000000000000000000000000000000000000000000000000000)\r\n        }\r\n    }\r\n\r\n    function locationOf(bytes _data, uint256 _location) internal pure returns (uint256 result) {\r\n        assembly {\r\n            result := add(_data, add(0x20, _location))\r\n        }\r\n    }\r\n\r\n    function toBytes(bytes4 _sig) internal pure returns (bytes) {\r\n        bytes memory payload = new bytes(4);\r\n        assembly { mstore(add(payload, 0x20), _sig) }\r\n        return payload;\r\n    }\r\n}\r\n\r\n// File: contracts/evmscript/EVMScriptRegistry.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\n\r\n\r\n\r\n\r\n/* solium-disable function-order */\r\n// Allow public initialize() to be first\r\ncontract EVMScriptRegistry is IEVMScriptRegistry, EVMScriptRegistryConstants, AragonApp {\r\n    using ScriptHelpers for bytes;\r\n\r\n    /* Hardcoded constants to save gas\r\n    bytes32 public constant REGISTRY_ADD_EXECUTOR_ROLE = keccak256(\"REGISTRY_ADD_EXECUTOR_ROLE\");\r\n    bytes32 public constant REGISTRY_MANAGER_ROLE = keccak256(\"REGISTRY_MANAGER_ROLE\");\r\n    */\r\n    bytes32 public constant REGISTRY_ADD_EXECUTOR_ROLE = 0xc4e90f38eea8c4212a009ca7b8947943ba4d4a58d19b683417f65291d1cd9ed2;\r\n    // WARN: Manager can censor all votes and the like happening in an org\r\n    bytes32 public constant REGISTRY_MANAGER_ROLE = 0xf7a450ef335e1892cb42c8ca72e7242359d7711924b75db5717410da3f614aa3;\r\n\r\n    uint256 internal constant SCRIPT_START_LOCATION = 4;\r\n\r\n    string private constant ERROR_INEXISTENT_EXECUTOR = \"EVMREG_INEXISTENT_EXECUTOR\";\r\n    string private constant ERROR_EXECUTOR_ENABLED = \"EVMREG_EXECUTOR_ENABLED\";\r\n    string private constant ERROR_EXECUTOR_DISABLED = \"EVMREG_EXECUTOR_DISABLED\";\r\n    string private constant ERROR_SCRIPT_LENGTH_TOO_SHORT = \"EVMREG_SCRIPT_LENGTH_TOO_SHORT\";\r\n\r\n    struct ExecutorEntry {\r\n        IEVMScriptExecutor executor;\r\n        bool enabled;\r\n    }\r\n\r\n    uint256 private executorsNextIndex;\r\n    mapping (uint256 => ExecutorEntry) public executors;\r\n\r\n    event EnableExecutor(uint256 indexed executorId, address indexed executorAddress);\r\n    event DisableExecutor(uint256 indexed executorId, address indexed executorAddress);\r\n\r\n    modifier executorExists(uint256 _executorId) {\r\n        require(_executorId > 0 && _executorId < executorsNextIndex, ERROR_INEXISTENT_EXECUTOR);\r\n        _;\r\n    }\r\n\r\n    /**\r\n    * @notice Initialize the registry\r\n    */\r\n    function initialize() public onlyInit {\r\n        initialized();\r\n        // Create empty record to begin executor IDs at 1\r\n        executorsNextIndex = 1;\r\n    }\r\n\r\n    /**\r\n    * @notice Add a new script executor with address `_executor` to the registry\r\n    * @param _executor Address of the IEVMScriptExecutor that will be added to the registry\r\n    * @return id Identifier of the executor in the registry\r\n    */\r\n    function addScriptExecutor(IEVMScriptExecutor _executor) external auth(REGISTRY_ADD_EXECUTOR_ROLE) returns (uint256 id) {\r\n        uint256 executorId = executorsNextIndex++;\r\n        executors[executorId] = ExecutorEntry(_executor, true);\r\n        emit EnableExecutor(executorId, _executor);\r\n        return executorId;\r\n    }\r\n\r\n    /**\r\n    * @notice Disable script executor with ID `_executorId`\r\n    * @param _executorId Identifier of the executor in the registry\r\n    */\r\n    function disableScriptExecutor(uint256 _executorId)\r\n        external\r\n        authP(REGISTRY_MANAGER_ROLE, arr(_executorId))\r\n    {\r\n        // Note that we don't need to check for an executor's existence in this case, as only\r\n        // existing executors can be enabled\r\n        ExecutorEntry storage executorEntry = executors[_executorId];\r\n        require(executorEntry.enabled, ERROR_EXECUTOR_DISABLED);\r\n        executorEntry.enabled = false;\r\n        emit DisableExecutor(_executorId, executorEntry.executor);\r\n    }\r\n\r\n    /**\r\n    * @notice Enable script executor with ID `_executorId`\r\n    * @param _executorId Identifier of the executor in the registry\r\n    */\r\n    function enableScriptExecutor(uint256 _executorId)\r\n        external\r\n        authP(REGISTRY_MANAGER_ROLE, arr(_executorId))\r\n        executorExists(_executorId)\r\n    {\r\n        ExecutorEntry storage executorEntry = executors[_executorId];\r\n        require(!executorEntry.enabled, ERROR_EXECUTOR_ENABLED);\r\n        executorEntry.enabled = true;\r\n        emit EnableExecutor(_executorId, executorEntry.executor);\r\n    }\r\n\r\n    /**\r\n    * @dev Get the script executor that can execute a particular script based on its first 4 bytes\r\n    * @param _script EVMScript being inspected\r\n    */\r\n    function getScriptExecutor(bytes _script) public view returns (IEVMScriptExecutor) {\r\n        require(_script.length >= SCRIPT_START_LOCATION, ERROR_SCRIPT_LENGTH_TOO_SHORT);\r\n        uint256 id = _script.getSpecId();\r\n\r\n        // Note that we don't need to check for an executor's existence in this case, as only\r\n        // existing executors can be enabled\r\n        ExecutorEntry storage entry = executors[id];\r\n        return entry.enabled ? entry.executor : IEVMScriptExecutor(0);\r\n    }\r\n}\r\n\r\n// File: contracts/evmscript/executors/BaseEVMScriptExecutor.sol\r\n\r\n/*\r\n * SPDX-License-Identitifer:    MIT\r\n */\r\n\r\npragma solidity ^0.4.24;\r\n\r\n\r\n\r\n\r\ncontract BaseEVMScriptExecutor is IEVMScriptExecutor, Autopetrified {\r\n    uint256 internal constant SCRIPT_START_LOCATION = 4;\r\n}\r\n\r\n// File: contracts/evmscript/executors/CallsScript.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n// Inspired by https://github.com/reverendus/tx-manager\r\n\r\n\r\n\r\n\r\ncontract CallsScript is BaseEVMScriptExecutor {\r\n    using ScriptHelpers for bytes;\r\n\r\n    /* Hardcoded constants to save gas\r\n    bytes32 internal constant EXECUTOR_TYPE = keccak256(\"CALLS_SCRIPT\");\r\n    */\r\n    bytes32 internal constant EXECUTOR_TYPE = 0x2dc858a00f3e417be1394b87c07158e989ec681ce8cc68a9093680ac1a870302;\r\n\r\n    string private constant ERROR_BLACKLISTED_CALL = \"EVMCALLS_BLACKLISTED_CALL\";\r\n    string private constant ERROR_INVALID_LENGTH = \"EVMCALLS_INVALID_LENGTH\";\r\n\r\n    /* This is manually crafted in assembly\r\n    string private constant ERROR_CALL_REVERTED = \"EVMCALLS_CALL_REVERTED\";\r\n    */\r\n\r\n    event LogScriptCall(address indexed sender, address indexed src, address indexed dst);\r\n\r\n    /**\r\n    * @notice Executes a number of call scripts\r\n    * @param _script [ specId (uint32) ] many calls with this structure ->\r\n    *    [ to (address: 20 bytes) ] [ calldataLength (uint32: 4 bytes) ] [ calldata (calldataLength bytes) ]\r\n    * @param _blacklist Addresses the script cannot call to, or will revert.\r\n    * @return Always returns empty byte array\r\n    */\r\n    function execScript(bytes _script, bytes, address[] _blacklist) external isInitialized returns (bytes) {\r\n        uint256 location = SCRIPT_START_LOCATION; // first 32 bits are spec id\r\n        while (location < _script.length) {\r\n            // Check there's at least address + calldataLength available\r\n            require(_script.length - location >= 0x18, ERROR_INVALID_LENGTH);\r\n\r\n            address contractAddress = _script.addressAt(location);\r\n            // Check address being called is not blacklist\r\n            for (uint256 i = 0; i < _blacklist.length; i++) {\r\n                require(contractAddress != _blacklist[i], ERROR_BLACKLISTED_CALL);\r\n            }\r\n\r\n            // logged before execution to ensure event ordering in receipt\r\n            // if failed entire execution is reverted regardless\r\n            emit LogScriptCall(msg.sender, address(this), contractAddress);\r\n\r\n            uint256 calldataLength = uint256(_script.uint32At(location + 0x14));\r\n            uint256 startOffset = location + 0x14 + 0x04;\r\n            uint256 calldataStart = _script.locationOf(startOffset);\r\n\r\n            // compute end of script / next location\r\n            location = startOffset + calldataLength;\r\n            require(location <= _script.length, ERROR_INVALID_LENGTH);\r\n\r\n            bool success;\r\n            assembly {\r\n                success := call(\r\n                    sub(gas, 5000),       // forward gas left - 5000\r\n                    contractAddress,      // address\r\n                    0,                    // no value\r\n                    calldataStart,        // calldata start\r\n                    calldataLength,       // calldata length\r\n                    0,                    // don't write output\r\n                    0                     // don't write output\r\n                )\r\n\r\n                switch success\r\n                case 0 {\r\n                    let ptr := mload(0x40)\r\n\r\n                    switch returndatasize\r\n                    case 0 {\r\n                        // No error data was returned, revert with \"EVMCALLS_CALL_REVERTED\"\r\n                        // See remix: doing a `revert(\"EVMCALLS_CALL_REVERTED\")` always results in\r\n                        // this memory layout\r\n                        mstore(ptr, 0x08c379a000000000000000000000000000000000000000000000000000000000)         // error identifier\r\n                        mstore(add(ptr, 0x04), 0x0000000000000000000000000000000000000000000000000000000000000020) // starting offset\r\n                        mstore(add(ptr, 0x24), 0x0000000000000000000000000000000000000000000000000000000000000016) // reason length\r\n                        mstore(add(ptr, 0x44), 0x45564d43414c4c535f43414c4c5f524556455254454400000000000000000000) // reason\r\n\r\n                        revert(ptr, 100) // 100 = 4 + 3 * 32 (error identifier + 3 words for the ABI encoded error)\r\n                    }\r\n                    default {\r\n                        // Forward the full error data\r\n                        returndatacopy(ptr, 0, returndatasize)\r\n                        revert(ptr, returndatasize)\r\n                    }\r\n                }\r\n                default { }\r\n            }\r\n        }\r\n        // No need to allocate empty bytes for the return as this can only be called via an delegatecall\r\n        // (due to the isInitialized modifier)\r\n    }\r\n\r\n    function executorType() external pure returns (bytes32) {\r\n        return EXECUTOR_TYPE;\r\n    }\r\n}\r\n\r\n// File: contracts/factory/EVMScriptRegistryFactory.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\ncontract EVMScriptRegistryFactory is EVMScriptRegistryConstants {\r\n    EVMScriptRegistry public baseReg;\r\n    IEVMScriptExecutor public baseCallScript;\r\n\r\n    /**\r\n    * @notice Create a new EVMScriptRegistryFactory.\r\n    */\r\n    constructor() public {\r\n        baseReg = new EVMScriptRegistry();\r\n        baseCallScript = IEVMScriptExecutor(new CallsScript());\r\n    }\r\n\r\n    /**\r\n    * @notice Install a new pinned instance of EVMScriptRegistry on `_dao`.\r\n    * @param _dao Kernel\r\n    * @return Installed EVMScriptRegistry\r\n    */\r\n    function newEVMScriptRegistry(Kernel _dao) public returns (EVMScriptRegistry reg) {\r\n        bytes memory initPayload = abi.encodeWithSelector(reg.initialize.selector);\r\n        reg = EVMScriptRegistry(_dao.newPinnedAppInstance(EVMSCRIPT_REGISTRY_APP_ID, baseReg, initPayload, true));\r\n\r\n        ACL acl = ACL(_dao.acl());\r\n\r\n        acl.createPermission(this, reg, reg.REGISTRY_ADD_EXECUTOR_ROLE(), this);\r\n\r\n        reg.addScriptExecutor(baseCallScript);     // spec 1 = CallsScript\r\n\r\n        // Clean up the permissions\r\n        acl.revokePermission(this, reg, reg.REGISTRY_ADD_EXECUTOR_ROLE());\r\n        acl.removePermissionManager(reg, reg.REGISTRY_ADD_EXECUTOR_ROLE());\r\n\r\n        return reg;\r\n    }\r\n}\r\n\r\n// File: contracts/factory/DAOFactory.sol\r\n\r\npragma solidity 0.4.24;\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\ncontract DAOFactory {\r\n    IKernel public baseKernel;\r\n    IACL public baseACL;\r\n    EVMScriptRegistryFactory public regFactory;\r\n\r\n    event DeployDAO(address dao);\r\n    event DeployEVMScriptRegistry(address reg);\r\n\r\n    /**\r\n    * @notice Create a new DAOFactory, creating DAOs with Kernels proxied to `_baseKernel`, ACLs proxied to `_baseACL`, and new EVMScriptRegistries created from `_regFactory`.\r\n    * @param _baseKernel Base Kernel\r\n    * @param _baseACL Base ACL\r\n    * @param _regFactory EVMScriptRegistry factory\r\n    */\r\n    constructor(IKernel _baseKernel, IACL _baseACL, EVMScriptRegistryFactory _regFactory) public {\r\n        // No need to init as it cannot be killed by devops199\r\n        if (address(_regFactory) != address(0)) {\r\n            regFactory = _regFactory;\r\n        }\r\n\r\n        baseKernel = _baseKernel;\r\n        baseACL = _baseACL;\r\n    }\r\n\r\n    /**\r\n    * @notice Create a new DAO with `_root` set as the initial admin\r\n    * @param _root Address that will be granted control to setup DAO permissions\r\n    * @return Newly created DAO\r\n    */\r\n    function newDAO(address _root) public returns (Kernel) {\r\n        Kernel dao = Kernel(new KernelProxy(baseKernel));\r\n\r\n        if (address(regFactory) == address(0)) {\r\n            dao.initialize(baseACL, _root);\r\n        } else {\r\n            dao.initialize(baseACL, this);\r\n\r\n            ACL acl = ACL(dao.acl());\r\n            bytes32 permRole = acl.CREATE_PERMISSIONS_ROLE();\r\n            bytes32 appManagerRole = dao.APP_MANAGER_ROLE();\r\n\r\n            acl.grantPermission(regFactory, acl, permRole);\r\n\r\n            acl.createPermission(regFactory, dao, appManagerRole, this);\r\n\r\n            EVMScriptRegistry reg = regFactory.newEVMScriptRegistry(dao);\r\n            emit DeployEVMScriptRegistry(address(reg));\r\n\r\n            // Clean up permissions\r\n            // First, completely reset the APP_MANAGER_ROLE\r\n            acl.revokePermission(regFactory, dao, appManagerRole);\r\n            acl.removePermissionManager(dao, appManagerRole);\r\n\r\n            // Then, make root the only holder and manager of CREATE_PERMISSIONS_ROLE\r\n            acl.revokePermission(regFactory, acl, permRole);\r\n            acl.revokePermission(this, acl, permRole);\r\n            acl.grantPermission(_root, acl, permRole);\r\n            acl.setPermissionManager(_root, acl, permRole);\r\n        }\r\n\r\n        emit DeployDAO(address(dao));\r\n\r\n        return dao;\r\n    }\r\n}","deployed_bytecode":"0x60806040526004361061006c5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634555d5c9811461012b57806348a0c8dd146101525780635c60da1b1461017b57806380afdea8146101b9578063d4aae0c4146101ce575b6127107f665fd576fbbe6f247aff98f5c94a561e3f71ec2d3c988d56f12d342396c50cea6000825a10156100e15760003411361583541616156100dc576040513381523460208201527f15eeaa57c7bd188c1388020bcadc2c436ec60d647d36ef5b9eb3c742217ddee1604082a1005b600080fd5b6100e96101e3565b9050610126816000368080601f016020809104026020016040519081016040528093929190818152602001838380828437506101fa945050505050565b505050005b34801561013757600080fd5b5061014061023b565b60408051918252519081900360200190f35b34801561015e57600080fd5b50610167610240565b604080519115158252519081900360200190f35b34801561018757600080fd5b506101906101e3565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b3480156101c557600080fd5b5061014061026b565b3480156101da57600080fd5b50610190610296565b60006101f56101f061026b565b6102c1565b905090565b600061020583610395565b151561021057600080fd5b612710905060008083516020850186855a03f43d604051816000823e828015610237578282f35b8282fd5b600290565b60006101f57f665fd576fbbe6f247aff98f5c94a561e3f71ec2d3c988d56f12d342396c50cea6103cf565b60006101f57fd625496217aa6a3453eecb9c3489dc5a53e6c67b444329ea2b2cbc9ff547639b6103cf565b60006101f57f4172f0f7d2289153072b0a6ca36959e0cbe2efc3afe50fc81636caa96338137b6103cf565b60006102cb610296565b604080517fbe00bbd80000000000000000000000000000000000000000000000000000000081527ff1f3eb40f5bc1ad1344716ced8b8a0431d840b5783aea1fd01786bc26f35ac0f600482015260248101859052905173ffffffffffffffffffffffffffffffffffffffff929092169163be00bbd8916044808201926020929091908290030181600087803b15801561036357600080fd5b505af1158015610377573d6000803e3d6000fd5b505050506040513d602081101561038d57600080fd5b505192915050565b60008073ffffffffffffffffffffffffffffffffffffffff831615156103be57600091506103c9565b823b90506000811191505b50919050565b5490565b5490565b9055565b90555600a165627a7a72305820976bd9d6f6ad7a0d339ea3b373704842cdb3d9e15e7463676c04c1fa6ffb56410029","optimization_enabled":true,"verified_twin_address_hash":null,"is_verified":true,"compiler_settings":{"evmVersion":"byzantium","libraries":{},"optimizer":{"enabled":true,"runs":10000},"outputSelection":{"*":{"":["*"],"*":["*"]}}},"optimization_runs":10000,"sourcify_repo_url":null,"decoded_constructor_args":[["0xb8FFC3Cd6e7Cf5a098A1c92F48009765B24088Dc",{"name":"_kernel","type":"address"}],["0x3ca7c3e38968823ccb4c78ea688df41356f182ae1d159e4ee608d30d68cef320",{"name":"_appId","type":"bytes32"}],["0x",{"name":"_initializePayload","type":"bytes"}]],"compiler_version":"v0.4.24+commit.e67f0147","is_verified_via_verifier_alliance":true,"verified_at":"2022-09-18T21:12:34.839054Z","implementations":[{"address_hash":"0x028271E30a695c0527A0C50cA30603feD004cDb0","name":"Lido"}],"proxy_type":"basic_implementation","external_libraries":[],"creation_bytecode":"0x608060405234801561001057600080fd5b506040516106ed3803806106ed8339810160409081528151602083015191830151909201828282600061004b84640100000000610124810204565b61005d8364010000000061014c810204565b61006f83640100000000610183810204565b90506000825111156101185761008d81640100000000610253810204565b151561009857600080fd5b80600160a060020a03168260405180828051906020019080838360005b838110156100cd5781810151838201526020016100b5565b50505050905090810190601f1680156100fa5780820380516001836020036101000a031916815260200191505b50915050600060405180830381855af4915050151561011857600080fd5b505050505050506102b3565b6101496000805160206106cd833981519152826401000000006103d761028082021704565b50565b6101497fd625496217aa6a3453eecb9c3489dc5a53e6c67b444329ea2b2cbc9ff547639b826401000000006103d761028082021704565b6000610196640100000000610284810204565b604080517fbe00bbd80000000000000000000000000000000000000000000000000000000081527ff1f3eb40f5bc1ad1344716ced8b8a0431d840b5783aea1fd01786bc26f35ac0f6004820152602481018590529051600160a060020a03929092169163be00bbd8916044808201926020929091908290030181600087803b15801561022157600080fd5b505af1158015610235573d6000803e3d6000fd5b505050506040513d602081101561024b57600080fd5b505192915050565b600080600160a060020a038316151561026f576000915061027a565b823b90506000811191505b50919050565b9055565b60006102aa6000805160206106cd8339815191526401000000006103cf6102af82021704565b905090565b5490565b61040b806102c26000396000f30060806040526004361061006c5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634555d5c9811461012b57806348a0c8dd146101525780635c60da1b1461017b57806380afdea8146101b9578063d4aae0c4146101ce575b6127107f665fd576fbbe6f247aff98f5c94a561e3f71ec2d3c988d56f12d342396c50cea6000825a10156100e15760003411361583541616156100dc576040513381523460208201527f15eeaa57c7bd188c1388020bcadc2c436ec60d647d36ef5b9eb3c742217ddee1604082a1005b600080fd5b6100e96101e3565b9050610126816000368080601f016020809104026020016040519081016040528093929190818152602001838380828437506101fa945050505050565b505050005b34801561013757600080fd5b5061014061023b565b60408051918252519081900360200190f35b34801561015e57600080fd5b50610167610240565b604080519115158252519081900360200190f35b34801561018757600080fd5b506101906101e3565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b3480156101c557600080fd5b5061014061026b565b3480156101da57600080fd5b50610190610296565b60006101f56101f061026b565b6102c1565b905090565b600061020583610395565b151561021057600080fd5b612710905060008083516020850186855a03f43d604051816000823e828015610237578282f35b8282fd5b600290565b60006101f57f665fd576fbbe6f247aff98f5c94a561e3f71ec2d3c988d56f12d342396c50cea6103cf565b60006101f57fd625496217aa6a3453eecb9c3489dc5a53e6c67b444329ea2b2cbc9ff547639b6103cf565b60006101f57f4172f0f7d2289153072b0a6ca36959e0cbe2efc3afe50fc81636caa96338137b6103cf565b60006102cb610296565b604080517fbe00bbd80000000000000000000000000000000000000000000000000000000081527ff1f3eb40f5bc1ad1344716ced8b8a0431d840b5783aea1fd01786bc26f35ac0f600482015260248101859052905173ffffffffffffffffffffffffffffffffffffffff929092169163be00bbd8916044808201926020929091908290030181600087803b15801561036357600080fd5b505af1158015610377573d6000803e3d6000fd5b505050506040513d602081101561038d57600080fd5b505192915050565b60008073ffffffffffffffffffffffffffffffffffffffff831615156103be57600091506103c9565b823b90506000811191505b50919050565b5490565b5490565b9055565b90555600a165627a7a72305820976bd9d6f6ad7a0d339ea3b373704842cdb3d9e15e7463676c04c1fa6ffb564100294172f0f7d2289153072b0a6ca36959e0cbe2efc3afe50fc81636caa96338137b000000000000000000000000b8ffc3cd6e7cf5a098a1c92f48009765b24088dc3ca7c3e38968823ccb4c78ea688df41356f182ae1d159e4ee608d30d68cef32000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000","name":"AppProxyUpgradeable","is_blueprint":false,"license_type":"none","is_fully_verified":false,"is_verified_via_eth_bytecode_db":true,"language":"solidity","evm_version":"byzantium","can_be_visualized_via_sol2uml":true,"is_verified_via_sourcify":false,"additional_sources":[],"certified":false,"conflicting_implementations":null,"abi":[{"constant":true,"inputs":[],"name":"proxyType","outputs":[{"name":"proxyTypeId","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[],"name":"isDepositable","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"implementation","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"appId","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"kernel","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_kernel","type":"address"},{"name":"_appId","type":"bytes32"},{"name":"_initializePayload","type":"bytes"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":false,"name":"sender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"ProxyDeposit","type":"event"}],"is_changed_bytecode":false,"is_partially_verified":true,"constructor_args":"0x000000000000000000000000b8ffc3cd6e7cf5a098a1c92f48009765b24088dc3ca7c3e38968823ccb4c78ea688df41356f182ae1d159e4ee608d30d68cef32000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000"}