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

docs: document vm.prompt display in script with external libs #1315

Open
2 tasks done
beeb opened this issue Aug 13, 2024 · 10 comments
Open
2 tasks done

docs: document vm.prompt display in script with external libs #1315

beeb opened this issue Aug 13, 2024 · 10 comments
Labels
good first issue Good for newcomers

Comments

@beeb
Copy link

beeb commented Aug 13, 2024

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 (a0a0020 2024-08-12T00:21:34.427762642Z)

What command(s) is the bug in?

forge script

Operating System

Linux

Describe the bug

Repro code: https://github.com/beeb/foundry-repro-prompt-lib

When a contract must be linked against external libraries, and a Foundry script deploys such contract, prompts are
shown twice.

Reproduction steps:

  1. Launch an anvil instance: anvil -a 1
  2. Launch script: forge script -f http://localhost:8545 --broadcast script/Counter.s.sol:CounterScript
  3. Observe that a prompt shows up and paste the first anvil private key: 0xac0974bec3...
  4. Observe that a second identical prompt is displayed

If the deployed contract does not have external libraries that must be linked, the problem does not happen.

@samooyo
Copy link

samooyo commented Aug 13, 2024

I encountered the same issue. I believe there's a problem with the deployment of external libraries and the prompt sequence. When using a script where external libraries need to be deployed, this task is performed first, even before the run function starts executing. However when a prompt is included in the script, the deployment of these libraries is delayed, awaiting user input, which maybe conflicts with the deployment process.

The inputs from the second prompt overwrite those from the first.

Initially, I thought the duplicated prompt was related to the simulation of the script, but using the --skip-simulation option didn't change anything.

@zerosnacks zerosnacks added this to the v1.0.0 milestone Aug 13, 2024
@zerosnacks zerosnacks changed the title Duplicate vm.prompt display in script with external libs bug(forge script): duplicate vm.prompt display in script with external libs Aug 13, 2024
@mds1
Copy link
Contributor

mds1 commented Aug 14, 2024

@klkvr Potentially related to foundry-rs/foundry#8639?

@klkvr
Copy link
Member

klkvr commented Aug 14, 2024

This is happening because of the way scripts handle external libraries deployment when private key is not known before running the script. Forge needs to know which address to use to deploy external libraries, and if the only signer is being resolved dynamically in script (in this case, by prompting private key), then we need to run script second time with correctly calculated library addresses, deployed by the prompted private key

This is is not specific to vm.prompt, scripts would be executed twice also in cases when private key is being read from e.g. environment variable

@beeb
Copy link
Author

beeb commented Aug 14, 2024

Thanks for the explanation! Could a fix potentially be to skip showing the prompts the second time around and reuse the values provided the first time?

@beeb
Copy link
Author

beeb commented Aug 14, 2024

Maybe it's simpler to invoke the script with -i 1 and not have the private key prompt in the script. Is there a way to detect if that argument is missing to e.g. revert inside the script if missing?

@klkvr
Copy link
Member

klkvr commented Aug 14, 2024

Thanks for the explanation! Could a fix potentially be to skip showing the prompts the second time around and reuse the values provided the first time?

This could work, though it might result in unexpected edge cases in situations where prompts order is not deterministic, so its hard to come up with a generally working approach here

Maybe it's simpler to invoke the script with -i 1 and not have the private key prompt in the script. Is there a way to detect if that argument is missing to e.g. revert inside the script if missing?

if it will be missing, then script will just dry-run with default sender, and once you try to broadcast it will throw a error saying that script is missing sender, do you need some different behavior for this case?

@beeb
Copy link
Author

beeb commented Aug 14, 2024

@klkvr never mind my suggestion, the problem is the same with -i 1 added to the script command. It prompts twice.

@klkvr
Copy link
Member

klkvr commented Aug 14, 2024

@klkvr never mind my suggestion, the problem is the same with -i 1 added to the script command. It prompts twice.

is the script still using vm.startBroadcast(vm.promptSecretUint("Enter the private key"))?

@beeb
Copy link
Author

beeb commented Aug 16, 2024

No I removed it since the -i 1 prompt does the same

@beeb
Copy link
Author

beeb commented Aug 16, 2024

Ok never mind I tried again and there is no double prompt with -i 1. I must have done something wrong. So the workaround would work.

@jenpaff jenpaff changed the title bug(forge script): duplicate vm.prompt display in script with external libs docs: document vm.prompt display in script with external libs Sep 24, 2024
@zerosnacks zerosnacks transferred this issue from foundry-rs/foundry Sep 24, 2024
@zerosnacks zerosnacks removed this from the v1.0.0 milestone Sep 24, 2024
@zerosnacks zerosnacks added the good first issue Good for newcomers label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
No open projects
Status: Todo
Development

No branches or pull requests

5 participants