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
tx.origin are overwritten in forge script #4434
Comments
Hmm this does seem like a bug, cc @joshieDo. Ran both below examples with But if you run both of the examples as Example 1A slightly simpler version of the above, which shows different tx.origin logs. contract MyScript is Script {
function run() public {
uint256 pk = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(pk);
ExternalContract ext = new ExternalContract();
MyContract my = new MyContract();
my.myFunc(ext);
vm.stopBroadcast();
}
}
contract MyContract {
function myFunc(ExternalContract ext) public {
console.log("MyContract.myFunc-1 ", tx.origin);
ext.extFunc();
console.log("MyContract.myFunc-2 ", tx.origin);
}
}
contract ExternalContract {
function extFunc() public {
console.log("MyContract.myFunc -> ExternalContract.extFunc", tx.origin);
}
}
Example 2Moving the contract deploying within the contract MyScript is Script {
function run() public {
uint256 pk = vm.envUint("PRIVATE_KEY");
vm.startBroadcast(pk);
MyContract my = new MyContract();
my.myFunc();
vm.stopBroadcast();
}
}
contract MyContract {
function myFunc() public {
ExternalContract ext = new ExternalContract();
console.log("MyContract.myFunc-1 ", tx.origin);
ext.extFunc();
console.log("MyContract.myFunc-2 ", tx.origin);
}
}
contract ExternalContract {
function extFunc() public {
console.log("MyContract.myFunc -> ExternalContract.extFunc", tx.origin);
}
}
|
I still have this problem. After calling callback function in my contract, tx.origin changes back to 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38(default user?) |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (c5dd9a6 2023-02-26T00:12:08.486636Z)
What command(s) is the bug in?
forge script
Operating System
macOS (Apple Silicon)
Describe the bug
I'm using
forge script
to run transactions and deploy contracts. Usually everything works well but I'm running into an issue where the tx.origin seems to be changing in the middle of a script.Here is my code:
The first log shows the correct value: the address generated from the
PRIVATE_KEY
but the second log prints0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38
I have
anvil
running and the script is connecting to it.The command i'm running is
forge script ./script/myscript.s.sol --tc MyScript
And I have the networks setup in
foundry.toml
:The text was updated successfully, but these errors were encountered: