Skip to content

Commit 55f10ca

Browse files
committed
Refactor MultisigProposal and Proposal contracts for improved operation handling and code clarity
- Removed the constant MULTISIG_BYTECODE_HASH from MultisigProposal. - Simplified the getOperations function for better readability. - Enhanced getCalldata to ensure consistent validation of targets, values, arguments, and operations. - Updated internal functions for clarity and conciseness, including _validateAction and _processStateChanges. - Improved logging for proposal actions and calldata.
1 parent 803a740 commit 55f10ca

File tree

3 files changed

+36
-17
lines changed

3 files changed

+36
-17
lines changed

src/proposals/MultisigProposal.sol

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import {Constants} from "@utils/Constants.sol";
99
abstract contract MultisigProposal is Proposal {
1010
using Address for address;
1111

12-
bytes32 public constant MULTISIG_BYTECODE_HASH = bytes32(
13-
0xb89c1b3bdf2cf8827818646bce9a8f6e372885f8c55e5c07acbd307cb133b000
14-
);
15-
1612
struct Call3Value {
1713
address target;
1814
bool allowFailure;
@@ -47,7 +43,8 @@ abstract contract MultisigProposal is Proposal {
4743

4844
require(
4945
targets.length == values.length && values.length == arguments.length
50-
&& arguments.length == operations.length,
46+
&& arguments.length == operations.length
47+
&& operations.length == actions.length,
5148
"Array lengths mismatch"
5249
);
5350

@@ -80,16 +77,34 @@ abstract contract MultisigProposal is Proposal {
8077
function _simulateActions(address multisig) internal {
8178
vm.startPrank(multisig);
8279

83-
/// this is a hack because multisig execTransaction requires owners signatures
84-
/// so we cannot simulate it exactly as it will be executed on mainnet
85-
vm.etch(multisig, Constants.MULTISEND_BYTECODE);
86-
8780
bytes memory data = getCalldata();
8881

89-
multisig.functionCall(data);
82+
// this is a hack because multisig execTransaction requires owners signatures
83+
// so the SAFE_CREATION_BYTECODE override the checkNSignatures function
84+
bytes memory bytecode = Constants.SAFE_CREATION_BYTECODE;
85+
address addr;
86+
/// @solidity memory-safe-assembly
87+
assembly {
88+
addr := create(0, add(bytecode, 0x20), mload(bytecode))
89+
}
90+
91+
vm.etch(multisig, address(addr).code);
92+
93+
bytes memory safeCalldata = abi.encodeWithSignature(
94+
"execTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes)",
95+
Constants.SAFE_MULTISEND_COTNRACT,
96+
0,
97+
data,
98+
1,
99+
0,
100+
0,
101+
0,
102+
address(0),
103+
address(0),
104+
""
105+
);
90106

91-
/// revert contract code to original safe bytecode
92-
vm.etch(multisig, Constants.SAFE_BYTECODE);
107+
multisig.functionCall(safeCalldata);
93108

94109
vm.stopPrank();
95110
}

src/proposals/Proposal.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {Test} from "@forge-std/Test.sol";
44
import {VmSafe} from "@forge-std/Vm.sol";
55
import {console} from "@forge-std/console.sol";
66

7+
import {Addresses} from "@addresses/Addresses.sol";
78
import {Script} from "@forge-std/Script.sol";
89
import {IProposal} from "@proposals/IProposal.sol";
9-
import {Addresses} from "@addresses/Addresses.sol";
1010

1111
abstract contract Proposal is Test, Script, IProposal {
1212
struct Action {
@@ -363,10 +363,10 @@ abstract contract Proposal is Test, Script, IProposal {
363363
/// static calls are ignored,
364364
/// calls to and from Addresses and the vm contract are ignored
365365
if (
366+
/// ignore calls to vm in the build function
366367
accountAccesses[i].account != address(addresses)
367368
&& accountAccesses[i].account != address(vm)
368-
/// ignore calls to vm in the build function
369-
&& accountAccesses[i].accessor != address(addresses)
369+
&& accountAccesses[i].accessor != address(addresses)
370370
&& accountAccesses[i].kind == VmSafe.AccountAccessKind.Call
371371
&& accountAccesses[i].accessor == caller
372372
) {

0 commit comments

Comments
 (0)