@@ -29,3 +29,32 @@ The :py:meth:`eth_abi.decoding.BaseDecoder.decode` function provides an API for
2929decoding binary values for ABI types into python values. It accepts a sequence of
3030ABI type strings as the first argument and the binary data to be decoded, as a python
3131``bytes `` or ``bytearray `` value, as the second argument.
32+
33+ Strict Mode
34+ -----------
35+
36+ By default, the decoder will raise an exception if the binary data to be decoded
37+ is not padded to the next 32-byte boundary. This behavior can be disabled for the
38+ ``ByteStringDecoder `` (the default decoder for ``bytes `` and ``string `` types) by
39+ passing ``strict=False `` to the :py:meth: `eth_abi.abi.decode ` method. Turning off
40+ strict mode will also ignore any trailing bytes beyond the data size specified. This
41+ means that if there is any padding, the validation for only empty bytes in the padding
42+ area is also ignored.
43+
44+ .. doctest ::
45+
46+ >>> from eth_abi import abi
47+
48+ >>> # decode a bytes value without strict mode
49+ >>> hex_val = (
50+ ... # offset to data is 32 bytes:
51+ ... " 0000000000000000000000000000000000000000000000000000000000000020"
52+ ... # length of data is 1 byte:
53+ ... " 0000000000000000000000000000000000000000000000000000000000000001"
54+ ... # b"\x01" with less than 32 bytes of padding
55+ ... # and not strictly padded with only zero bytes:
56+ ... " 0100000000000001020300"
57+ ... )
58+ >>> (decoded,) = abi.decode([' bytes' ], bytes .fromhex(hex_val), strict = False )
59+ >>> decoded
60+ b'\x01'
0 commit comments