The script programmatically accesses a sensitive private key stored in the system's environment variables.
There are three primary ways this leads to theft:
Shell History: If the key is set via export PRIVATE_KEY=..., it is saved in plaintext in ~/.bash_history or ~/.zsh_history.
Version Control Leakage: If the key is stored in a .env file and that file is accidentally committed to a public repository (e.g., forgetting to update .gitignore), bots will scrape and drain the wallet instantly.
Process Inspection: Environment variables can sometimes be read by other processes running on the same machine, increasing the attack surface for malware.
Likelihood: Medium
Common "copy-paste" deployment commands often lead to keys being left in terminal history.
Accidental .env uploads are one of the most frequent causes of lost funds in web3 development.
Impact: Critical
Total loss of all assets held by the deployer address.
Immediate compromise of the TreasureHunt contract's admin privileges.
Developer runs export PRIVATE_KEY=0x123... in their terminal.
Developer runs the forge script.
An attacker gains access to the machine (or a public repo where the history was leaked) and runs cat ~/.bash_history.
The attacker finds the export command, imports the key, and drains the account.
Use Foundry Keystores instead of environment variables. Keystores store the key in an encrypted file on your disk that requires a password to unlock during the broadcast phase.
Update the script to remove the envUint requirement:
The deployment workflow pulls a raw EOA private key directly from the environment with `vm.envUint("PRIVATE_KEY")` and then uses it in `vm.startBroadcast(deployerKey)`, meaning the signing key is handled as an unencrypted scalar rather than through a safer account abstraction or keystore-backed signer. It is vulnerable to accidental commit, shell/session leakage, workstation compromise, or exposure to any process that can read the environment, turning compromise of the deploy machine into immediate compromise of the deployer account itself.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.