Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

stellarSignTransaction did not return the correct signature #970

Closed
overcat opened this issue Dec 10, 2021 · 24 comments · Fixed by #974
Closed

stellarSignTransaction did not return the correct signature #970

overcat opened this issue Dec 10, 2021 · 24 comments · Fixed by #974
Assignees

Comments

@overcat
Copy link
Contributor

overcat commented Dec 10, 2021

environment info

connect 8.2.3
Model One 1.10.4
Model T 2.4.3

tx info

path: "m/44'/148'/0'"
mnemonic_phrase: "bridge endless life will season cigar crash relief give syrup annual inner"
passphrase: ""
public_key: "GDIO5QKU6PBJ6OCML6XCU3EBG4LINOVXPMNJJFMAWXDZIKMGJP7JH2UL"
secret: "SCABM2RHNGNUGTA3U6EDNPQ7CCDVDC5Z5R6DGHUCY5GIRYALLJCEEILF"
network_passphrase: "Public Global Stellar Network ; September 2015"
xdr: "AAAAAgAAAADQ7sFU88KfOExfripsgTcWhrq3exqUlYC1x5Qphkv+kwAAAGQCTfIHAAAAAQAAAAEAAAAAAAAAAAAAAABhszoiAAAAAAAAAAEAAAAAAAAACgAAAAVoZWxsbwAAAAAAAAAAAAAAAAAAAA=="

Expected signature
I got this signature through trezorctl, so I think there is no problem with Trezor firmware.

"Xwqw6xRo2pP7mUE4ybQxvYy7T4tYHq8YuoIlZ5UqnyM70+8PIf/wKFGzFY2kBVCoScYQlBzR9lopH3VoHiL+DA=="

signature returned by stellarSignTransaction

"BmraoPzbn69nUkB7Be8sEwYLqU0fkUbBNv66q3MBp3Op7z2FiJneaolD5DPfcEsvAbaWmOIe/M9WRoIIpPOTDw=="

code

      function signTx() {
        const params = {
          path: "m/44'/148'/0'",
          networkPassphrase: "Public Global Stellar Network ; September 2015",
          transaction: {
            source: "GDIO5QKU6PBJ6OCML6XCU3EBG4LINOVXPMNJJFMAWXDZIKMGJP7JH2UL",
            fee: 100,
            sequence: "166054873161269249",
            memo: {
              type: 0,
            },
            timebounds: {
              minTime: 0,
              maxTime: 1639135778,
            },
            operations: [
              {
                type: "manageData",
                name: "hello",
              },
            ],
          },
        };
        TrezorConnect.stellarSignTransaction(params)
          .then((result) => {
            if (result.success) {
              console.log(result.payload.signature);
            }
          })
          .catch((error) => {
            console.error("TrezorConnectError", error);
          });
      }
@overcat
Copy link
Contributor Author

overcat commented Dec 10, 2021

This is debugging information. Why is the sequence received by Trezor T different from the sequence passed to stellarSignTransaction? Hi @mroz22, do you have any ideas?

21407047712 trezor.wire DEBUG 0:0 receive: <StellarSignTx>
21407070999 trezor.wire DEBUG received message contents:

StellarSignTx {
    network_passphrase: 'Public Global Stellar Network ; September 2015'
    memo_hash: None
    address_n: [2147483692, 2147483796, 2147483648]
    source_account: 'GDIO5QKU6PBJ6OCML6XCU3EBG4LINOVXPMNJJFMAWXDZIKMGJP7JH2UL'
    sequence_number: 166054873161269248
    timebounds_start: 0
    num_operations: 1
    fee: 100
    memo_type: 0
    timebounds_end: 1639135778
    memo_text: None
    memo_id: None
}

@overcat
Copy link
Contributor Author

overcat commented Dec 10, 2021

trezorctl works fine, it got the correct sequence

21841576419 trezor.wire DEBUG 0:0 receive: <StellarSignTx>
21841595270 trezor.wire DEBUG received message contents:
StellarSignTx {
    network_passphrase: 'Public Global Stellar Network ; September 2015'
    memo_hash: None
    address_n: [2147483692, 2147483796, 2147483648]
    source_account: 'GDIO5QKU6PBJ6OCML6XCU3EBG4LINOVXPMNJJFMAWXDZIKMGJP7JH2UL'
    sequence_number: 166054873161269249
    timebounds_start: 0
    num_operations: 1
    fee: 100
    memo_type: 0
    timebounds_end: 1639135778
    memo_text: None
    memo_id: None
}

@overcat
Copy link
Contributor Author

overcat commented Dec 10, 2021

If the sequence number is a small value, then everything seems to work fine, is this related to exceeding MAX_SAFE_INTEGER?

@mroz22
Copy link
Contributor

mroz22 commented Dec 10, 2021

Yes, this is happening due to sending number parameter which is higher then MAX_SAFE_INTEGER

What we should do now? probably change conect interface in that way that it will be able to accept also string here instead of number

@overcat
Copy link
Contributor Author

