Giter Site home page Giter Site logo

Comments (4)

reedsa avatar reedsa commented on August 16, 2024 1

@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.

alebaffa avatar alebaffa commented on August 16, 2024 1

oh I see thank you guys!

from eth-abi.

alebaffa avatar alebaffa commented on August 16, 2024

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.

fselmo avatar fselmo commented on August 16, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.