{
    "Function": "checkNSignatures",
    "File": "contracts/lib/safe-contracts/contracts/GnosisSafe.sol",
    "Parent Contracts": [
        "contracts/lib/safe-contracts/contracts/base/GuardManager.sol",
        "contracts/lib/safe-contracts/contracts/common/StorageAccessible.sol",
        "contracts/lib/safe-contracts/contracts/base/FallbackManager.sol",
        "contracts/lib/safe-contracts/contracts/interfaces/ISignatureValidator.sol",
        "contracts/lib/safe-contracts/contracts/common/SecuredTokenTransfer.sol",
        "contracts/lib/safe-contracts/contracts/common/SignatureDecoder.sol",
        "contracts/lib/safe-contracts/contracts/base/OwnerManager.sol",
        "contracts/lib/safe-contracts/contracts/base/ModuleManager.sol",
        "contracts/lib/safe-contracts/contracts/base/Executor.sol",
        "contracts/lib/safe-contracts/contracts/common/SelfAuthorized.sol",
        "contracts/lib/safe-contracts/contracts/common/Singleton.sol",
        "contracts/lib/safe-contracts/contracts/common/EtherPaymentFallback.sol"
    ],
    "High-Level Calls": [
        "GnosisSafeMath",
        "ISignatureValidator",
        "GnosisSafeMath",
        "GnosisSafeMath",
        "GnosisSafeMath",
        "GnosisSafeMath"
    ],
    "Internal Calls": [
        "require(bool,string)",
        "abi.encodePacked()",
        "keccak256(bytes)",
        "ecrecover(bytes32,uint8,bytes32,bytes32)",
        "require(bool,string)",
        "require(bool,string)",
        "signatureSplit",
        "mload(uint256)",
        "ecrecover(bytes32,uint8,bytes32,bytes32)",
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)",
        "require(bool,string)"
    ],
    "Library Calls": [
        "mul",
        "add",
        "add",
        "mul",
        "add"
    ],
    "Low-Level Calls": [],
    "Code": "function checkNSignatures(\n        bytes32 dataHash,\n        bytes memory data,\n        bytes memory signatures,\n        uint256 requiredSignatures\n    ) public view {\n        // Check that the provided signature data is not too short\n        require(signatures.length >= requiredSignatures.mul(65), \"GS020\");\n        // There cannot be an owner with address 0.\n        address lastOwner = address(0);\n        address currentOwner;\n        uint8 v;\n        bytes32 r;\n        bytes32 s;\n        uint256 i;\n        for (i = 0; i < requiredSignatures; i++) {\n            (v, r, s) = signatureSplit(signatures, i);\n            if (v == 0) {\n                // If v is 0 then it is a contract signature\n                // When handling contract signatures the address of the contract is encoded into r\n                currentOwner = address(uint160(uint256(r)));\n\n                // Check that signature data pointer (s) is not pointing inside the static part of the signatures bytes\n                // This check is not completely accurate, since it is possible that more signatures than the threshold are send.\n                // Here we only check that the pointer is not pointing inside the part that is being processed\n                require(uint256(s) >= requiredSignatures.mul(65), \"GS021\");\n\n                // Check that signature data pointer (s) is in bounds (points to the length of data -> 32 bytes)\n                require(uint256(s).add(32) <= signatures.length, \"GS022\");\n\n                // Check if the contract signature is in bounds: start of data is s + 32 and end is start + signature length\n                uint256 contractSignatureLen;\n                // solhint-disable-next-line no-inline-assembly\n                assembly {\n                    contractSignatureLen := mload(add(add(signatures, s), 0x20))\n                }\n                require(uint256(s).add(32).add(contractSignatureLen) <= signatures.length, \"GS023\");\n\n                // Check signature\n                bytes memory contractSignature;\n                // solhint-disable-next-line no-inline-assembly\n                assembly {\n                    // The signature data for contract signatures is appended to the concatenated signatures and the offset is stored in s\n                    contractSignature := add(add(signatures, s), 0x20)\n                }\n                require(ISignatureValidator(currentOwner).isValidSignature(data, contractSignature) == EIP1271_MAGIC_VALUE, \"GS024\");\n            } else if (v == 1) {\n                // If v is 1 then it is an approved hash\n                // When handling approved hashes the address of the approver is encoded into r\n                currentOwner = address(uint160(uint256(r)));\n                // Hashes are automatically approved by the sender of the message or when they have been pre-approved via a separate transaction\n                require(msg.sender == currentOwner || approvedHashes[currentOwner][dataHash] != 0, \"GS025\");\n            } else if (v > 30) {\n                // If v > 30 then default va (27,28) has been adjusted for eth_sign flow\n                // To support eth_sign and similar we adjust v and hash the messageHash with the Ethereum message prefix before applying ecrecover\n                currentOwner = ecrecover(keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", dataHash)), v - 4, r, s);\n            } else {\n                // Default is the ecrecover flow with the provided data hash\n                // Use ecrecover with the messageHash for EOA signatures\n                currentOwner = ecrecover(dataHash, v, r, s);\n            }\n            require(currentOwner > lastOwner && owners[currentOwner] != address(0) && currentOwner != SENTINEL_OWNERS, \"GS026\");\n            lastOwner = currentOwner;\n        }\n    }"
}