{"uuid": "d25f8002-25e0-4495-8537-ce26d6abb8f5", "vulnerability_lookup_origin": "1a89b78e-f703-45f3-bb86-59eb712668bd", "author": "9f56dd64-161d-43a6-b9c3-555944290a09", "vulnerability": "GHSA-g2xh-c426-v8mf", "type": "seen", "source": "https://gist.github.com/FuzzysTodd/4e10f5b327d09a37dc02a2a08f442f94", "content": ".. index:: function, built-in;\n\n.. _built_in_functions:\n\nBuilt-in Functions\n##################\n\nVyper provides a collection of built-in functions available in the global namespace of all contracts.\n\nBitwise Operations\n==================\n\n.. py:function:: bitwise_and(x: uint256, y: uint256) -&gt; uint256\n\n    Perform a \"bitwise and\" operation. Each bit of the output is 1 if the corresponding bit of ``x`` AND of ``y`` is 1, otherwise it is 0.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(x: uint256, y: uint256) -&gt; uint256:\n            return bitwise_and(x, y)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(31337, 8008135)\n        12353\n\n.. note::\n\n  This function has been deprecated from version 0.3.4 onwards. Please use the ``&amp;`` operator instead.\n\n.. py:function:: bitwise_not(x: uint256) -&gt; uint256\n\n    Return the bitwise complement of ``x`` - the number you get by switching each 1 for a 0 and each 0 for a 1.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(x: uint256) -&gt; uint256:\n            return bitwise_not(x)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(0)\n        115792089237316195423570985008687907853269984665640564039457584007913129639935\n\n.. note::\n\n  This function has been deprecated from version 0.3.4 onwards. Please use the ``~`` operator instead.\n\n.. py:function:: bitwise_or(x: uint256, y: uint256) -&gt; uint256\n\n    Perform a \"bitwise or\" operation. Each bit of the output is 0 if the corresponding bit of ``x`` AND of ``y`` is 0, otherwise it is 1.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(x: uint256, y: uint256) -&gt; uint256:\n            return bitwise_or(x, y)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(31337, 8008135)\n        8027119\n\n.. note::\n\n  This function has been deprecated from version 0.3.4 onwards. Please use the ``|`` operator instead.\n\n.. py:function:: bitwise_xor(x: uint256, y: uint256) -&gt; uint256\n\n    Perform a \"bitwise exclusive or\" operation. Each bit of the output is the same as the corresponding bit in ``x`` if that bit in ``y`` is 0, and it is the complement of the bit in ``x`` if that bit in ``y`` is 1.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(x: uint256, y: uint256) -&gt; uint256:\n            return bitwise_xor(x, y)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(31337, 8008135)\n        8014766\n\n.. note::\n\n  This function has been deprecated from version 0.3.4 onwards. Please use the ``^`` operator instead.\n\n.. py:function:: shift(x: int256 | uint256, _shift: integer) -&gt; uint256\n\n    Return ``x`` with the bits shifted ``_shift`` places. A positive ``_shift`` value equals a left shift, a negative value is a right shift.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(x: uint256, y: int128) -&gt; uint256:\n            return shift(x, y)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(2, 8)\n        512\n\n.. note::\n\n  This function has been deprecated from version 0.3.8 onwards. Please use the ``&lt;&lt;`` and ``&gt;&gt;`` operators instead.\n\n\nChain Interaction\n=================\n\n\nVyper has three built-ins for contract creation; all three contract creation built-ins rely on the code to deploy already being stored on-chain, but differ in call vs deploy overhead, and whether or not they invoke the constructor of the contract to be deployed. The following list provides a short summary of the differences between them.\n\n* ``create_minimal_proxy_to(target: address, ...)``\n    * Creates an immutable proxy to ``target``\n    * Expensive to call (incurs a single ``DELEGATECALL`` overhead on every invocation), cheap to create (since it only deploys ``EIP-1167`` forwarder bytecode)\n    * Does not have the ability to call a constructor\n    * Does **not** check that there is code at ``target`` (allows one to deploy proxies counterfactually)\n* ``create_copy_of(target: address, ...)``\n    * Creates a byte-for-byte copy of runtime code stored at ``target``\n    * Cheap to call (no ``DELEGATECALL`` overhead), expensive to create (200 gas per deployed byte)\n    * Does not have the ability to call a constructor\n    * Performs an ``EXTCODESIZE`` check to check there is code at ``target``\n* ``create_from_blueprint(target: address, ...)``\n    * Deploys a contract using the initcode stored at ``target``\n    * Cheap to call (no ``DELEGATECALL`` overhead), expensive to create (200 gas per deployed byte)\n    * Invokes constructor, requires a special \"blueprint\" contract to be deployed\n    * Performs an ``EXTCODESIZE`` check to check there is code at ``target``\n\n.. py:function:: create_minimal_proxy_to(target: address, value: uint256 = 0, revert_on_failure: bool = True[, salt: bytes32]) -&gt; address\n\n    Deploys a small, EIP1167-compliant \"minimal proxy contract\" that duplicates the logic of the contract at ``target``, but has its own state since every call to ``target`` is made using ``DELEGATECALL`` to ``target``. To the end user, this should be indistinguishable from an independently deployed contract with the same code as ``target``.\n\n\n    * ``target``: Address of the contract to proxy to\n    * ``value``: The wei value to send to the new contract address (Optional, default 0)\n    * ``revert_on_failure``: If ``False``, instead of reverting when the create operation fails, return the zero address (Optional, default ``True``)\n    * ``salt``: A ``bytes32`` value utilized by the deterministic ``CREATE2`` opcode (Optional, if not supplied, ``CREATE`` is used)\n\n    Returns the address of the newly created proxy contract. If the create operation fails (for instance, in the case of a ``CREATE2`` collision), execution will revert.\n\n    .. code-block:: vyper\n\n        @external\n        def foo(target: address) -&gt; address:\n            return create_minimal_proxy_to(target)\n\n.. note::\n\n  It is very important that the deployed contract at ``target`` is code you know and trust, and does not implement the ``selfdestruct`` opcode or have upgradeable code as this will affect the operation of the proxy contract.\n\n.. note::\n\n  There is no runtime check that there is code already deployed at ``target`` (since a proxy may be deployed counterfactually). Most applications may want to insert this check.\n\n.. note::\n\n  Before version 0.3.4, this function was named ``create_forwarder_to``.\n\n\n.. py:function:: create_copy_of(target: address, value: uint256 = 0, revert_on_failure: bool = True[, salt: bytes32]) -&gt; address\n\n    Create a physical copy of the runtime code at ``target``. The code at ``target`` is byte-for-byte copied into a newly deployed contract.\n\n    * ``target``: Address of the contract to copy\n    * ``value``: The wei value to send to the new contract address (Optional, default 0)\n    * ``revert_on_failure``: If ``False``, instead of reverting when the create operation fails, return the zero address (Optional, default ``True``)\n    * ``salt``: A ``bytes32`` value utilized by the deterministic ``CREATE2`` opcode (Optional, if not supplied, ``CREATE`` is used)\n\n    Returns the address of the created contract. If the create operation fails (for instance, in the case of a ``CREATE2`` collision), execution will revert. If there is no code at ``target``, execution will revert.\n\n    .. code-block:: vyper\n\n        @external\n        def foo(target: address) -&gt; address:\n            return create_copy_of(target)\n\n.. note::\n\n    The implementation of ``create_copy_of`` assumes that the code at ``target`` is smaller than 16MB. While this is much larger than the EIP-170 constraint of 24KB, it is a conservative size limit intended to future-proof deployer contracts in case the EIP-170 constraint is lifted. If the code at ``target`` is larger than 16MB, the behavior of ``create_copy_of`` is undefined.\n\n\n.. py:function:: create_from_blueprint(target: address, *args, value: uint256 = 0, raw_args: bool = False, code_offset: int = 3, revert_on_failure: bool = True[, salt: bytes32]) -&gt; address\n\n    Copy the code of ``target`` into memory and execute it as initcode. In other words, this operation interprets the code at ``target`` not as regular runtime code, but directly as initcode. The ``*args`` are interpreted as constructor arguments, and are ABI-encoded and included when executing the initcode.\n\n    * ``target``: Address of the blueprint to invoke\n    * ``*args``: Constructor arguments to forward to the initcode.\n    * ``value``: The wei value to send to the new contract address (Optional, default 0)\n    * ``raw_args``: If ``True``, ``*args`` must be a single ``Bytes[...]`` argument, which will be interpreted as a raw bytes buffer to forward to the create operation (which is useful for instance, if pre- ABI-encoded data is passed in from elsewhere). (Optional, default ``False``)\n    * ``code_offset``: The offset to start the ``EXTCODECOPY`` from (Optional, default 3)\n    * ``revert_on_failure``: If ``False``, instead of reverting when the create operation fails, return the zero address (Optional, default ``True``)\n    * ``salt``: A ``bytes32`` value utilized by the deterministic ``CREATE2`` opcode (Optional, if not supplied, ``CREATE`` is used)\n\n    Returns the address of the created contract. If the create operation fails (for instance, in the case of a ``CREATE2`` collision), execution will revert. If ``code_offset &gt;= target.codesize`` (ex. if there is no code at ``target``), execution will revert.\n\n    .. code-block:: vyper\n\n        @external\n        def foo(blueprint: address) -&gt; address:\n            arg1: uint256 = 18\n            arg2: String[32] = \"some string\"\n            return create_from_blueprint(blueprint, arg1, arg2, code_offset=1)\n\n.. note::\n\n    To properly deploy a blueprint contract, special deploy bytecode must be used. The output of ``vyper -f blueprint_bytecode`` will produce bytecode which deploys an ERC-5202 compatible blueprint.\n\n.. note::\n\n  Prior to Vyper version ``0.4.0``, the ``code_offset`` parameter defaulted to ``0``.\n\n.. warning::\n\n    It is recommended to deploy blueprints with an `ERC-5202 `_ preamble like ``0xFE7100`` to guard them from being called as regular contracts. This is particularly important for factories where the constructor has side effects (including ``SELFDESTRUCT``!), as those could get executed by *anybody* calling the blueprint contract directly. The ``code_offset=`` kwarg is provided (and defaults to the ERC-5202 default of 3) to enable this pattern:\n\n    .. code-block:: vyper\n\n        @external\n        def foo(blueprint: address) -&gt; address:\n            # `blueprint` is a blueprint contract with some known preamble b\"abcd...\"\n            return create_from_blueprint(blueprint, code_offset=)\n\n.. py:function:: raw_call(to: address, data: Bytes, max_outsize: uint256 = 0, gas: uint256 = gasLeft, value: uint256 = 0, is_delegate_call: bool = False, is_static_call: bool = False, revert_on_failure: bool = True) -&gt; Bytes[max_outsize]\n\n    Call to the specified Ethereum address.\n\n    * ``to``: Destination address to call to\n    * ``data``: Data to send to the destination address\n    * ``max_outsize``: Maximum length of the bytes array returned from the call. If the returned call data exceeds this length, only this number of bytes is returned. (Optional, default ``0``)\n    * ``gas``: The amount of gas to attach to the call. (Optional, defaults to ``msg.gas``).\n    * ``value``: The wei value to send to the address (Optional, default ``0``)\n    * ``is_delegate_call``: If ``True``, the call will be sent as ``DELEGATECALL`` (Optional, default ``False``)\n    * ``is_static_call``: If ``True``, the call will be sent as ``STATICCALL`` (Optional, default ``False``)\n    * ``revert_on_failure``: If ``True``, the call will revert on a failure, otherwise ``success`` will be returned (Optional, default ``True``)\n\n    .. note::\n\n        Returns the data returned by the call as a ``Bytes`` list, with ``max_outsize`` as the max length. The actual size of the returned data may be less than ``max_outsize``. You can use ``len`` to obtain the actual size.\n\n        Returns nothing if ``max_outsize`` is omitted or set to ``0``.\n\n        Returns ``success`` in a tuple with return value if ``revert_on_failure`` is set to ``False``.\n\n    .. code-block:: vyper\n\n        @external\n        @payable\n        def foo(_target: address) -&gt; Bytes[32]:\n            response: Bytes[32] = raw_call(_target, method_id(\"someMethodName()\"), max_outsize=32, value=msg.value)\n            return response\n\n        @external\n        @payable\n        def bar(_target: address) -&gt; Bytes[32]:\n            success: bool = False\n            response: Bytes[32] = b\"\"\n            x: uint256 = 123\n            success, response = raw_call(\n                _target,\n                abi_encode(x, method_id=method_id(\"someMethodName(uint256)\")),\n                max_outsize=32,\n                value=msg.value,\n                revert_on_failure=False\n                )\n            assert success\n            return response\n\n    .. note::\n\n        Regarding \"forwarding all gas\", note that, while Vyper will provide ``msg.gas`` to the call, in practice, there are some subtleties around forwarding all remaining gas on the EVM which are out of scope of this documentation and could be subject to change. For instance, see the language in EIP-150 around \"all but one 64th\".\n\n.. py:function:: raw_log(topics: bytes32[4], data: Union[Bytes, bytes32]) -&gt; None\n\n    Provides low level access to the ``LOG`` opcodes, emitting a log without having to specify an ABI type.\n\n    * ``topics``: List of ``bytes32`` log topics. The length of this array determines which opcode is used.\n    * ``data``: Unindexed event data to include in the log. May be given as ``Bytes`` or ``bytes32``.\n\n    .. code-block:: vyper\n\n        @external\n        def foo(_topic: bytes32, _data: Bytes[100]):\n            raw_log([_topic], _data)\n\n.. py:function:: raw_revert(data: Bytes) -&gt; None\n\n    Provides low level access to the ``REVERT`` opcode, reverting execution with the specified data returned.\n\n    * ``data``: Data representing the error message causing the revert.\n\n    .. code-block:: vyper\n\n        @external\n        def foo(_data: Bytes[100]):\n            raw_revert(_data)\n\n.. py:function:: selfdestruct(to: address) -&gt; None\n\n    Trigger the ``SELFDESTRUCT`` opcode (``0xFF``), causing the contract to be destroyed.\n\n    * ``to``: Address to forward the contract's ether balance to\n\n    .. warning::\n\n        This method deletes the contract from the blockchain. All non-ether assets associated with this contract are \"burned\" and the contract is no longer accessible.\n\n    .. note::\n\n        This function has been deprecated from version 0.3.8 onwards. The underlying opcode will eventually undergo breaking changes, and its use is not recommended.\n\n    .. code-block:: vyper\n\n        @external\n        def do_the_needful():\n            selfdestruct(msg.sender)\n\n.. py:function:: send(to: address, value: uint256, gas: uint256 = 0) -&gt; None\n\n    Send ether from the contract to the specified Ethereum address.\n\n    * ``to``: The destination address to send ether to\n    * ``value``: The wei value to send to the address\n    * ``gas``: The amount of gas (the \"stipend\") to attach to the call. If not set, the stipend defaults to 0.\n\n    .. note::\n\n        The amount to send is always specified in ``wei``.\n\n    .. code-block:: vyper\n\n        @external\n        def foo(_receiver: address, _amount: uint256, gas: uint256):\n            send(_receiver, _amount, gas=gas)\n\nCryptography\n============\n\n.. py:function:: ecadd(a: uint256[2], b: uint256[2]) -&gt; uint256[2]\n\n    Take two points on the Alt-BN128 curve and add them together.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(x: uint256[2], y: uint256[2]) -&gt; uint256[2]:\n            return ecadd(x, y)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo([1, 2], [1, 2])\n        [\n            1368015179489954701390400359078579693043519447331113978918064868415326638035,\n            9918110051302171585080402603319702774565515993150576347155970296011118125764,\n        ]\n\n.. py:function:: ecmul(point: uint256[2], scalar: uint256) -&gt; uint256[2]\n\n    Take a point on the Alt-BN128 curve (``p``) and a scalar value (``s``), and return the result of adding the point to itself ``s`` times, i.e. ``p * s``.\n\n    * ``point``: Point to be multiplied\n    * ``scalar``: Scalar value\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(point: uint256[2], scalar: uint256) -&gt; uint256[2]:\n            return ecmul(point, scalar)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo([1, 2], 3)\n        [\n            3353031288059533942658390886683067124040920775575537747144343083137631628272,\n            19321533766552368860946552437480515441416830039777911637913418824951667761761,\n        ]\n\n.. py:function:: ecrecover(hash: bytes32, v: uint256 | uint8, r: uint256 | bytes32, s: uint256 | bytes32) -&gt; address\n\n    Recover the address associated with the public key from the given elliptic curve signature.\n\n    * ``r``: first 32 bytes of signature\n    * ``s``: second 32 bytes of signature\n    * ``v``: final 1 byte of signature\n\n    Returns the associated address, or ``empty(address)`` on error.\n\n    .. note::\n\n         Prior to Vyper ``0.3.10``, the ``ecrecover`` function could return an undefined (possibly nonzero) value for invalid inputs to ``ecrecover``. For more information, please see `GHSA-f5x6-7qgp-jhf3 `_.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(hash: bytes32, v: uint8, r:bytes32, s:bytes32) -&gt; address:\n            return ecrecover(hash, v, r, s)\n\n\n        @external\n        @view\n        def foo(hash: bytes32, v: uint256, r:uint256, s:uint256) -&gt; address:\n            return ecrecover(hash, v, r, s)\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo('0x6c9c5e133b8aafb2ea74f524a5263495e7ae5701c7248805f7b511d973dc7055',\n             28,\n             78616903610408968922803823221221116251138855211764625814919875002740131251724,\n             37668412420813231458864536126575229553064045345107737433087067088194345044408\n            )\n        '0x9eE53ad38Bb67d745223a4257D7d48cE973FeB7A'\n\n.. py:function:: keccak256(_value) -&gt; bytes32\n\n    Return a ``keccak256`` hash of the given value.\n\n    * ``_value``: Value to hash. Can be a ``String``, ``Bytes``, or ``bytes32``.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(_value: Bytes[100]) -&gt; bytes32\n            return keccak256(_value)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(b\"potato\")\n        0x9e159dfcfe557cc1ca6c716e87af98fdcb94cd8c832386d0429b2b7bec02754f\n\n.. py:function:: sha256(_value) -&gt; bytes32\n\n    Return a ``sha256`` (SHA2 256-bit output) hash of the given value.\n\n    * ``_value``: Value to hash. Can be a ``String``, ``Bytes``, or ``bytes32``.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(_value: Bytes[100]) -&gt; bytes32\n            return sha256(_value)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(b\"potato\")\n        0xe91c254ad58860a02c788dfb5c1a65d6a8846ab1dc649631c7db16fef4af2dec\n\nData Manipulation\n=================\n\n.. py:function:: concat(a, b, *args) -&gt; Union[Bytes, String]\n\n    Take 2 or more bytes arrays of type ``bytesM``, ``Bytes`` or ``String`` and combine them into a single value.\n\n    If the input arguments are ``String`` the return type is ``String``.  Otherwise the return type is ``Bytes``.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(a: String[5], b: String[5], c: String[5]) -&gt; String[100]:\n            return concat(a, \" \", b, \" \", c, \"!\")\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(\"why\",\"hello\",\"there\")\n        \"why hello there!\"\n\n.. py:function:: convert(value, type_) -&gt; Any\n\n    Converts a variable or literal from one type to another.\n\n    * ``value``: Value to convert\n    * ``type_``: The destination type to convert to (e.g., ``bool``, ``decimal``, ``int128``, ``uint256`` or ``bytes32``)\n\n    Returns a value of the type specified by ``type_``.\n\n    For more details on available type conversions, see :ref:`type_conversions`.\n\n.. py:function:: uint2str(value: unsigned integer) -&gt; String\n\n    Returns an unsigned integer's string representation.\n\n    * ``value``: Unsigned integer to convert.\n\n    Returns the string representation of ``value``.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(b: uint256) -&gt; String[78]:\n            return uint2str(b)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(420)\n        \"420\"\n\n.. py:function:: extract32(b: Bytes, start: uint256, output_type=bytes32) -&gt; Any\n\n    Extract a value from a ``Bytes`` list.\n\n    * ``b``: ``Bytes`` list to extract from\n    * ``start``: Start point to extract from\n    * ``output_type``: Type of output (``bytesM``, ``integer``, or ``address``). Defaults to ``bytes32``.\n\n    Returns a value of the type specified by ``output_type``.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(b: Bytes[32]) -&gt; address:\n            return extract32(b, 0, output_type=address)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(\"0x0000000000000000000000009f8F72aA9304c8B593d555F12eF6589cC3A579A2\")\n        \"0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2\"\n\n.. py:function:: slice(b: Union[Bytes, bytes32, String], start: uint256, length: uint256) -&gt; Union[Bytes, String]\n\n    Copy a list of bytes and return a specified slice.\n\n    * ``b``: value being sliced\n    * ``start``: start position of the slice\n    * ``length``: length of the slice\n\n    If the value being sliced is a ``Bytes`` or ``bytes32``, the return type is ``Bytes``.  If it is a ``String``, the return type is ``String``.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(s: String[32]) -&gt; String[5]:\n            return slice(s, 4, 5)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(\"why hello! how are you?\")\n        \"hello\"\n\nMath\n====\n\n.. py:function:: abs(value: int256) -&gt; int256\n\n    Return the absolute value of a signed integer.\n\n    * ``value``: Integer to return the absolute value of\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(value: int256) -&gt; int256:\n            return abs(value)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(-31337)\n        31337\n\n.. py:function:: ceil(value: decimal) -&gt; int256\n\n    Round a decimal up to the nearest integer.\n\n    * ``value``: Decimal value to round up\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(x: decimal) -&gt; int256:\n            return ceil(x)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(3.1337)\n        4\n\n.. py:function:: epsilon(typename) -&gt; Any\n\n    Returns the smallest non-zero value for a decimal type.\n\n    * ``typename``: Name of the decimal type (currently only ``decimal``)\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo() -&gt; decimal:\n            return epsilon(decimal)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo()\n        Decimal('1E-10')\n\n.. py:function:: floor(value: decimal) -&gt; int256\n\n    Round a decimal down to the nearest integer.\n\n    * ``value``: Decimal value to round down\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(x: decimal) -&gt; int256:\n            return floor(x)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(3.1337)\n        3\n\n.. py:function:: max(a: numeric, b: numeric) -&gt; numeric\n\n    Return the greater value of ``a`` and ``b``. The input values may be any numeric type as long as they are both of the same type.  The output value is of the same type as the input values.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(a: uint256, b: uint256) -&gt; uint256:\n            return max(a, b)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(23, 42)\n        42\n\n.. py:function:: max_value(type_) -&gt; numeric\n\n    Returns the maximum value of the numeric type specified by ``type_`` (e.g., ``int128``, ``uint256``, ``decimal``).\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo() -&gt; int256:\n            return max_value(int256)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo()\n        57896044618658097711785492504343953926634992332820282019728792003956564819967\n\n.. py:function:: min(a: numeric, b: numeric) -&gt; numeric\n\n    Returns the lesser value of ``a`` and ``b``. The input values may be any numeric type as long as they are both of the same type.  The output value is of the same type as the input values.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(a: uint256, b: uint256) -&gt; uint256:\n            return min(a, b)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(23, 42)\n        23\n\n.. py:function:: min_value(type_) -&gt; numeric\n\n    Returns the minimum value of the numeric type specified by ``type_`` (e.g., ``int128``, ``uint256``, ``decimal``).\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo() -&gt; int256:\n            return min_value(int256)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo()\n        -57896044618658097711785492504343953926634992332820282019728792003956564819968\n\n.. py:function:: pow_mod256(a: uint256, b: uint256) -&gt; uint256\n\n    Return the result of ``a ** b % (2 ** 256)``.\n\n    This method is used to perform exponentiation without overflow checks.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(a: uint256, b: uint256) -&gt; uint256:\n            return pow_mod256(a, b)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(2, 3)\n        8\n        &gt;&gt;&gt; ExampleContract.foo(100, 100)\n        59041770658110225754900818312084884949620587934026984283048776718299468660736\n\n.. py:function:: sqrt(d: decimal) -&gt; decimal\n\n    Return the square root of the provided decimal number, using the Babylonian square root algorithm.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(d: decimal) -&gt; decimal:\n            return sqrt(d)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(9.0)\n        3.0\n\n.. py:function:: isqrt(x: uint256) -&gt; uint256\n\n    Return the (integer) square root of the provided integer number, using the Babylonian square root algorithm. The rounding mode is to round down to the nearest integer. For instance, ``isqrt(101) == 10``.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(x: uint256) -&gt; uint256:\n            return isqrt(x)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(101)\n        10\n\n.. py:function:: uint256_addmod(a: uint256, b: uint256, c: uint256) -&gt; uint256\n    \n    Return the modulo of ``(a + b) % c``. Reverts if ``c == 0``. As this built-in function is intended to provides access to the underlying ``ADDMOD`` opcode, all intermediate calculations of this operation are not subject to the ``2 ** 256`` modulo according to the EVM specifications.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(a: uint256, b: uint256, c: uint256) -&gt; uint256:\n            return uint256_addmod(a, b, c)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; (6 + 13) % 8\n        3\n        &gt;&gt;&gt; ExampleContract.foo(6, 13, 8)\n        3\n\n.. py:function:: uint256_mulmod(a: uint256, b: uint256, c: uint256) -&gt; uint256\n\n    Return the modulo from ``(a * b) % c``. Reverts if ``c == 0``. As this built-in function is intended to provides access to the underlying ``MULMOD`` opcode, all intermediate calculations of this operation are not subject to the ``2 ** 256`` modulo according to the EVM specifications.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(a: uint256, b: uint256, c: uint256) -&gt; uint256:\n            return uint256_mulmod(a, b, c)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; (11 * 2) % 5\n        2\n        &gt;&gt;&gt; ExampleContract.foo(11, 2, 5)\n        2\n\n.. py:function:: unsafe_add(x: integer, y: integer) -&gt; integer\n\n    Add ``x`` and ``y``, without checking for overflow. ``x`` and ``y`` must both be integers of the same type. If the result exceeds the bounds of the input type, it will be wrapped.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(x: uint8, y: uint8) -&gt; uint8:\n            return unsafe_add(x, y)\n\n        @external\n        @view\n        def bar(x: int8, y: int8) -&gt; int8:\n            return unsafe_add(x, y)\n\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(1, 1)\n        2\n\n        &gt;&gt;&gt; ExampleContract.foo(255, 255)\n        254\n\n        &gt;&gt;&gt; ExampleContract.bar(127, 127)\n        -2\n\n.. note::\n    Performance note: for the native word types of the EVM ``uint256`` and ``int256``, this will compile to a single ``ADD`` instruction, since the EVM natively wraps addition on 256-bit words.\n\n.. py:function:: unsafe_sub(x: integer, y: integer) -&gt; integer\n\n    Subtract ``x`` and ``y``, without checking for overflow. ``x`` and ``y`` must both be integers of the same type. If the result underflows the bounds of the input type, it will be wrapped.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(x: uint8, y: uint8) -&gt; uint8:\n            return unsafe_sub(x, y)\n\n        @external\n        @view\n        def bar(x: int8, y: int8) -&gt; int8:\n            return unsafe_sub(x, y)\n\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(4, 3)\n        1\n\n        &gt;&gt;&gt; ExampleContract.foo(0, 1)\n        255\n\n        &gt;&gt;&gt; ExampleContract.bar(-128, 1)\n        127\n\n.. note::\n    Performance note: for the native word types of the EVM ``uint256`` and ``int256``, this will compile to a single ``SUB`` instruction, since the EVM natively wraps subtraction on 256-bit words.\n\n\n.. py:function:: unsafe_mul(x: integer, y: integer) -&gt; integer\n\n    Multiply ``x`` and ``y``, without checking for overflow. ``x`` and ``y`` must both be integers of the same type. If the result exceeds the bounds of the input type, it will be wrapped.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(x: uint8, y: uint8) -&gt; uint8:\n            return unsafe_mul(x, y)\n\n        @external\n        @view\n        def bar(x: int8, y: int8) -&gt; int8:\n            return unsafe_mul(x, y)\n\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(1, 1)\n        1\n\n        &gt;&gt;&gt; ExampleContract.foo(255, 255)\n        1\n\n        &gt;&gt;&gt; ExampleContract.bar(-128, -128)\n        0\n\n        &gt;&gt;&gt; ExampleContract.bar(127, -128)\n        -128\n\n.. note::\n    Performance note: for the native word types of the EVM ``uint256`` and ``int256``, this will compile to a single ``MUL`` instruction, since the EVM natively wraps multiplication on 256-bit words.\n\n\n.. py:function:: unsafe_div(x: integer, y: integer) -&gt; integer\n\n    Divide ``x`` and ``y``, without checking for division-by-zero. ``x`` and ``y`` must both be integers of the same type. If the denominator is zero, the result will (following EVM semantics) be zero.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(x: uint8, y: uint8) -&gt; uint8:\n            return unsafe_div(x, y)\n\n        @external\n        @view\n        def bar(x: int8, y: int8) -&gt; int8:\n            return unsafe_div(x, y)\n\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(1, 1)\n        1\n\n        &gt;&gt;&gt; ExampleContract.foo(1, 0)\n        0\n\n        &gt;&gt;&gt; ExampleContract.bar(-128, -1)\n        -128\n\n.. note::\n    Performance note: this will compile to a single ``SDIV`` or ``DIV`` instruction, depending on if the inputs are signed or unsigned (respectively).\n\n\nUtilities\n=========\n\n.. py:function:: as_wei_value(_value, unit: str) -&gt; uint256\n\n    Take an amount of ether currency specified by a number and a unit and return the integer quantity of wei equivalent to that amount.\n\n    * ``_value``: Value for the ether unit. Any numeric type may be used, however the value cannot be negative.\n    * ``unit``: Ether unit name (e.g. ``\"wei\"``, ``\"ether\"``, ``\"gwei\"``, etc.) indicating the denomination of ``_value``. Must be given as a literal string.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(s: String[32]) -&gt; uint256:\n            return as_wei_value(1.337, \"ether\")\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(1)\n        1337000000000000000\n\n.. py:function:: blockhash(block_num: uint256) -&gt; bytes32\n\n    Return the hash of the block at the specified height.\n\n    .. note::\n\n        The EVM only provides access to the most recent 256 blocks. This function reverts if the block number is greater than or equal to the current block number or more than 256 blocks behind the current block.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo() -&gt; bytes32:\n            return blockhash(block.number - 16)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo()\n        0xf3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n\n.. py:function:: blobhash(index: uint256) -&gt; bytes32\n\n    Return the versioned hash of the ``index``-th BLOB associated with the current transaction.\n\n    .. note::\n\n         A versioned hash consists of a single byte representing the version (currently ``0x01``), followed by the last 31 bytes of the ``SHA256`` hash of the KZG commitment (`EIP-4844 `_). For the case ``index &gt;= len(tx.blob_versioned_hashes)``, ``blobhash(index: uint256)`` returns ``empty(bytes32)``.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(index: uint256) -&gt; bytes32:\n            return blobhash(index)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(0)\n        0xfd28610fb309939bfec12b6db7c4525446f596a5a5a66b8e2cb510b45b2bbeb5\n\n        &gt;&gt;&gt; ExampleContract.foo(6)\n        0x0000000000000000000000000000000000000000000000000000000000000000\n\n\n.. py:function:: empty(typename) -&gt; Any\n\n    Return a value which is the default (zero-ed) value of its type. Useful for initializing new memory variables.\n\n    * ``typename``: Name of the type, except ``HashMap[_KeyType, _ValueType]``\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo():\n            x: uint256[2][5] = empty(uint256[2][5])\n\n.. py:function:: len(b: Union[Bytes, String, DynArray[_Type, _Integer]]) -&gt; uint256\n\n    Return the length of a given ``Bytes``, ``String`` or ``DynArray[_Type, _Integer]``.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(s: String[32]) -&gt; uint256:\n            return len(s)\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo(\"hello\")\n        5\n\n.. py:function:: method_id(method, output_type: type = Bytes[4]) -&gt; Union[Bytes[4], bytes4]\n\n    Takes a function declaration and returns its method_id (used in data field to call it).\n\n    * ``method``: Method declaration as given as a literal string\n    * ``output_type``: The type of output (``Bytes[4]`` or ``bytes4``). Defaults to ``Bytes[4]``.\n\n    Returns a value of the type specified by ``output_type``.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo() -&gt; Bytes[4]:\n            return method_id('transfer(address,uint256)', output_type=Bytes[4])\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo()\n\t0xa9059cbb\n\n.. py:function:: abi_encode(*args, ensure_tuple: bool = True) -&gt; Bytes[]\n\n    Takes a variable number of args as input, and returns the ABIv2-encoded bytestring. Used for packing arguments to raw_call, EIP712 and other cases where a consistent and efficient serialization method is needed.\n    Once this function has seen more use we provisionally plan to put it into the ``ethereum.abi`` namespace.\n\n    * ``*args``: Arbitrary arguments\n    * ``ensure_tuple``: If set to True, ensures that even a single argument is encoded as a tuple. In other words, ``bytes`` gets encoded as ``(bytes,)``, and ``(bytes,)`` gets encoded as ``((bytes,),)`` This is the calling convention for Vyper and Solidity functions. Except for very specific use cases, this should be set to True. Must be a literal.\n    * ``method_id``: A literal hex or Bytes[4] value to append to the beginning of the abi-encoded bytestring.\n\n    Returns a bytestring whose max length is determined by the arguments. For example, encoding a ``Bytes[32]`` results in a ``Bytes[64]`` (first word is the length of the bytestring variable).\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo() -&gt; Bytes[132]:\n            x: uint256 = 1\n            y: Bytes[32] = b\"234\"\n            return abi_encode(x, y, method_id=method_id(\"foo()\"))\n\n    .. code-block:: vyper\n\n        &gt;&gt;&gt; ExampleContract.foo().hex()\n        \"c2985578\"\n        \"0000000000000000000000000000000000000000000000000000000000000001\"\n        \"0000000000000000000000000000000000000000000000000000000000000040\"\n        \"0000000000000000000000000000000000000000000000000000000000000003\"\n        \"3233340000000000000000000000000000000000000000000000000000000000\"\n\n    .. note::\n        Prior to v0.4.0, this function was named ``_abi_encode``.\n\n\n.. py:function:: abi_decode(b: Bytes, output_type: type_, unwrap_tuple: bool = True) -&gt; Any\n\n    Takes a byte array as input, and returns the decoded values according to the specified output types. Used for unpacking ABIv2-encoded values.\n    Once this function has seen more use we provisionally plan to put it into the ``ethereum.abi`` namespace.\n\n    * ``b``: A byte array of a length that is between the minimum and maximum ABIv2 size bounds of the ``output type``.\n    * ``output_type``: Name of the output type, or tuple of output types, to be decoded.\n    * ``unwrap_tuple``: If set to True, the input is decoded as a tuple even if only one output type is specified. In other words, ``abi_decode(b, Bytes[32])`` gets decoded as ``(Bytes[32],)``. This is the convention for ABIv2-encoded values generated by Vyper and Solidity functions. Except for very specific use cases, this should be set to True. Must be a literal.\n\n    Returns the decoded value(s), with type as specified by `output_type`.\n\n    .. code-block:: vyper\n\n        @external\n        @view\n        def foo(someInput: Bytes[128]) -&gt; (uint256, Bytes[32]):\n            x: uint256 = empty(uint256)\n            y: Bytes[32] = empty(Bytes[32])\n            x, y =  abi_decode(someInput, (uint256, Bytes[32]))\n            return x, y\n\n    .. note::\n        Prior to v0.4.0, this function was named ``_abi_decode``.\n\n\n.. py:function:: print(*args, hardhat_compat=False) -&gt; None\n\n    \"prints\" the arguments by issuing a static call to the \"console\" address, ``0x000000000000000000636F6E736F6C652E6C6F67``. This is supported by some smart contract development frameworks.\n\n    The default mode works natively with titanoboa. For hardhat-style frameworks, use ``hardhat_compat=True)``.\n\n.. note::\n\n    Issuing of the static call is *NOT* mode-dependent (that is, it is not removed from production code), although the compiler will issue a warning whenever ``print`` is used.\n\n.. warning::\n    In Vyper, as of v0.4.0, the order of argument evaluation of builtins is not defined. That means that the compiler may choose to reorder evaluation of arguments. For example, ``extract32(x(), y())`` may yield unexpected results if ``x()`` and ``y()`` both touch the same data. For this reason, it is best to avoid calling functions with side-effects inside of builtins. For more information, see `GHSA-g2xh-c426-v8mf `_ and `issue #4019 `_.\n", "creation_timestamp": "2026-05-21T00:45:42.000000Z"}