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

web3.eth.contract with no abi #2539

Closed
deandunbar opened this issue Jun 26, 2022 · 4 comments · Fixed by #3137
Closed

web3.eth.contract with no abi #2539

deandunbar opened this issue Jun 26, 2022 · 4 comments · Fixed by #3137

Comments

@deandunbar
Copy link

  • Version: 5.29.1
  • Python: 3.10.4
  • OS: linux
  • pip freeze output
eth-abi==2.1.1
eth-account==0.5.7
eth-hash==0.3.2
eth-keyfile==0.5.1
eth-keys==0.3.4
eth-rlp==0.2.1
eth-typing==2.3.0
eth-utils==1.10.0
web3==5.29.1

What was wrong?

testContract = w3.eth.contract(address=add)
testContract.get_function_by_selector("0x370158ea")
Gives an error:

  File "/home/dean/.local/lib/python3.10/site-packages/web3/_utils/abi.py", line 89, in filter_by_type
    return [abi for abi in contract_abi if abi['type'] == _type]
TypeError: 'NoneType' object is not iterable

running the same commands but with abi included gives the correct value:
testContract = web3.eth.contract(address=add,abi=abi)
testContract.get_function_by_selector("0x370158ea")
<Function info()>

The documentation documentation
Does not show abi as a required parameter when instantiating the Contract class. But all the examples show it being used.
I can instantiate a contract by passing it an address without an abi parameter. But later calls fail. Is this expected behavior?
I should still be able to interact with the bytecode at a specific address as long as I can either generate a function signature or call the selector directly.

Is it expected behavior to require abi for all contract interaction, even those that don't require it?

Please include any of the following that are applicable:

  • The code which produced the error
  • The full output of the error
  • What type of node you were connecting to.

I used a remote infura node. I noticed this issue when working with brownie and verified that it was happening in using web3 directly.

How can it be fixed?

Updating the documentation if this is expected behavior. If this is not expected behavior then adding a check on for set abi on the contract function calls.


Note: We prefer to use issues to track our work. If you think you've encountered a bug in web3py or
have a feature request, you're in the right place. If you have implementation or usage questions,
please refer to our documentation and/or join the conversation
on discord.

@deandunbar
Copy link
Author

deandunbar commented Jun 26, 2022

I want to make sure I reiterate that I know in most common usage of web3.py you would need to have the abi.
I am working on some security tooling to interact with contracts without abi by generating the signature for the function call based on name and input params/expected output type or having the selector.

@kclowes
Copy link
Collaborator

kclowes commented Jun 27, 2022

I believe if you are interacting through a contract instance, the ABI is required. A check and/or documentation could certainly be improved, so I'll leave this open. If you want to work around that, you can just use w3.eth.build_transaction/w3.eth.call/w3.eth.send_transaction etc. What's your use case for interacting with a contract object without the ABI?

@deandunbar
Copy link
Author

Thank you, yes if this is expected behavior I can see about adding to the documentation.

I am working on offensive security tooling for interacting with contracts. The abi is not always available and being able to call the function signature directly helps in certain reversing flows.
To be fair, it sounds like I am working on an edge case and there might not be any merit in merging any of the lower level calls to web3.py.
I can directly call the loaded address and encode the function selector manually via abi.endodeWithSingature("foo(uint256)", "call foo", 123)

I can look at the code, but if the web3.py library is calling the same function under the hood then there is no technical requirement for needing the abi when calling by function selector. If that is the case, is there any reason for enforcing the need of abi for those lower level calls?

@kclowes
Copy link
Collaborator

kclowes commented Jun 29, 2022

Yeah, we do not call abi.encodeWithSignature under the hood. And following the function calls, the ABI does get used a lot, so documenting that the ABI is required is probably the best path for now. Thanks!

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

Successfully merging a pull request may close this issue.

2 participants