Skip to content

Commit

Permalink
Consistency cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mdehoog committed Oct 20, 2024
1 parent e817916 commit de4c8bb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
28 changes: 15 additions & 13 deletions script/universal/MultisigBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ abstract contract MultisigBuilder is MultisigBase {
// Snapshot and restore Safe nonce after simulation, otherwise the data logged to sign
// would not match the actual data we need to sign, because the simulation
// would increment the nonce.
uint256 originalNonce = _getNonce(safe);
uint256 nonce = _getNonce(safe);

IMulticall3.Call3[] memory calls = _buildCalls();
(Vm.AccountAccess[] memory accesses, SimulationPayload memory simPayload) = _simulateForSigner(safe, calls);
_postSign(accesses, simPayload);
_postCheck();

// Restore the original nonce.
vm.store(address(safe), SAFE_NONCE_SLOT, bytes32(uint256(originalNonce)));
vm.store(address(safe), SAFE_NONCE_SLOT, bytes32(nonce));

_printDataToSign(safe, calls);
}

/**
* Step 2
* Step 1.1 (optional)
* ======
* Verify the signatures generated from step 1 are valid.
* This allow transactions to be pre-signed and stored safely before execution.
Expand All @@ -90,23 +90,17 @@ abstract contract MultisigBuilder is MultisigBase {
_checkSignatures(IGnosisSafe(_ownerSafe()), _buildCalls(), _signatures);
}

function nonce() public view {
IGnosisSafe safe = IGnosisSafe(_ownerSafe());
console.log("Nonce:", safe.nonce());
}

/**
* Step 3
* Step 1.2 (optional)
* ======
* Simulate the transaction. This method should be called by the final member of the multisig
* Simulate the transaction. This method can be called by the final member of the multisig
* that will execute the transaction. Signatures from step 1 are required.
*
* Differs from `run` in that you can override the safe nonce for simulation purposes.
*/
function simulate(bytes memory _signatures) public {
IGnosisSafe safe = IGnosisSafe(_ownerSafe());
uint256 _nonce = _getNonce(safe);
vm.store(address(safe), SAFE_NONCE_SLOT, bytes32(uint256(_nonce)));
vm.store(address(safe), SAFE_NONCE_SLOT, bytes32(_getNonce(safe)));

(Vm.AccountAccess[] memory accesses, SimulationPayload memory simPayload) = _executeTransaction(safe, _buildCalls(), _signatures);

Expand All @@ -115,7 +109,7 @@ abstract contract MultisigBuilder is MultisigBase {
}

/**
* Step 4
* Step 2
* ======
* Execute the transaction. This method should be called by the final member of the multisig
* that will execute the transaction. Signatures from step 1 are required.
Expand All @@ -132,6 +126,14 @@ abstract contract MultisigBuilder is MultisigBase {
_postCheck();
}

/**
* Print the current safe nonce.
*/
function nonce() public view {
IGnosisSafe safe = IGnosisSafe(_ownerSafe());
console.log("Nonce:", safe.nonce());
}

function _readFrom_SAFE_NONCE() internal pure override returns (bool) {
return true;
}
Expand Down
17 changes: 15 additions & 2 deletions script/universal/NestedMultisigBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,25 @@ abstract contract NestedMultisigBuilder is MultisigBase {
_postCheck();

// Restore the original nonce.
vm.store(address(nestedSafe), SAFE_NONCE_SLOT, bytes32(uint256(originalNonce)));
vm.store(address(_signerSafe), SAFE_NONCE_SLOT, bytes32(uint256(originalSignerNonce)));
vm.store(address(nestedSafe), SAFE_NONCE_SLOT, bytes32(originalNonce));
vm.store(address(_signerSafe), SAFE_NONCE_SLOT, bytes32(originalSignerNonce));

_printDataToSign(_signerSafe, toArray(call));
}

/**
* Step 1.1 (optional)
* ======
* Verify the signatures generated from step 1 are valid.
* This allow transactions to be pre-signed and stored safely before execution.
*/
function verify(IGnosisSafe _signerSafe, bytes memory _signatures) public view {
IGnosisSafe nestedSafe = IGnosisSafe(_ownerSafe());
IMulticall3.Call3[] memory nestedCalls = _buildCalls();
IMulticall3.Call3 memory call = _generateApproveCall(nestedSafe, nestedCalls);
_checkSignatures(_signerSafe, toArray(call), _signatures);
}

/**
* Step 2
* ======
Expand Down

0 comments on commit de4c8bb

Please sign in to comment.