Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error prone parsing of bool in encode_typed_data/encoding_and_hashing.py:encode_field #303

Open
Tracked by #296
Philogy opened this issue Oct 6, 2024 · 1 comment
Assignees
Labels

Comments

@Philogy
Copy link

Philogy commented Oct 6, 2024

What happened?

The encode_data method which is the underlying method for EIP712 encoding uses encode_field to encode its fields into the underlying python type. In the case of bool it just uses the python bool method to convert values to booleans, this however leads to very counterintuitive results, with strings like "False", "false", or "0" all getting parsed to True

Code that produced the error

from eth_account._utils.encode_typed_data.encoding_and_hashing import encode_data

if __name__ == '__main__':
    comp = encode_data(
        'Wow',
        {
            'Wow': [
                {'name': 'nice', 'type': 'bool'}
            ]
        },
        {
            'nice': '0' # can substitute for 'False' for same result
        }
    )

    # outputs: aa6fc6f6e625657d3af464fe79175e37e32237d2b4af802593e53cf78ab9a20900000000000000000000000000000000000000000000000000
00000000000001
    print(f'comp.hex(): {comp.hex()}')

Full error output

No response

Fill this section in if you know how this could or should be fixed

  • Change the bool parsing approach to recognize string formatted values like "false" / "False"
  • Be more explicit about parsing, either expecting the already encoded type or rejecting unrecognized versions with an actual error

eth-account Version

0.13.4

Python Version

3.12.4

Operating System

osx

Output from pip freeze

annotated-types==0.7.0
bitarray==2.9.2
ckzg==2.0.1
cytoolz==1.0.0
eth-abi==5.1.0
eth-account==0.13.4
eth-hash==0.7.0
eth-keyfile==0.8.1
eth-keys==0.5.1
eth-rlp==2.1.0
eth-typing==5.0.0
eth-utils==5.0.0
hexbytes==1.2.1
parsimonious==0.10.0
pycryptodome==3.21.0
pydantic==2.9.2
pydantic-core==2.23.4
regex==2024.9.11
rlp==4.0.1
toolz==1.0.0
typing-extensions==4.12.2
@pacrob pacrob self-assigned this Oct 15, 2024
@pacrob
Copy link
Collaborator

pacrob commented Nov 25, 2024

Good point, @Philogy. We'll get it in in the next breaking update cycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants