Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix contract deployments with Ledger #4683

Open
314159265359879 opened this issue Dec 13, 2023 · 17 comments
Open

Fix contract deployments with Ledger #4683

314159265359879 opened this issue Dec 13, 2023 · 17 comments
Labels
area:bns area:ledger area:stacks bug Functionality broken bug-p2 Critical functionality broken for few users, with no clear workarounds for:support-team-priorities

Comments

@314159265359879
Copy link
Contributor

Steps to reproduce:

  1. Go to explorer.hiro.so
  2. Click on sandbox in the navbar
  3. Sign in with your ledger enabled wallet
  4. Deploy the contract
  5. Sign transaction on the ledger device
  6. See this error:

image

Other steps that lead to the same outcome:

  1. Go to stacks.gamma.io
  2. Sign in with an account that has a BNS name
  3. List the BNS name
  4. (this will also try to deploy a contract), sign the transaction on the Ledger device
  5. see the same error as in 6 above.
@314159265359879 314159265359879 added bug Functionality broken bug-p1 Critical functionality broken for many customers, with no clear workarounds area:ledger area:stacks labels Dec 13, 2023
@markmhendrickson
Copy link
Collaborator

@kyranjamie any idea what could be causing this?

@markmhendrickson markmhendrickson added bug-p2 Critical functionality broken for few users, with no clear workarounds area:bns and removed bug-p1 Critical functionality broken for many customers, with no clear workarounds labels Dec 22, 2023
@markmhendrickson markmhendrickson changed the title Deploying contracts with Ledger enabled wallet fails with "Data invalid, your ledger device has rejected the payload stating it is invalid" Fix contract deployments with Ledger Dec 22, 2023
@markmhendrickson markmhendrickson added this to the Fix urgent bugs milestone Jan 2, 2024
@edgarkhanzadian edgarkhanzadian self-assigned this Jan 2, 2024
@edgarkhanzadian
Copy link
Contributor

It could be that the stacks library that we are using for ledger doesn't support contract deploys. Opened an issue here: Zondax/ledger-stacks#153

@edgarkhanzadian
Copy link
Contributor

Update: waiting for this PR to get merged before implementing it in the wallet: Zondax/ledger-stacks#155

@edgarkhanzadian
Copy link
Contributor

Waiting for the new zondax/ledger-stacks app release to ledger store

@kyranjamie
Copy link
Collaborator

Removing from milestone because blocked

@markmhendrickson
Copy link
Collaborator

@pete-watters does this appear to be the same issue as to #5115 to you?

@pete-watters
Copy link
Contributor

@pete-watters does this appear to be the same issue as to #5115 to you?

The error we show is similar but when I provided data from #5115 to Zondax they ran it through their simulator and it was working so they haven't added a fix for it in their latest version. On that issue they ask about the data we are sending that comes from the contract itself

I have this issue open on their repo: Zondax/ledger-stacks#159

They helped me debug as I sent them the data we send to ledger and they ran tests on it and it worked OK in their simulator.

From Leather we get an error code back from the Ledger and we don't show any prompts on the users Ledger: #5115 (comment)

@markmhendrickson
Copy link
Collaborator

Got it, so should we close out this specific issue in favor of #5115 or are they still technically different?

@pete-watters
Copy link
Contributor

Lets keep this open and see if the Ledger App update resolves it. @edgarkhanzadian was waiting on that

If that fixes this issue, we can close it then. If not lets analyse it with #5115 and see if they are the same.

They could be having different failures for different reasons.

In the UI we show the message Your Ledger device has rejected... as a generic way of handling different errors so we should try and solve them on a case by case basis if we can.

@314159265359879
Copy link
Contributor Author

According to @MicaiahReid contract deployments are rejected when the size of the transaction is equal or greater than 16390 bytes. When they use Xverse to deploy, smaller size transactions will succeed. Examples of raw payloads can be found in this source comment: Zondax/ledger-stacks#166 (comment)

With Leather contract deployments fail with "your ledger device has rejected the payload stating it is invalid" with any size according to @lgalabru. Source: Zondax/ledger-stacks#166 (comment)

@314159265359879
Copy link
Contributor Author

I used a Ledger Nano S+ to deploy a small smart contract with Leather/Ledger and that works now.

Example contract (default contract in stacks explorer sandbox):

;; hello-world contract

(define-constant sender 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR)
(define-constant recipient 'SM2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQVX8X0G)

(define-fungible-token novel-token-19)
(ft-mint? novel-token-19 u12 sender)
(ft-transfer? novel-token-19 u2 sender recipient)

(define-non-fungible-token hello-nft uint)

(nft-mint? hello-nft u1 sender)
(nft-mint? hello-nft u2 sender)
(nft-transfer? hello-nft u1 sender recipient)

(define-public (test-emit-event)
  (begin
    (print "Event! Hello world")
    (ok u1)
  )
)

(begin (test-emit-event))

(define-public (test-event-types)
  (begin
    (unwrap-panic (ft-mint? novel-token-19 u3 recipient))
    (unwrap-panic (nft-mint? hello-nft u2 recipient))
    (unwrap-panic (stx-transfer? u60 tx-sender 'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR))
    (unwrap-panic (stx-burn? u20 tx-sender))
    (ok u1)
  )
)

(define-map store { key: (buff 32) } { value: (buff 32) })

(define-public (get-value (key (buff 32)))
  (begin
    (match (map-get? store { key: key })
      entry (ok (get value entry))
      (err 0)
    )
  )
)

(define-public (set-value (key (buff 32)) (value (buff 32)))
  (begin
    (map-set store { key: key } { value: value })
    (ok u1)
  )
)

Trying a contract with 500 lines fails which is expected due to the current memory limitations mentioned in the Ledger-stacks issue thread (166).

@MicaiahReid
Copy link

Nice @314159265359879 ! Did something have to change to get this working, or was I doing something wrong when attempting to deploy a contract with Leather/Ledger?

@314159265359879
Copy link
Contributor Author

Nice @314159265359879 ! Did something have to change to get this working, or was I doing something wrong when attempting to deploy a contract with Leather/Ledger?

There is one change, this is the first time I tried this with Stacks app version 0.24.2 which was released yesterday. Prior to this I was using 0.23.3 and I also was under the impression that contract deployments with leather/ledger would fail regardless of the size.

@MicaiahReid
Copy link

with leather/ledger would fail regardless of the size.

Yep, those were my findings as well. Glad it's fixed, thanks!

@markmhendrickson
Copy link
Collaborator

@314159265359879 can we close this issue?

@314159265359879
Copy link
Contributor Author

Lets close this when the fix for big contracts is also live on Ledger Live/(Stacks App 0v24.4 or higher). The fix should improve things for Nano S+, X, Stax and Flex. Older models (Nano) does not have enough memory to change anything so if users encounter it there they may need to upgrade to one of these newer ledger devices to deploy a sizeable (or any) contract.

This it the related PR (increase flash buffer size) Zondax/ledger-stacks#172

@pete-watters
Copy link
Contributor

There has been an update on the Zondax ticket to indicate a fix for this has been merged by Ledger 🤞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:bns area:ledger area:stacks bug Functionality broken bug-p2 Critical functionality broken for few users, with no clear workarounds for:support-team-priorities
Projects
None yet
Development

No branches or pull requests

6 participants