Al-Qa-qa / dyad-private-audit

4 stars 1 forks source link

How to Deploy when the Owner is Safe Wallet #13

Open Al-Qa-qa opened 1 week ago

Al-Qa-qa commented 1 week ago

Firstly, we need to understand how openzeppelin-foundry-upgrades upgrade the contract UUPS.

  1. It deploys the new implementation
  2. calls upgradeToAndCall(newImpl, data)

And here is how Safe Wallet execute Transactions.

    function execTransaction(
        address to, 
        uint256 value, // Zero
        bytes calldata data, // Thi
        Enum.Operation operation,
        uint256 safeTxGas,
        uint256 baseGas,
        uint256 gasPrice,
        address gasToken,
        address payable refundReceiver,
        bytes memory signatures // Safe Owners Signatures to execute this transaction
    ) public payable virtual override returns (bool success) {

So what we should do is:

This can be done manually (without using openzeppelin-foundry-upgrades), but this lib bootstrap the process in just one thing, and perform some checks which is safer.


I do not know if this library has a relation do OZ::defender or not. But I found that the defender has deploy module that supports SafeWallets. https://docs.openzeppelin.com/defender/v2/tutorial/deploy

Since the Owner is SafeWallet (MultiSig), when I searched in the Docs, I found that this lib can integrats with OpenZepplin Defender, and Defender supports Safe Wallets and supports deploying using CLI too, but it is a paid service.

IDK, if this lib supports MultiSig or not but in I think it did not.


In brief, If the team already has a Defender plan, then I think it is better to follow Defender guide. But if not, we have two solutions.

shafu0x commented 1 week ago

Yeah lets go with step 1

Al-Qa-qa commented 1 week ago

Great! You can deploy the VaultManagerV3 contract. There is no problem who deployed it.

It will be the same as simple contract deploying process.

shafu0x commented 1 week ago

just to double confirm. This is the correct data 0x8129fc1c

Its just abi.encodeCall(VaultManagerV3.initialize, ())

Al-Qa-qa commented 1 week ago

Yea. then you will encode upgradeToAndCall(address newImplementation, bytes memory data).

newImplementation: VaultManagerV3 implementation data: 0x8129fc1c

shafu0x commented 1 week ago

why do I need to encode that? I should just call it directly through the multi sig right?

Al-Qa-qa commented 1 week ago

Yea, you can call it from mutliSig Directly (using UI). I though you want to run it in script.