Skip to content

Commit 3edd2e1

Browse files
ustas-ethr0qs
authored andcommitted
[docs] Add warning about codehash behavior depending on the account state
Co-authored-by: r0qs <[email protected]>
1 parent d6fa849 commit 3edd2e1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

docs/types/value-types.rst

+7
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ You can query the deployed code for any smart contract. Use ``.code`` to get the
344344
``bytes memory``, which might be empty. Use ``.codehash`` to get the Keccak-256 hash of that code
345345
(as a ``bytes32``). Note that ``addr.codehash`` is cheaper than using ``keccak256(addr.code)``.
346346

347+
.. warning::
348+
The output of ``addr.codehash`` may be ``0`` if the account associated with ``addr`` is empty or non-existent
349+
(i.e., it has no code, zero balance, and zero nonce as defined by `EIP-161 <https://eips.ethereum.org/EIPS/eip-161>`_).
350+
If the account has no code but a non-zero balance or nonce, then ``addr.codehash`` will output the Keccak-256 hash of empty data
351+
(i.e., ``keccak256("")`` which is equal to ``c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470``), as defined by
352+
`EIP-1052 <https://eips.ethereum.org/EIPS/eip-1052>`_.
353+
347354
.. note::
348355
All contracts can be converted to ``address`` type, so it is possible to query the balance of the
349356
current contract using ``address(this).balance``.

0 commit comments

Comments
 (0)