Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions script/universal/MultisigBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "./Simulator.sol";

abstract contract MultisigBase is Simulator {
IMulticall3 internal constant multicall = IMulticall3(MULTICALL3_ADDRESS);
bytes32 internal constant SAFE_NONCE_SLOT = bytes32(uint256(5));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is risk this will collide with another value that is automatically assigned by solc


function _getTransactionHash(address _safe, IMulticall3.Call3[] memory calls) internal view returns (bytes32) {
bytes memory data = abi.encodeCall(IMulticall3.aggregate3, (calls));
Expand Down
10 changes: 10 additions & 0 deletions script/universal/MultisigBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,19 @@ abstract contract MultisigBuilder is MultisigBase {
*/
function sign() public {
address safe = _ownerSafe();

// 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 = IGnosisSafe(safe).nonce();

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

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

_printDataToSign(safe, calls);
}

Expand Down
10 changes: 10 additions & 0 deletions script/universal/NestedMultisigBuilder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ abstract contract NestedMultisigBuilder is MultisigBase {
*/
function sign(address _signerSafe) public {
address nestedSafeAddress = _ownerSafe();

// 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 = IGnosisSafe(nestedSafeAddress).nonce();

IMulticall3.Call3[] memory nestedCalls = _buildCalls();
IMulticall3.Call3 memory call = _generateApproveCall(nestedSafeAddress, nestedCalls);
bytes32 hash = _getTransactionHash(_signerSafe, toArray(call));
Expand All @@ -58,6 +64,10 @@ abstract contract NestedMultisigBuilder is MultisigBase {
console.logBytes32(hash);
(Vm.AccountAccess[] memory accesses, SimulationPayload memory simPayload) = _simulateForSigner(_signerSafe, nestedSafeAddress, nestedCalls);
_postCheck(accesses, simPayload);

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

_printDataToSign(_signerSafe, toArray(call));
}

Expand Down