0xProject / 0x-monorepo

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

order-utils: Orders Signed By Trust Wallet Return As INVALID_SIGNATURE #1724

Open pointtoken opened 5 years ago

pointtoken commented 5 years ago

When attempting to sign a typed order from Trust Wallet, the signature fails validation.

Here is the code to create the signature

      const signedOrder = await signatureUtils.ecSignTypedDataOrderAsync(
        this.web3,
        order,
        signerAddress
      );
      return signedOrder;

This will successfully fire off the 712 signing UI from Trust Wallet and return a signature. But when the signed order is then passed to validateOrderFillableOrThrowAsync it returns

Error: INVALID_ORDER_SIGNATURE
    at OrderValidationUtils.<anonymous> (node_modules/@0x/order-utils/src/order_validation_utils.ts:154:19)
dekz commented 5 years ago

what is the web3 object in this context?

pointtoken commented 5 years ago

Trust Wallet injects it:

this.web3 = this.windowRef.nativeWindow.web3.currentProvider;

Are there any websites or dexes that one can navigate to from Trust Wallet and create a valid signed order?

dekz commented 5 years ago

I'd suggest the 0x codesandbox but it appears that Trust Wallet has disabled testnet support?

fabioberger commented 5 years ago

@pointtoken are you able to fill the order? Wondering if the issue is with Trust Wallet or validateOrderFillableOrThrowAsync.

pointtoken commented 5 years ago

@fabioberger no the order is not able to be filled.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

fabioberger commented 5 years ago

@pointtoken if this is still an issue, mind sending as a repro? Or repo where we can see the code? I'd need to put in some debug logs to see what's going on.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

amaurer commented 5 years ago

I'm also having an issue with signing typed data in Trust wallet. It seems to immediately fail.

e.toLowerCase is not a function. (In 'e.toLowerCase()', 'e.toLowerCase' is undefined)

I know that isn't much help but it's what I have. It's difficult to debug because we're in an embedded browser within Trust.

Also, this seems to be specific to signing typed data. I am able to sign a message successfully and send it to the exchange contract, but it doesn't pass signature validation. It returns "SIGNATURE_UNSUPPORTED"

Here is some sample code.

  async signTransactionAsync(transaction) {
    return await signatureUtils.ecSignTypedDataTransactionAsync(
      this.provider,
      transaction,
      transaction.signerAddress,
    );
  },

  async submitOrders(afterConfirmation) {
    const data = await this.getEncodedTransactionData();
    const transaction = { // ZeroExTransaction Object
      salt: new Date().getTime(),
      signerAddress: this.account,
      verifyingContractAddress: this.contractWrappers.exchange.address,
      data,
    };

    const signature = await this.signTransactionAsync(transaction);
    const signedTransaction = {
      ...transaction,
      signature,
    };

    const { gas, gasPrice } = await this.getGas();
    const txHash = await this.ourContract.ourFunction.sendTransactionAsync(
      signedTransaction,
      signature,
      {
        from: transaction.signerAddress,
        gas,
        gasPrice,
      },
    );
    return this.web3Wrapper.awaitTransactionMinedAsync(txHash);
  },