Comments (4)
@alebaffa In your examples, the data includes offsets which declare the position of the values when decoding the bytes
values. In the second case, your positions are finding the values relative to the beginning of the data. When you add the address
topics, the data positions change and thus must be reflected in the bytes headers.
I've added a few tests to illustrate this in https://github.com/ethereum/eth-abi/pull/228/files
from eth-abi.
oh I see thank you guys!
from eth-abi.
I keep testing and I found that, from the test above, if I keep only the Data fields (i.e. amount
, data
, operatorData
):
["uint256", "bytes", "bytes"],
(
# Data
"0000000000000000000000000000000000000000000004a8f8176590b4e9237f"
"000000000000000000000000000000000000000000000000000000000000006"
"0000000000000000000000000000000000000000000000000000000000000008"
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
),
the decode correctly returns empty bytes where the fields are empty:
(22006395804779840873343, b'', b'')
In this case, the value returns an empty byte as expected:
class HeadTailDecoder(BaseDecoder):
....
def decode(self, stream):
start_pos = decode_uint_256(stream)
stream.push_frame(start_pos)
value = self.tail_decoder(stream) # <--- correctly returns an empty bytes. While in the previous test - with all the other fields too - this fails.
stream.pop_frame()
return value
So the problem seems to be in ByteStringDecoder
:
def read_data_from_stream(self, stream):
data_length = decode_uint_256(stream)
padded_length = ceil32(data_length)
data = stream.read(padded_length) # <--- this fails in the previous test, but it is OK now.
specifically, in the previous failing test the data_length
and padded_length
were different by one digit:
data_length: 22006395804779840873343 # <--- this is actually the value of the`amount` field in the data
data_length: 22006395804779840873344
while in this second successful test they are both 0
and everything works.
So it seems that decode
cannot handle properly topics + data
when some of the data fields are empty bytes.
from eth-abi.
@reedsa good summary. The topics
and the log data
are separate parts of the transaction receipt log and so the data
field contains position information if you were to decode it separately, not along with the topics
. To illustrate this exact transaction using web3.py:
>>> from web3 import Web3, HTTPProvider
>>> from eth_abi import abi
>>> w3 = Web3(HTTPProvider(provider_url))
>>> tx_receipt = w3.eth.get_transaction_receipt("0x128bae16288948bdeead21cbd662bdebae0c25ebb0817741e4577ee83b6339a2")
>>> log_in_question = tx_receipt["logs"][2]
>>> log_in_question["topics"] # returns topics [0, 1: operator, 2: from, 3: to]
[HexBytes('0x06b541ddaa720db2b10a4d0cdac39b8d360425fc073085fac19bc82614677987'),
HexBytes('0x000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3'),
HexBytes('0x00000000000000000000000050650a86840e5c4c46641a9435418b7458458747'),
HexBytes('0x00000000000000000000000098409d8ca9629fbe01ab1b914ebf304175e384c8')]
>>> abi.decode(['uint256', 'bytes', 'bytes'], log_in_question["data"])
(22006395804779840873343, b'', b'')
from eth-abi.
Related Issues (20)
- Unable to decode Arrays of Structs HOT 4
- ImportError: cannot import name 'encode' from 'eth_abi' HOT 2
- Is there a way to match calldata/memory encoding conventions? HOT 1
- Decoding data of type byte[] array results in an an empty element at the end HOT 3
- Byte value of length 32b results in decoding error using 'decode' HOT 2
- Decoding an array type returns a tuple instead of list HOT 5
- `ImportError: cannot import name 'getargspec' from 'inspect'` in Python >= 3.11 due to outdated `parsimonious` dependency version
- Wrong encoding output when using uint256[] HOT 1
- Decoding arbitrary length bytes fails due to expected padding HOT 2
- encoding tuple with nested tuple containing dynamic types HOT 3
- [Project Management] When will eth-abi>=4.0.0 be released? HOT 2
- Dependency errors for newer versions of uth-utils>=2.0.0 and eth-abi>=3.0.0
- Different behaviour: `encode_single` vs `encode` HOT 9
- typing/linting tools review
- Add utility method for getting an acceptable byte range from a list of ABI types
- OverflowError: Python int too large to convert to C ssize_t HOT 5
- decode failing on input that is not divided by 32 HOT 1
- Replace `functools.lru_cache`
- Decode input data with bad padding HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eth-abi.