foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.05k stars 1.66k forks source link

Foundry script breaks on Base network for certain transactions signed with Ledger (error: chainId 0) #5819

Open sendra opened 11 months ago

sendra commented 11 months ago

Component

Forge

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

What version of Foundry are you on?

forge 0.2.0 (bff4ed9 2023-08-29T00:32:25.634676000Z)

What command(s) is the bug in?

forge script

Operating System

macOS (Apple Silicon)

Describe the bug

When using forge script to deploy on the Base network, on certain transactions its sending chainId 0 to ledger, which makes it fail with error:


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

Chain 8453

Estimated gas price: 0.109494488 gwei

Estimated total gas used for script: 5370493

Estimated amount required: 0.000588039381342584 ETH

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

###
Finding wallets for all the necessary addresses...
##
Sending transactions [0 - 2].
2023-09-12T11:21:32.611137Z ERROR coins_ledger::transports: Received error from device err="Ledger device: APDU Response error `Code 6985 ([APDU_CODE_CONDITIONS_NOT_SATISFIED] Conditions of use not satisfied)`"
2023-09-12T11:21:32.611366Z ERROR ethers_signers::ledger::app: error=Ledger device: APDU Response error `Code 6985 ([APDU_CODE_CONDITIONS_NOT_SATISFIED] Conditions of use not satisfied)`

Transactions saved to: /Users/SomeContractPath/8453/run-latest.json

Sensitive values saved to: /Users/SomeContractPath/8453/run-latest.json

Error:
Failed to sign transaction

Context:
- Ledger device: APDU Response error `Code 6985 ([APDU_CODE_CONDITIONS_NOT_SATISFIED] Conditions of use not satisfied)`
make: *** [deploy-payloads-controller-chain] Error 1

Have not been able to isolate the cases for when this happens. But provably similar problem to this issue: https://github.com/foundry-rs/foundry/issues/4362

zerosnacks commented 1 month ago

Hi @sendra thanks for reporting. Have you experienced issues around this more recently? We've since migrated from Ethers to Alloy. If so, would greatly appreciate a minimal reproduction if possible.

The root cause of #4362 is still open unfortunately: https://github.com/LedgerHQ/app-ethereum/issues/409

The workaround implemented in Ethers has also been implemented in Alloy: https://github.com/alloy-rs/alloy/blob/ca1f1f00dc98c975ab81ea095ecd6de627974e82/crates/signer-ledger/src/signer.rs#L246-L249