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 when invoking ambiguous contract functions #3482

Open
falvaradorodriguez opened this issue Sep 11, 2024 · 4 comments
Open

Error when invoking ambiguous contract functions #3482

falvaradorodriguez opened this issue Sep 11, 2024 · 4 comments
Assignees

Comments

@falvaradorodriguez
Copy link

What happened?

Migrating from version 6 to version 7 of the safe-eth-py library we have detected a problem invoking a function of a contract with the same name but ambiguous arguments.

Specifically, the function names are:

isValidSignature(bytes32,bytes) and isValidSignature(bytes,bytes).

The values I am passing as an argument (for example) are:

  • self.safe_hash_preimage = b'\x9c’\xff_!\xf0\xb8\x1b11>c\xf7\xdbm\xa9O\xedxedxef\x11\xb2\x11\x9b@\x88\xb8\x96d\xfb9a<\xb6X‘
  • self.contract_signature = b''.

The code we execute is similar to the one indicated in the guide for this case and in the migration guide from version 6 to 7 I don't see any entry related to this problem.

Code that produced the error

def is_valid(self, ethereum_client: EthereumClient, *args) -> bool:
        compatibility_fallback_handler = get_compatibility_fallback_handler_contract(
            ethereum_client.w3, self.owner
        )
        is_valid_signature_fn = (
            compatibility_fallback_handler.get_function_by_signature(
                "isValidSignature(bytes,bytes)"
            )
        )
        try:
            return is_valid_signature_fn(
                bytes(self.safe_hash_preimage), bytes(self.contract_signature)
            ).call() in (
                self.EIP1271_MAGIC_VALUE,
                self.EIP1271_MAGIC_VALUE_UPDATED,
            )
        except (Web3Exception, DecodingError, Web3ValueError, Web3RPCError):
            # Error using `pending` block identifier or contract does not exist
            logger.warning(
                "Cannot check EIP1271 signature from contract %s", self.owner
            )
        return False

Full error output

Could not identify the intended function with name `isValidSignature`, positional arguments with type(s) `(bytes,bytes)` and keyword arguments with type(s) `{}`.
Found 2 function(s) with the name `isValidSignature`: ['isValidSignature(bytes32,bytes)', 'isValidSignature(bytes,bytes)']
Ambiguous argument encoding. Provided arguments can be encoded to multiple functions matching this call.

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

Debugging the BaseContractFunction call function I see that the execution flow goes through the encode_transaction_data function of web3._utils.contracts.py.

In this function, it is executed:

fn_info = get_abi_element_info(
            contract_abi,
            abi_element_identifier,
            *args,
            abi_codec=w3.codec,
            **kwargs,
        )

where abi_callable, which represents the selected signature, is not being taken into account, so the result will be ambiguous as the arguments are valid for both functions.

web3 Version

7.2.0

Python Version

3.12

Operating System

osx

Output from pip freeze

