ethereum / eth-account

Account abstraction library for web3.py
http://eth-account.readthedocs.io/
MIT License
258 stars 155 forks source link

sign_transaction doesn't accept access_list which created by web3-py #286

Closed Nov1kov closed 1 month ago

Nov1kov commented 2 months ago

What happened?

According that issue in web3 py, the method sign_transaction in eth-account should allow the flow:

result = web3.eth.create_access_list(tx)
tx['accessList'] = result['accessList']
signed_tx = account.sign_transaction(tx)
web3.send_raw_transaction(signed_tx)

In my case, eth-account == 0.13.0 couldn't validate the HexBytes in "storageKeys" without workaround:

    for al in result['accessList']:
        for i, sk in enumerate(al['storageKeys']):
            al['storageKeys'][i] = sk.hex()

Code that produced the error

No response

Full error output

return transaction, self.bot_account.sign_transaction(transaction).raw_transaction
.venv-311\Lib\site-packages\eth_account\signers\local.py:84: in sign_transaction
    return self._publicapi.sign_transaction(transaction_dict, self.key, blobs=blobs)
.venv-311\Lib\site-packages\eth_utils\decorators.py:20: in _wrapper
    return self.method(objtype, *args, **kwargs)
.venv-311\Lib\site-packages\eth_account\account.py:801: in sign_transaction
    ) = sign_transaction_dict(account._key_obj, sanitized_transaction, blobs=blobs)
.venv-311\Lib\site-packages\eth_account\_utils\signing.py:32: in sign_transaction_dict
    unsigned_transaction = serializable_unsigned_transaction_from_dict(
.venv-311\Lib\site-packages\eth_account\_utils\legacy_transactions.py:43: in serializable_unsigned_transaction_from_dict
    return TypedTransaction.from_dict(transaction_dict, blobs=blobs)
.venv-311\Lib\site-packages\eth_account\typed_transactions\typed_transaction.py:97: in from_dict
    transaction=transaction.from_dict(dictionary, blobs=blobs),
.venv-311\Lib\site-packages\eth_account\typed_transactions\dynamic_fee_transaction.py:147: in from_dict
....
    cls.assert_valid_fields(dictionary)
        if not all(valid_fields.values()):
            invalid = {
                key: dictionary[key] for key, valid in valid_fields.items() if not valid
            }
>           raise TypeError(f"Transaction had invalid fields: {repr(invalid)}")
E           TypeError: Transaction had invalid fields: {'accessList': [AttributeDict({'address': ....

.venv-311\Lib\site-packages\eth_account\typed_transactions\dynamic_fee_transaction.py:133: TypeError


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

[That check](https://github.com/ethereum/eth-account/blob/c64c402b43acb3bea64314ee1e8558e71c6bcc62/eth_account/_utils/validation.py#L77_) doesn't allow `HexBytes` in storageKey. 

### eth-account Version

0.13.0

### Python Version

3.11.9

### Operating System

linux/win

### Output from `pip freeze`

_No response_
pacrob commented 1 month ago

Thanks for the issue! web3 was indeed providing HexBytes when it shouldn't have been. It's been fixed here and will be available in the next v7 beta release. Stable v7 release coming soon.