{
    "Function": "_checkpointsLookup",
    "File": "contracts/lib/openzeppelin-contracts/contracts/mocks/token/ERC20VotesLegacyMock.sol",
    "Parent Contracts": [
        "contracts/lib/openzeppelin-contracts/contracts/token/ERC20/extensions/ERC20Permit.sol",
        "contracts/lib/openzeppelin-contracts/contracts/utils/cryptography/EIP712.sol",
        "contracts/lib/openzeppelin-contracts/contracts/interfaces/IERC5267.sol",
        "contracts/lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol",
        "contracts/lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol",
        "contracts/lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol",
        "contracts/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol",
        "contracts/lib/openzeppelin-contracts/contracts/utils/Context.sol",
        "contracts/lib/openzeppelin-contracts/contracts/governance/utils/IVotes.sol"
    ],
    "High-Level Calls": [
        "Math",
        "Math"
    ],
    "Internal Calls": [
        "_unsafeAccess",
        "_unsafeAccess",
        "_unsafeAccess"
    ],
    "Library Calls": [
        "average",
        "sqrt"
    ],
    "Low-Level Calls": [],
    "Code": "function _checkpointsLookup(Checkpoint[] storage ckpts, uint256 blockNumber) private view returns (uint256) {\n        // We run a binary search to look for the earliest checkpoint taken after `blockNumber`.\n        //\n        // Initially we check if the block is recent to narrow the search range.\n        // During the loop, the index of the wanted checkpoint remains in the range [low-1, high).\n        // With each iteration, either `low` or `high` is moved towards the middle of the range to maintain the invariant.\n        // - If the middle checkpoint is after `blockNumber`, we look in [low, mid)\n        // - If the middle checkpoint is before or equal to `blockNumber`, we look in [mid+1, high)\n        // Once we reach a single value (when low == high), we've found the right checkpoint at the index high-1, if not\n        // out of bounds (in which case we're looking too far in the past and the result is 0).\n        // Note that if the latest checkpoint available is exactly for `blockNumber`, we end up with an index that is\n        // past the end of the array, so we technically don't find a checkpoint after `blockNumber`, but it works out\n        // the same.\n        uint256 length = ckpts.length;\n\n        uint256 low = 0;\n        uint256 high = length;\n\n        if (length > 5) {\n            uint256 mid = length - Math.sqrt(length);\n            if (_unsafeAccess(ckpts, mid).fromBlock > blockNumber) {\n                high = mid;\n            } else {\n                low = mid + 1;\n            }\n        }\n\n        while (low < high) {\n            uint256 mid = Math.average(low, high);\n            if (_unsafeAccess(ckpts, mid).fromBlock > blockNumber) {\n                high = mid;\n            } else {\n                low = mid + 1;\n            }\n        }\n\n        unchecked {\n            return high == 0 ? 0 : _unsafeAccess(ckpts, high - 1).votes;\n        }\n    }"
}