foundry icon indicating copy to clipboard operation
foundry copied to clipboard

feat(script): propose a script's broadcast to a Safe (`--safe`)

Open aelmanaa opened this issue 1 month ago • 2 comments

Component

Forge (script)

Describe the feature you would like

Revisiting #1232 now that cast has a Safe client (#16377).

Teams whose contracts are owned by a Safe cannot run an admin or upgrade script against it. Today they run the script, then copy each transaction's calldata into the Safe UI or cast safe propose one at a time, or they use third-party libraries that shell out through vm.ffi (safe-utils, forge-safe, treb).

#1232 (16 👍) was closed in June 2025 as out of scope and solved by those libraries. Since then #16377 added cast safe (create, propose, sign, simulate, execute), with a Transaction Service client and SafeTx signing. So Foundry now has the pieces, and the remaining step is letting a script use them.

Proposal:

forge script script/Upgrade.s.sol --rpc-url mainnet --safe 0xSafe --account proposer --broadcast
  1. The script runs as today, broadcasting from the Safe: vm.startBroadcast(0xSafe). In this mode an address without a key is accepted.
  2. On --broadcast, instead of sending, forge batches the recorded transactions into one MultiSendCallOnly call (or a plain call when there is one transaction).
  3. It computes the SafeTx hash with the Safe's current nonce, signs it with the proposer (--account, Ledger, keystore, ...) and proposes it to the Transaction Service, reusing the cast safe code. It prints the SafeTx hash and the Safe UI link.
  4. The broadcast file records the proposal (Safe, nonce, SafeTx hash) instead of receipts.

Limits:

  • A Safe cannot CREATE from a MultiSend batch. Deployments would go through CREATE2 (the script's create2_deployer); a plain new in Safe mode fails with a message saying so.
  • One SafeTx has one gas limit; forge warns when the batch is above the block gas limit.

Suggested split, each a small PR:

  • (a) move the Safe client from crates/cast/src/cmd/safe/ to a shared crate, no behavior change;
  • (b) --safe for scripts with calls only;
  • (c) contract creation.

Would you accept this, and is the split right? If you would rather keep scripts out of it, a smaller step would be cast safe propose reading a broadcast file, so a script's dry run can be proposed in one command.

aelmanaa avatar Oct 31 '26 08:10 aelmanaa

I'd like to work on this, following the split above: first move the Safe client from cast into a shared crate, then --safe for call-only scripts, then contract creation. Before starting, is this something you'd accept now, given #1232 was closed as out of scope?

SibghatUllah1997 avatar Nov 12 '26 14:11 SibghatUllah1997

This makes sense to revisit now that cast safe is in. Reusing that code for a call-only forge script --safe seems like a reasonable next step.

@0xKarl98 what do you think about this approach and the proposed split?

mablr avatar Nov 13 '26 15:11 mablr