aiohttp==3.9.5
aiosignal==1.3.1
alabaster==0.7.16
annotated-types==0.7.0
anyio==4.4.0
asgiref==3.8.1
asttokens==2.4.1
attrs==23.2.0
Babel==2.14.0
bitarray==2.9.2
cached-property==1.5.2
certifi==2024.2.2
cffi==1.17.0
cfgv==3.4.0
charset-normalizer==3.3.2
ckzg==2.0.1
click==8.1.7
coverage==7.6.1
cryptography==43.0.0
cytoolz==0.12.3
decorator==5.1.1
Deprecated==1.2.14
distlib==0.3.8
Django==4.2.11
django-filter==24.3
djangorestframework==3.15.2
docutils==0.20.1
eth-account==0.13.3
eth-bloom==3.0.1
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
eth_abi==5.1.0
executing==2.0.1
Faker==28.4.1
filelock==3.13.4
flake8==7.0.0
frozenlist==1.4.1
gitdb==4.0.11
GitPython==3.1.43
h11==0.14.0
hatch==1.12.0
hatchling==1.25.0
hexbytes==1.2.1
httpcore==1.0.5
httpx==0.27.0
hyperlink==21.0.0
identify==2.5.36
idna==3.7
imagesize==1.4.1
iniconfig==2.0.0
ipdb==0.13.13
ipython==8.24.0
isort==5.13.2
jaraco.classes==3.4.0
jaraco.context==6.0.1
jaraco.functools==4.0.2
jedi==0.19.1
Jinja2==3.1.3
jsonschema==4.21.1
jsonschema-specifications==2023.12.1
keyring==25.3.0
lru-dict==1.2.0
markdown-it-py==3.0.0
MarkupSafe==2.1.5
matplotlib-inline==0.1.7
mccabe==0.7.0
mdurl==0.1.2
more-itertools==10.4.0
multidict==6.0.5
mypy==1.11.2
mypy-extensions==1.0.0
nodeenv==1.8.0
packaging==24.1
parsimonious==0.10.0
parso==0.8.4
pathspec==0.12.1
pexpect==4.9.0
platformdirs==4.2.1
pluggy==1.5.0
pre-commit==3.8.0
prompt-toolkit==3.0.43
protobuf==5.26.1
psycopg2-binary==2.9.9
ptyprocess==0.7.0
pure-eval==0.2.2
py-ecc==7.0.1
py-evm==0.10.1b1
pycodestyle==2.11.1
pycparser==2.22
pycryptodome==3.20.0
pydantic==2.9.0
pydantic_core==2.23.2
pyflakes==3.2.0
PyGithub==2.3.0
Pygments==2.17.2
PyJWT==2.9.0
PyNaCl==1.5.0
pytest==8.3.2
pytest-django==4.8.0
pytest-env==1.1.3
pytest-rerunfailures==14.0
pytest-sugar==1.0.0
python-dateutil==2.9.0.post0
pyunormalize==15.1.0
PyYAML==6.0.1
referencing==0.35.0
regex==2024.4.28
requests==2.32.3
rich==13.7.1
rlp==4.0.1
rpds-py==0.18.0
safe-eth-py==5.8.0
safe-pysha3==1.0.4
setuptools==69.5.1
shellingham==1.5.4
six==1.16.0
smmap==5.0.1
sniffio==1.3.1
snowballstemmer==2.2.0
sortedcontainers==2.4.0
Sphinx==7.3.7
sphinx-rtd-theme==2.0.0
sphinxcontrib-applehelp==1.0.8
sphinxcontrib-devhelp==1.0.6
sphinxcontrib-htmlhelp==2.0.5
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.7
sphinxcontrib-serializinghtml==1.1.10
sqlparse==0.5.0
stack-data==0.6.3
termcolor==2.4.0
tomli_w==1.0.0
tomlkit==0.13.2
toolz==0.12.1
traitlets==5.14.3
trie==3.0.1
trove-classifiers==2024.7.2
types-requests==2.32.0.20240712
typing_extensions==4.11.0
tzdata==2024.1
urllib3==2.2.1
userpath==1.9.2
uv==0.2.37
virtualenv==20.26.3
wcwidth==0.2.13
web3==7.2.0
websockets==12.0
wrapt==1.16.0
yarl==1.9.4
zstandard==0.23.0
@reedsa
Copy link
Contributor

reedsa commented Sep 11, 2024

Appreciate you reaching out about this, @falvaradorodriguez

I have found another report of a similar issue happening with overloaded events as well (#1704). I've been working on a fix for these in #3476.

@falvaradorodriguez
Copy link
Author

Thank you very much for your quick response @reedsa!

Perfect, we look forward to this being released in a future release. Thanks.

@reedsa reedsa self-assigned this Sep 13, 2024
@falvaradorodriguez
Copy link
Author

Hi @reedsa!
We have tested with the latest web3 7.4.0 release and we see that the error persists.
Should it have been fixed?
Thanks

@reedsa
Copy link
Contributor

reedsa commented Oct 22, 2024

@falvaradorodriguez thanks for following up on this. I have encountered an issue with the contract caller API that causes conflicts in the functions and events with names that overlap with internal variables of the contract classes. Once I have those nailed down, we will release the fix. The PR that includes these changes are in #3491

reedsa added a commit to reedsa/web3.py that referenced this issue Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants