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

Sequence mismatch. Got 1 from device. Expected 0 #3266

Closed
2 tasks done
AmesCornish opened this issue Sep 19, 2022 · 13 comments
Closed
2 tasks done

Sequence mismatch. Got 1 from device. Expected 0 #3266

AmesCornish opened this issue Sep 19, 2022 · 13 comments
Assignees
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-bug Type: bug

Comments

@AmesCornish
Copy link

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (084ef3d 2022-09-19T00:07:01.878472846Z)

What command(s) is the bug in?

script

Operating System

Linux

Describe the bug

I'm getting this error when trying to broadcast a transaction to mainnet using a ledger. The command is:

forge script script/MyScript.s.sol --broadcast --ledger

I had one transaction with a different script work this way, but this one succeeded in the dry run just fine, I approved it in the ledger just fine, but then I get the following output with a warning:

...
Script ran successfully.

==========================

Estimated total gas used for script: 174237

Estimated amount required: 0.002697348679248762 ETH

==========================

###
Finding wallets for all the necessary addresses...
##
Sending transactions [0 - 0].

Transactions saved to: /home/.../MyScript.s.sol/1/run-latest.json

Error: 
Sequence mismatch. Got 1 from device. Expected 0

At first I thought this might be a nonce error, but the on-chain nonce is 3, so that doesn't fit.

What is this "sequence" of which it speaks? Any pointers would be appreciated!

@AmesCornish AmesCornish added the T-bug Type: bug label Sep 19, 2022
@gakonst gakonst moved this to Todo in Foundry Sep 19, 2022
@gakonst gakonst added this to Foundry Sep 19, 2022
@rkrasiuk rkrasiuk added C-forge Command: forge Cmd-forge-script Command: forge script labels Sep 19, 2022
@gakonst
Copy link
Member

gakonst commented Sep 19, 2022

Is this error still around? Did you try replugging the ledger?

@AmesCornish
Copy link
Author

AmesCornish commented Sep 19, 2022

Yes, I kept getting the error, after replugging and restarting the ledger several times. As a note, I saw a similar issue trying to connect my Ledger to Metamask, through I then connected it to the Coinbase wallet without issue. I suspect there's some protocol version incompatibility between the ledger and whatever client library you're using on linux.

@mattsse
Copy link
Member

mattsse commented Sep 19, 2022

cc @joshieDo

@gakonst
Copy link
Member

gakonst commented Sep 20, 2022

cc @prestwich re: Ledger, has there been any change recently?

@prestwich
Copy link
Contributor

prestwich commented Sep 20, 2022

error originates here during APDU response payload header parsing: https://github.com/summa-tx/bitcoins-rs/blob/c6fdb4cc6b2c8779d1e71c7046ff3eec6dcf61e1/ledger/src/transports/hid.rs#L259-L264

no change to the lib for a couple months. The sequence mismatch (got 0 expected 1) would indicate one of

  • malformed response (possibly do to malformed request)
  • some channel id weirdness that we're not handling correctly
  • non-exclusive access to the device (multiple futures trying to use it at the same time?)
  • sequence int rolls over (very large tx, more than ~256 * 60 bytes)

Documentation of the sequence system for large blob txns
https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.asc#transport-protocol

Are you running ledger live or any other ledger-using application at the same time you're running the script?

@joshieDo
Copy link
Collaborator

joshieDo commented Sep 20, 2022

non-exclusive access to the device (multiple futures trying to use it at the same time?)

Leaning towards this.

I don't have access to a ledger anymore, but I remember seeing some recent changes to how we instantiate wallets in the beginning. May be a resurgence of this gakonst/ethers-rs#1602 / #2790 - although i remember the error being different at the time.

edit: #3047 recent changes i mentioned

@AmesCornish
Copy link
Author

malformed response (possibly do to malformed request)

maybe?

some channel id weirdness that we're not handling correctly

maybe?

non-exclusive access to the device (multiple futures trying to use it at the same time?)

I was careful to close down Ledger Live and unconnect/reconnect the ledger, and clean the forge cache. Didn't help.

sequence int rolls over (very large tx, more than ~256 * 60 bytes)

The error started with a two-transaction script. The first (small) transaction succeeded, and the second repeatedly failed after approval on the ledger. The second transaction was big-ger, but still only about 256 bytes of calldata. I also tried re-doing the script to only broadcast the second transaction, but it still failed.

I'll try to post a redacted broadcast record to help debugging...

@prestwich
Copy link
Contributor

second repeatedly failed after approval on the ledger

this would seem to rule out the large payload, as the response payload from the ledger sign is small

@prestwich
Copy link
Contributor

I don't have much time to work on this. but if someone wants to add tracing to the underlying ledger lib.....? :)

@AmesCornish
Copy link
Author

Bump. This is still happening with latest foundryup.

@prestwich
Copy link
Contributor

@gakonst I'm pretty sure this is related to running multiple signing processes at once

@zerosnacks
Copy link
Member

Hi @AmesCornish,

Would be great if you could check again, we've since moved to Alloy and a bug related to the kb size of the contract suite being deployed was fixed: #6516 (comment)

@zerosnacks zerosnacks self-assigned this Jul 4, 2024
@zerosnacks
Copy link
Member

Tentatively marking as resolved

Feel free to re-open if you are still facing issues around this @AmesCornish

@jenpaff jenpaff moved this from Todo to Completed in Foundry Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-script Command: forge script T-bug Type: bug
Projects
Status: Completed
Development

No branches or pull requests

7 participants