overcat commented Dec 10, 2021

Yes, I think we should define it as string type in JavaScript. (The source code of Trezor Model T is written in Python, and Python can handle it accurately.)

I am not familiar with JavaScript, the sequence number I passed in is string type, where is it converted to number?

@mroz22 mroz22 self-assigned this Dec 10, 2021
@mroz22
Copy link
Contributor

mroz22 commented Dec 10, 2021

I have already found the root of this problem and I am preparing fix. Thanks for reporting.

@prusnak
Copy link
Member

prusnak commented Dec 11, 2021

@mroz22 While you are on it, can you also please set the asset field to native if it is not specified by the caller? See trezor/trezor-firmware#1997 (comment) and @matejcik can provide you with more info.

@matejcik
Copy link
Contributor

fwiw i believe that whoever is using the official Stellar SDK will always specify the asset, and that is what callers should be doing

@overcat
Copy link
Contributor Author

overcat commented Dec 11, 2021

Hi @mroz22, I found that other projects did not use the transformTransaction function provided by the connect library, but made a separate copy. Do you have any ideas?

https://github.com/stellar/laboratory/blob/master/src/helpers/trezorTransformTransaction.js
https://github.com/stellarterm/stellarterm/blob/master/src/lib/TransformTrezorTransaction.js

@prusnak
Copy link
Member

prusnak commented Dec 11, 2021

I found that other projects did not use the transformTransaction function provided by the connect library, but made a separate copy.

Can you please open issues in the respective projects to not do this and rather use a function provided by Connect? There is no good reason why they should do this. And mainly this behaviour leads to more issues and makes fixing stuff much more complicated.

@overcat
Copy link
Contributor Author

overcat commented Dec 11, 2021

I found that other projects did not use the transformTransaction function provided by the connect library, but made a separate copy.

Can you please open issues in the respective projects to not do this and rather use a function provided by Connect? There is no good reason why they should do this. And mainly this behaviour leads to more issues and makes fixing stuff much more complicated.

Sorry for this, I will raise this issue elsewhere.

@mroz22
Copy link
Contributor

mroz22 commented Dec 12, 2021

@mroz22 While you are on it, can you also please set the asset field to native if it is not specified by the caller? See trezor/trezor-firmware#1997 (comment) and @matejcik can provide you with more info.

Just to clarify. Do we still want this? I wasn't sure whether anything changed after closing trezor/trezor-firmware#1997 (comment)

@shiny-mountain
Copy link

I found that other projects did not use the transformTransaction function provided by the connect library, but made a separate copy.

Can you please open issues in the respective projects to not do this and rather use a function provided by Connect? There is no good reason why they should do this. And mainly this behaviour leads to more issues and makes fixing stuff much more complicated.

I couldn't find this method "transformTransaction" inside the "trezor-connect" package. The "lib" folder does not contain the "plugins" folder.

@mroz22
Copy link
Contributor

mroz22 commented Dec 13, 2021

hey @shiny-mountain plugins folder is available only from -extended package. for example 8.2.3-extended. does it suit your needs?

@shiny-mountain
Copy link

hey @shiny-mountain plugins folder is available only from -extended package. for example 8.2.3-extended. does it suit your needs?

Yes, that's what we need. In the near future, Stellarterm will start using this

@shiny-mountain
Copy link

@mroz22 Will transaction signing be fixed in the next version of the package?

@mroz22
Copy link
Contributor

mroz22 commented Dec 13, 2021

yes, it is likely to happen in couple of hours.

@shiny-mountain
Copy link

ok, then we will update Stellarterm immediately with the new version

@shiny-mountain
Copy link

@mroz22 I installed "8.2.4-extended" version but I don't see the "plugins" folder in it

@overcat
Copy link
Contributor Author

overcat commented Dec 13, 2021

@mroz22 I installed "8.2.4-extended" version but I don't see the "plugins" folder in it

It works fine on my end, see stellar/account-viewer-v2#366

@shiny-mountain
Copy link

shiny-mountain commented Dec 13, 2021

Oops, my mistake. It was just necessary to change "^8.2.4-extended" to "8.2.4-extended"

@felixlucid
Copy link

I have already found the root of this problem and I am preparing fix. Thanks for reporting.

Thank you so much for your attention to this matter. I'm a Trezor Model T user affected by this issue and was referred here by the Support Team. As of now, I am still unable to sign transactions on the SDEX via StellarTerm with my Model T 1.4.3 FW. Please let me know the update status for the fix. Thank you!

@felixlucid
Copy link

ok, then we will update Stellarterm immediately with the new version

I'm a Model T StellarTerm user with vested interest in the resolution of this transaction signing problem. Could you give me the status of the fix intergration on StellarTerm and inform me whether I should be able to start transacting on the platform? Thank you for your support.

@overcat
Copy link
Contributor Author

overcat commented Dec 14, 2021

Hi @felixlucid, it works fine on my end, what error did you get? Let's move to stellarterm/stellarterm#951 to continue the discussion.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants