Skip to content

Commit

Permalink
Docs: Explicitly note solidityKeccak performs a packed encoding. (#1971)
Browse files Browse the repository at this point in the history
* Docs: Explicitly note solidityKeccak performs a packed encoding.

* add newsfragment

Co-authored-by: Marc Garreau <[email protected]>
  • Loading branch information
gnattishness and wolovim authored May 5, 2021
1 parent 48ce4c2 commit f143b0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions docs/web3.main.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Attributes
Returns the current Web3 version.

.. code-block:: python
>>> web3.api
"4.7.0"
Expand Down Expand Up @@ -271,8 +271,8 @@ Cryptographic Hashing
.. py:classmethod:: Web3.solidityKeccak(abi_types, value)
Returns the Keccak-256 as it would be computed by the solidity ``keccak``
function on the provided ``value`` and ``abi_types``. The ``abi_types``
value should be a list of solidity type strings which correspond to each
function on a *packed* ABI encoding of the ``value`` list contents. The ``abi_types``
argument should be a list of solidity type strings which correspond to each
of the provided values.


Expand All @@ -293,6 +293,17 @@ Cryptographic Hashing
>>> Web3.solidityKeccak(['address'], ["ethereumfoundation.eth"])
HexBytes("0x913c99ea930c78868f1535d34cd705ab85929b2eaaf70fcd09677ecd6e5d75e9")
Comparable solidity usage:

.. code-block:: solidity
bytes32 data1 = keccak256(abi.encodePacked(true));
assert(data1 == hex"5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2");
bytes32 data2 = keccak256(abi.encodePacked(uint8(97), uint8(98), uint8(99)));
assert(data2 == hex"4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45");
.. py:classmethod:: Web3.sha3(primitive=None, hexstr=None, text=None)
.. WARNING::
Expand Down
1 change: 1 addition & 0 deletions newsfragments/1971.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarify solidityKeccak documentation.

0 comments on commit f143b0e

Please sign in to comment.