ethereum / web3.py

A python interface for interacting with the Ethereum blockchain and ecosystem.
http://web3py.readthedocs.io
MIT License
4.96k stars 1.69k forks source link

Deploying a contract is broken with `PyEVMBackend()` #1212

Closed njgheorghita closed 5 years ago

njgheorghita commented 5 years ago
appnope==0.1.0
asn1crypto==0.24.0
attrdict==2.0.0
backcall==0.1.0
certifi==2018.11.29
cffi==1.11.5
chardet==3.0.4
cryptography==2.4.2
cytoolz==0.9.0.1
decorator==4.3.0
eth-abi==2.0.0b4
eth-account==0.3.0
eth-bloom==1.0.3
eth-hash==0.2.0
eth-keyfile==0.5.1
eth-keys==0.2.1
eth-rlp==0.1.2
eth-tester==0.1.0b36
eth-typing==2.0.0
eth-utils==1.4.1
hexbytes==0.1.0
idna==2.8
ipython==7.2.0
ipython-genutils==0.2.0
jedi==0.13.2
lru-dict==1.1.6
mypy-extensions==0.4.1
parsimonious==0.8.1
parso==0.3.1
pexpect==4.6.0
pickleshare==0.7.5
prompt-toolkit==2.0.7
ptyprocess==0.6.0
py-ecc==1.4.7
py-evm==0.2.0a39
py-geth==2.0.1
pycparser==2.19
pycryptodome==3.7.2
pyethash==0.1.27
Pygments==2.3.1
requests==2.21.0
rlp==1.1.0
semantic-version==2.6.0
six==1.12.0
toolz==0.9.0
traitlets==4.3.2
trie==1.3.8
urllib3==1.24.1
wcwidth==0.1.7
web3==5.0.0a3
websockets==7.0

What was wrong?

Trying to deploy a contract is broken when using PyEVMBackend() for Web3.EthereumTesterProvider.

w3 = Web3(Web3.EthereumTesterProvider(PyEVMBackend()))
contract_factory = w3.eth.contract(abi=abi, bytecode=bytecode)
tx_hash = contract_factory.constructor().transact()

The final line breaks and raises this error...

~/ethereum/py-ethpm/trash-venv/lib/python3.6/site-packages/eth/validation.py in validate_canonical_address(value, title)
    139     if not isinstance(value, bytes) or not len(value) == 20:
    140         raise ValidationError(
--> 141             "{title} {0} is not a valid canonical address".format(value, title=title)
    142         )
    143

ValidationError: Storage Address 0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf is not a valid canonical address

How can it be fixed?

No clue, I spent a fair amount of time digging around eth-tester to try and resolve, but no luck. My best guess is that it's a result of the recent eth-tester and py-evm upgrades. The same code works fine if Web3.EthereumTesterProvider() is instantiated as empty (aka with implicit MockBackend)

pipermerriam commented 5 years ago

Very likely that some normalization was accidentally removed. Full-ish stacktrace might make it a bit clearer where/why but somewhere a hex address is making it's way into the backend that should have been converted to a bytes address (canonical format).

Find the spot in your stacktrace where we exit the eth-tester code and transition into the py-evm code and trace your way up from there to figure out how the hex formatted address is making it's way through.