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 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.
The contest is complete and the rewards are being distributed.