To secure a contract's admin keys, move every privileged role (the owner, DEFAULT_ADMIN_ROLE, the proxy's upgrade rights, pausers, minters, oracle setters) from the deployer's single key to a Safe: a smart contract account that only executes a transaction once m of n owners have signed it. Put a TimelockController between the Safe and the contract for anything that isn't an emergency, so changes are public for a delay before they take effect. Give the owner keys to independent people on hardware wallets, and before anyone signs, verify the Safe transaction hash independently and confirm the operation is a plain CALL, not a DELEGATECALL. Finally, remove the deployer's rights and check on-chain that they are gone.
Why is a single admin key the weak point?
An admin key is usually the most powerful thing in a protocol. Depending on the contract, it can upgrade the implementation behind a proxy, mint unlimited tokens, pause withdrawals, change the oracle or fee recipient, or sweep funds. If that key is an EOA on a developer's laptop, every user's deposit is only as safe as that laptop, its browser extensions and that person's resistance to phishing. Compromised private keys and multisig signers tricked into approving malicious transactions have been behind some of the largest losses in the industry, often in protocols whose contract code was fine.
A multisig doesn't make the code safer. It changes what an attacker must compromise: several people, devices and locations instead of one.
How does a Safe enforce m-of-n?
Safe (formerly Gnosis Safe) is the standard multisig on Ethereum and most EVM chains. Each Safe is a small proxy that delegates to an audited singleton contract and stores:
- a list of owners and a threshold;
- a nonce, so each approved transaction executes once and in order;
- optional modules, guards and a fallback handler.
A Safe transaction is an EIP-712 struct:
SafeTx(address to, uint256 value, bytes data, uint8 operation,
uint256 safeTxGas, uint256 baseGas, uint256 gasPrice,
address gasToken, address refundReceiver, uint256 nonce)
Owners sign its hash off-chain. Once enough signatures exist, anyone can call execTransaction, which recomputes the hash, checks the signatures against the owner list and threshold, increments the nonce and performs the call. operation = 0 is a normal CALL. operation = 1 is a DELEGATECALL, which runs foreign code inside the Safe with full control over its storage, including its owners and its implementation pointer. (For why that is so dangerous, see how to use delegatecall safely.) If you haven't worked with typed data before, signing with EIP-191 and EIP-712 explains the domain and struct hashing.
Modules can execute transactions without owner signatures, and guards can veto transactions. Both are powerful: a malicious module is a backdoor, so enabling one deserves the same scrutiny as an upgrade. Safe v1.5.0, released in 2025, added module guards so you can also restrict what modules do. As of late 2026, v1.4.1 and v1.5.0 are the versions you'll most often see deployed.
Choosing owners and a threshold
For an admin role, a 3-of-5 or 4-of-7 Safe is typical. The rules from holding crypto safely as a team apply directly: no n-of-n (one lost key freezes the protocol), no 1-of-n, keys on hardware wallets, held by different people in different places, and not all reachable through one laptop or password manager. Many protocols include one or two respected external signers so the core team alone can't push a change.
It also helps to split roles by urgency:
| Role | Holder | Why |
|---|---|---|
| Upgrades, minting, parameter changes | Timelock, proposed by the main Safe | Users get time to see and react |
| Pause / emergency stop | The Safe directly, or a separate guardian Safe with a lower threshold | Must act within minutes |
| Unpause | Main Safe via timelock | Restarting is less urgent than stopping |
| Routine operations (fee collection) | A narrowly scoped role or module | Keeps the admin Safe out of daily use |
How do I move admin rights to a Safe?
The cleanest option is to never give the deployer admin rights at all: pass the Safe's address as initialOwner or defaultAdmin in the constructor or initializer. If the contract is already deployed, transfer each role and then prove the transfer.
Ownable2Step contracts need two steps, which protects you from typos:
# 1. From the current owner (the deployer):
cast send $CONTRACT "transferOwnership(address)" $SAFE \
--rpc-url $RPC_URL --account deployer
# 2. From the Safe: propose a transaction to $CONTRACT calling acceptOwnership()
# (selector 0x79ba5097), collect signatures, execute.
# 3. Verify
cast call $CONTRACT "owner()(address)" --rpc-url $RPC_URL
Plain Ownable transfers in one step, so triple-check the address and confirm it is a Safe on this chain. A Safe address on one network is not automatically a Safe you control on another.
AccessControl contracts need a grant, a check and a renounce:
ADMIN_ROLE=0x0000000000000000000000000000000000000000000000000000000000000000
cast send $CONTRACT "grantRole(bytes32,address)" $ADMIN_ROLE $SAFE --rpc-url $RPC_URL --account deployer
cast call $CONTRACT "hasRole(bytes32,address)(bool)" $ADMIN_ROLE $SAFE --rpc-url $RPC_URL # must be true
cast send $CONTRACT "renounceRole(bytes32,address)" $ADMIN_ROLE $DEPLOYER --rpc-url $RPC_URL --account deployer
Repeat for every other role (MINTER_ROLE, PAUSER_ROLE, UPGRADER_ROLE), because DEFAULT_ADMIN_ROLE can grant them but doesn't revoke existing holders. OpenZeppelin's AccessControlDefaultAdminRules adds a two-step, delayed admin transfer and is worth using in new contracts.
Proxies. For a Transparent proxy in OpenZeppelin v5, the upgrade right belongs to the owner of its ProxyAdmin, so transfer that ownership. For UUPS, upgrades are gated by whatever _authorizeUpgrade checks, usually the contract owner. How upgradeable proxies work covers where each pattern keeps that authority.
Then audit the Safe itself, on every chain where it holds power:
cast call $SAFE "getOwners()(address[])" --rpc-url $RPC_URL
cast call $SAFE "getThreshold()(uint256)" --rpc-url $RPC_URL
cast call $SAFE "VERSION()(string)" --rpc-url $RPC_URL
# Enabled modules: start from the sentinel address 0x1
cast call $SAFE "getModulesPaginated(address,uint256)(address[],address)" \
0x0000000000000000000000000000000000000001 10 --rpc-url $RPC_URL
# Transaction guard: keccak256("guard_manager.guard.address")
cast storage $SAFE 0x4a204f620c8c5ccdca3fd54d003badd85ba500436a431f0cbda4f558c93c34c8 --rpc-url $RPC_URL
Expect the owners and threshold you agreed, no modules you didn't deliberately enable, and a guard of zero unless you installed one.
How do I add a timelock?
A Safe stops one person acting alone. A timelock stops the signers acting quickly, which matters if they are coerced, phished or simply wrong. OpenZeppelin's TimelockController queues each call and only executes it after a minimum delay:
// in a Foundry deploy script
address[] memory proposers = new address[](1);
proposers[0] = SAFE; // proposers also receive CANCELLER_ROLE
address[] memory executors = new address[](1);
executors[0] = SAFE; // or address(0) to let anyone execute once the delay has passed
TimelockController timelock = new TimelockController(
2 days, // minDelay
proposers,
executors,
address(0) // no separate admin: the timelock administers itself
);
Make the timelock the owner or admin of the protocol contracts, and keep the emergency pause role outside it. Changing the delay must itself go through the timelock, so nobody can shorten it quietly. Publish the timelock address and monitor CallScheduled events so users and your own team see every queued change. A delay is only useful if someone is watching.
How do signers avoid approving a malicious transaction?
In February 2025, attackers who had compromised the Safe web interface showed Bybit's signers a routine-looking transfer while the hardware wallets were actually asked to sign a DELEGATECALL that replaced the Safe's logic. The multisig contracts worked exactly as designed. The signers simply could not see what they were approving.
Every signer should check, for every transaction:
tois the expected contract andoperationis0. A1should almost never appear outside a deliberate, reviewed batch through Safe'sMultiSendCallOnly.datadecodes to the expected function and arguments.value,gasToken,refundReceiverand gas fields are zero unless intended.nonceis the next one and matches what other signers see.- The Safe transaction hash shown on the hardware wallet matches one you computed independently of the web interface.
You can recompute the hash yourself in a few lines, here with viem:
import { hashTypedData, zeroAddress, encodeFunctionData, parseAbi } from "viem";
const data = encodeFunctionData({
abi: parseAbi(["function acceptOwnership()"]),
functionName: "acceptOwnership",
});
const safeTxHash = hashTypedData({
domain: { chainId: 1, verifyingContract: SAFE }, // Safe 1.3.0+ domain
types: {
SafeTx: [
{ name: "to", type: "address" },
{ name: "value", type: "uint256" },
{ name: "data", type: "bytes" },
{ name: "operation", type: "uint8" },
{ name: "safeTxGas", type: "uint256" },
{ name: "baseGas", type: "uint256" },
{ name: "gasPrice", type: "uint256" },
{ name: "gasToken", type: "address" },
{ name: "refundReceiver", type: "address" },
{ name: "nonce", type: "uint256" },
],
},
primaryType: "SafeTx",
message: {
to: CONTRACT, value: 0n, data, operation: 0,
safeTxGas: 0n, baseGas: 0n, gasPrice: 0n,
gasToken: zeroAddress, refundReceiver: zeroAddress,
nonce: 7n, // read the live value with nonce() on the Safe
},
});
console.log(safeTxHash);
Open-source tools such as safe-tx-hashes-util do the same from the command line and also print the domain and message hashes that many hardware wallets display. Beyond hashing: simulate each transaction against current state and read the resulting state changes, have at least one signer use a different interface (a self-hosted UI or CLI), and use hardware wallets that decode the transaction rather than blind-signing it.
Keeping it secure over time
- Rotate owners with
swapOwner(prevOwner, oldOwner, newOwner)when people leave, the same week they leave. Owners are a linked list, soprevOwneris the entry beforeoldOwner(the sentinel0x...01for the first one). - Treat configuration changes as critical.
addOwnerWithThreshold,removeOwner,changeThreshold,enableModuleandsetGuarddeserve the same review as an upgrade. - Monitor every proposal, signature, execution and configuration change, and alert on any
DELEGATECALL. - Run a drill: once a year, have each signer sign a harmless transaction from their backup.
- Document the Safe address per chain, its owners, threshold, version, modules and what each role controls. Auditors will ask for exactly this, as described in preparing for a smart contract audit.
Checklist
- Deploy with the Safe (or timelock) as owner and admin from the start.
- For existing contracts, transfer every role, verify with
owner()/hasRole, then renounce the deployer's roles. - Use 3-of-5 or stronger, hardware wallets, independent holders and locations.
- Route non-emergency changes through a
TimelockControllerwith a published delay; keep pausing fast. - Check
getOwners,getThreshold, modules and guard on every chain. - Before signing: expected
to,operation = 0, decodeddata, zero gas-refund fields, correct nonce, independently computed hash. - Simulate, use a second interface, and monitor every Safe and timelock event.
Get the weekly commit
New blockchain deep dives every week.