{
    "Function": "_addCalldataCheck",
    "File": "src/Timelock.sol",
    "Parent Contracts": [
        "lib/openzeppelin-contracts/contracts/token/ERC721/IERC721Receiver.sol",
        "lib/openzeppelin-contracts/contracts/token/ERC1155/IERC1155Receiver.sol",
        "lib/openzeppelin-contracts/contracts/access/extensions/AccessControlEnumerable.sol",
        "lib/openzeppelin-contracts/contracts/access/AccessControl.sol",
        "lib/openzeppelin-contracts/contracts/utils/introspection/ERC165.sol",
        "lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol",
        "lib/openzeppelin-contracts/contracts/access/extensions/IAccessControlEnumerable.sol",
        "lib/openzeppelin-contracts/contracts/access/IAccessControl.sol",
        "lib/openzeppelin-contracts/contracts/utils/Context.sol",
        "src/ConfigurablePause.sol"
    ],
    "High-Level Calls": [
        "EnumerableSet",
        "EnumerableSet"
    ],
    "Internal Calls": [
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)",
        "keccak256(bytes)",
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)"
    ],
    "Library Calls": [
        "values",
        "add"
    ],
    "Low-Level Calls": [],
    "Code": "function _addCalldataCheck(\n        address contractAddress,\n        bytes4 selector,\n        uint16 startIndex,\n        uint16 endIndex,\n        bytes[] memory data\n    ) private {\n        require(\n            contractAddress != address(0),\n            \"CalldataList: Address cannot be zero\"\n        );\n        require(selector != bytes4(0), \"CalldataList: Selector cannot be empty\");\n        require(\n            startIndex >= 4, \"CalldataList: Start index must be greater than 3\"\n        );\n\n        /// prevent misconfiguration where a hot signer could change timelock\n        /// or safe parameters\n        require(\n            contractAddress != address(this),\n            \"CalldataList: Address cannot be this\"\n        );\n        require(contractAddress != safe, \"CalldataList: Address cannot be safe\");\n\n        Index[] storage calldataChecks =\n            _calldataList[contractAddress][selector];\n        uint256 listLength = calldataChecks.length;\n\n        if (listLength == 1) {\n            require(\n                calldataChecks[0].startIndex != calldataChecks[0].endIndex,\n                \"CalldataList: Cannot add check with wildcard\"\n            );\n        }\n\n        if (startIndex == endIndex) {\n            require(\n                startIndex == 4,\n                \"CalldataList: End index equals start index only when 4\"\n            );\n            require(\n                listLength == 0,\n                \"CalldataList: Add wildcard only if no existing check\"\n            );\n            require(data.length == 0, \"CalldataList: Data must be empty\");\n        } else {\n            require(\n                endIndex > startIndex,\n                \"CalldataList: End index must be greater than start index\"\n            );\n            /// if we are adding a concrete check and not a wildcard, then the\n            /// calldata must not be empty\n            require(data.length != 0, \"CalldataList: Data empty\");\n        }\n\n        Index[] storage indexes = _calldataList[contractAddress][selector];\n        uint256 targetIndex = indexes.length;\n        {\n            bool found;\n            for (uint256 i = 0; i < indexes.length; i++) {\n                if (\n                    indexes[i].startIndex == startIndex\n                        && indexes[i].endIndex == endIndex\n                ) {\n                    targetIndex = i;\n                    found = true;\n                    break;\n                }\n                /// all calldata checks must be isolated to predefined calldata segments\n                /// for example given calldata with three parameters:\n\n                ///                    1.                              2.                             3.\n                ///       000000000000000112818929111111\n                ///                                     000000000000000112818929111111\n                ///                                                                   000000000000000112818929111111\n\n                /// checks must be applied in a way such that they do not overlap with each other.\n                /// having checks that check 1 and 2 together as a single parameter would be valid,\n                /// but having checks that check 1 and 2 together, and then check one separately\n                /// would be invalid.\n                /// checking 1, 2, and 3 separately is valid\n                /// checking 1, 2, and 3 as a single check is valid\n                /// checking 1, 2, and 3 separately, and then the last half of 2 and the first half\n                /// of 3 is invalid\n\n                require(\n                    startIndex > indexes[i].endIndex\n                        || endIndex < indexes[i].startIndex,\n                    \"CalldataList: Partial check overlap\"\n                );\n            }\n\n            if (!found) {\n                indexes.push();\n                indexes[targetIndex].startIndex = startIndex;\n                indexes[targetIndex].endIndex = endIndex;\n            }\n        }\n\n        for (uint256 i = 0; i < data.length; i++) {\n            /// data length must equal delta index\n            require(\n                data[i].length == endIndex - startIndex,\n                \"CalldataList: Data length mismatch\"\n            );\n            bytes32 dataHash = keccak256(data[i]);\n\n            /// make require instead of assert to have clear error messages\n            require(\n                indexes[targetIndex].dataHashes.add(dataHash),\n                \"CalldataList: Duplicate data\"\n            );\n        }\n\n        emit CalldataAdded(\n            contractAddress,\n            selector,\n            startIndex,\n            endIndex,\n            indexes[targetIndex].dataHashes.values()\n        );\n    }"
}