0xProject / 0x-launch-kit-backend

Launch a 0x relayer in under a minute [DEPRECATED]
Other
173 stars 265 forks source link

EIP-55 checksummed addresses not supported #73

Open feuGeneA opened 5 years ago

feuGeneA commented 5 years ago

In publishing the latest versions of the 0x Python packages, we're migrating from v4 to v5 of Web3.py. v5 will not accept any non-checksummed addresses for any inputs to any contracts.

We have an end-to-end tested example of the Python SRA client, which creates an order, posts it to the Launch Kit backend, retrieves the order from the order book, and then fills the order. After migrating this example to v5 of Web3.py, this test is failing with the following output:

131 ...     expirationTimeSeconds=round(
132 ...         (datetime.utcnow() + timedelta(days=1)).timestamp()
133 ...     )
134 ... )
135 
136 >>> from zero_ex.order_utils import generate_order_hash_hex
137 >>> order_hash_hex = generate_order_hash_hex(
138 ...     order, contract_addresses.exchange
139 ... )
140 >>> relayer.post_order_with_http_info(
UNEXPECTED EXCEPTION: ApiException()
Traceback (most recent call last):

  File "/home/gene/.pythonz/pythons/CPython-3.7.2/lib/python3.7/doctest.py", line 1329, in __run
    compileflags, 1), test.globs)

  File "<doctest zero_ex.sra_client[21]>", line 7, in <module>

  File "/home/gene/dev/0x-monorepo/python-packages/sra_client/src/zero_ex/sra_client/api/default_api.py", line 1096, in post_order_with_http_info
    collection_formats=collection_formats,

  File "/home/gene/dev/0x-monorepo/python-packages/sra_client/src/zero_ex/sra_client/api_client.py", line 385, in call_api
    _request_timeout,

  File "/home/gene/dev/0x-monorepo/python-packages/sra_client/src/zero_ex/sra_client/api_client.py", line 183, in __call_api
    _request_timeout=_request_timeout,

  File "/home/gene/dev/0x-monorepo/python-packages/sra_client/src/zero_ex/sra_client/api_client.py", line 455, in request
    body=body,

  File "/home/gene/dev/0x-monorepo/python-packages/sra_client/src/zero_ex/sra_client/rest.py", line 349, in POST
    body=body,

  File "/home/gene/dev/0x-monorepo/python-packages/sra_client/src/zero_ex/sra_client/rest.py", line 253, in request
    raise ApiException(http_resp=r)

zero_ex.sra_client.rest.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'X-Powered-By': 'Express', 'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '267', 'ETag': 'W/"10b-nhI1Hv/zADdsZ/uIGTlKZ6WiCIo"', 'Date': 'Wed, 07 Aug 2019 23:32:56 GMT', 'Connection': 'keep-alive'})
HTTP response body: {"code":100,"reason":"Validation Failed","validationErrors":[{"field":"instance","code":1001,"reason":"does not match allOf schema </orderSchema> with 1 error[s]:"},{"field":"instance.makerAddress","code":1001,"reason":"does not match pattern \"^0x[0-9a-f]{40}$\""}]}

/home/gene/dev/0x-monorepo/python-packages/sra_client/src/zero_ex/sra_client/__init__.py:140: UnexpectedException

The reason for the failure is that the example is sending a checksummed (mixed case) address for the makerAddress, and this build of Launch Kit is verifying that address against an old version of @0x/json-schemas. In version 3.1.1.1 the schemas were updated to allow for mixed case addresses.

However, simply accepting mixed case addresses in posting an order will not be sufficient to get these Python SRA client example working, because after posting an order, the example retrieves the order and fills it. So Launch Kit must also be changed to store the orders in mixed case as well, such that the retrieval will yield the case given in the posting.

feuGeneA commented 5 years ago

Testing against that PR #74 (as published to dockerhub 0xorg/launch-kit-backend:74bcc39) I'm able to post checksummed orders. However, now i'm getting that web3.py error when trying to fill the order:

InvalidAddress('Web3.py only accepts checksum addresses. The software that gave you this non-checksum address should be considered unsafe, please file it as a bug on their platform. Try using an ENS name instead. Or, if you must accept lower safety, use Web3.toChecksumAddress(lower_case_address).', '0x5409ed021d9299bf6814279a6a1411a7e866a631')

At the moment, this is enough to unblock the work I'm doing. I changed my SRA client example to just do toChecksumAddress on the maker address, and cited this Issue in the example explanation, and now my test passes.