0xProject / 0x-monorepo

0x protocol monorepo - includes our smart contracts and many developer tools
Other
1.41k stars 466 forks source link

Cannot use validateOrderFillableOrThrowAsync with SignatureType.Wallet type. #1407

Closed artiya4u closed 5 years ago

artiya4u commented 5 years ago

I create an order with a wallet smart contract and validate it with order-utils using validateOrderFillableOrThrowAsync but it threw an unreadable error.

(node:22935) UnhandledPromiseRejectionWarning: Error: invalid bytes value (arg="signature", coderType="bytes", value="04", version=4.0.17)

Expected Behavior

It should send the signature without type to validate on wallet contract.

Current Behavior

Send the signature type to validate from wallet smart contract wallet instead of the signature. I have dig into the code and found const signatureWithoutType is actually the type (04).

const signatureWithoutType = signature.slice(-2);

Possible Solution

The code should be like this

const signatureWithoutType = signature.slice(0, -2);

Steps to Reproduce (for bugs)

  1. Create a smart contract wallet and implement IWallet interface.
  2. Create an order from the wallet and sign the order.
  3. Call contractWrappers.exchange.validateOrderFillableOrThrowAsync(signedOrder); to validate order.

Context

I try to build a copy trading on 0x protocol with a smart contract wallet.

Your Environment

Linux, NodeJS v10.14.1

| Package | Version | | @0x/order-utils| 3.0.4 | | Exchange Contract | v2 |

Network
kovan
fabioberger commented 5 years ago

Thank you for the bug report @artiya4u. You are indeed correct that this is a bug. Will fix ASAP.

artiya4u commented 5 years ago

I try to send the order to RadarRelay without validation but it seems like the relay won't accept our order either. Could this bug cause the problem?

fabioberger commented 5 years ago

@artiya4u I'm pretty sure they are using our validation method (which includes the same bug). I will publish today and let them know.

fabioberger commented 5 years ago

Just published a new version of @0x/order-utils with this fixed: https://github.com/0xProject/0x-monorepo/releases/tag/monorepo%4096b8100