Did anyone else get tokens sent to 0x1804... when using mint(msg.sender, ...) in a deploy script? #13346
Unanswered
cypherpunk-bc
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
1. What happened to me
I used forge script to deploy a MockERC20. In the script I had token.mint(msg.sender, 1_000_000 * 1e18) so that 1M tokens would be minted to the deployer.
On-chain:
Contract creator and the from of all related txs are my wallet (0x1556...), so I did sign the deployment.
The mint’s Transfer event shows tokens going to 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38.
That tx’s input data is mint(address to, uint256 amount) with the first argument = 0x1804..., so the script encoded that address as the recipient.
2. My inferred cause (possibly Forge behavior)
After checking Foundry discussions and docs, I think this comes from how Forge runs scripts:
In the script, run() is invoked by Foundry’s default account, so inside the script msg.sender is that default (e.g. 0x1804...).
vm.startBroadcast(deployerPrivateKey) only decides who signs the transactions; it does not change who is “running” the script.
So: the transaction is signed by me (from = my address), but the mint recipient is whatever msg.sender was during simulation (0x1804...).
So I’m treating this as Forge script behavior: the “caller of run()” and the “broadcast signer” are different, and I didn’t change the script or env on purpose.
3. What I’d like to confirm with you
Has anyone else written something like mint(msg.sender, ...) (or “send to msg.sender”) in a deploy script and had tokens/values go to 0x1804... or another wrong address?
Do you also attribute it to msg.sender semantics in Forge scripts? Is there any more official explanation or recommended pattern?
My current workaround is to use vm.addr(deployerPrivateKey) whenever I need “the deployer address,” and avoid msg.sender for that. Do you do something different?
4. References
Contract: Base Sepolia 0xd6f268AF3C4C4Dd7852f51aedd9De12e7048Ec73
Problem tx: 0xb70e830c0ff87bbeed0738d5ec6a5137941deeacbd144d438de989abcb5335a6
Beta Was this translation helpful? Give feedback.
All reactions