Skip to content

Commit

Permalink
Merge pull request #37 from valory-xyz/multisig
Browse files Browse the repository at this point in the history
fix: multisig implementation
  • Loading branch information
kupermind authored Aug 17, 2022
2 parents 2ec7dae + c926e97 commit ed5f1d9
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 15 deletions.
46 changes: 44 additions & 2 deletions abis/GnosisSafeMultisig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,48 @@
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "expected",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "provided",
"type": "uint256"
}
],
"name": "IncorrectDataLength",
"type": "error"
},
{
"inputs": [],
"name": "DEFAULT_DATA_LENGTH",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "GNOSIS_SAFE_SETUP_SELECTOR",
"outputs": [
{
"internalType": "bytes4",
"name": "",
"type": "bytes4"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -75,8 +117,8 @@
"type": "function"
}
],
"bytecode": "0x60c060405234801561001057600080fd5b5060405161068c38038061068c83398101604081905261002f9161005e565b6001600160a01b039182166080521660a052610098565b6001600160a01b038116811461005b57600080fd5b50565b6000806040838503121561007157600080fd5b825161007c81610046565b602084015190925061008d81610046565b809150509250929050565b60805160a0516105c36100c960003960008181604b0152610182015260008181608e01526101af01526105c36000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063490b7a7914610046578063a84173ae14610089578063f398dba8146100b0575b600080fd5b61006d7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200160405180910390f35b61006d7f000000000000000000000000000000000000000000000000000000000000000081565b61006d6100be366004610351565b6000806000806000806000806100d38961022e565b9650965096509650965096509650600063b63e800d60e01b8c8c8a858b8b8a8c60405160240161010a98979695949392919061047b565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909416939093179092529051631688f0b960e01b81529091506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690631688f0b9906101db907f00000000000000000000000000000000000000000000000000000000000000009085908890600401610537565b6020604051808303816000875af11580156101fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061021e9190610569565b9c9b505050505050505050505050565b6000806000806000806060600088511115610277575050855160148701516028880151603c89015160508a015160708b015160908c0151958c0151949a50929850909650945092505b919395979092949650565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156102c1576102c1610282565b604052919050565b6001600160a01b03811681146102de57600080fd5b50565b600082601f8301126102f257600080fd5b813567ffffffffffffffff81111561030c5761030c610282565b61031f601f8201601f1916602001610298565b81815284602083860101111561033457600080fd5b816020850160208301376000918101602001919091529392505050565b60008060006060848603121561036657600080fd5b833567ffffffffffffffff8082111561037e57600080fd5b818601915086601f83011261039257600080fd5b81356020828211156103a6576103a6610282565b8160051b6103b5828201610298565b928352848101820192828101908b8511156103cf57600080fd5b958301955b848710156103f957863592506103e9836102c9565b82825295830195908301906103d4565b98505050870135945050604086013591508082111561041757600080fd5b50610424868287016102e1565b9150509250925092565b6000815180845260005b8181101561045457602081850181015186830182015201610438565b81811115610466576000602083870101525b50601f01601f19169290920160200192915050565b6101008082528951908201819052600090610120830190602090818d01845b828110156104bf5781516001600160a01b03168552938301939083019060010161049a565b50505083018a90526001600160a01b038916604084015282810360608401526104e8818961042e565b91505061050060808301876001600160a01b03169052565b6001600160a01b03851660a08301528360c083015261052a60e08301846001600160a01b03169052565b9998505050505050505050565b6001600160a01b0384168152606060208201526000610559606083018561042e565b9050826040830152949350505050565b60006020828403121561057b57600080fd5b8151610586816102c9565b939250505056fea26469706673582212209c1f4278c73ec349d9a4e6a42f437e9e98177a52ff1db3584f23086723c3152964736f6c634300080f0033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100415760003560e01c8063490b7a7914610046578063a84173ae14610089578063f398dba8146100b0575b600080fd5b61006d7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200160405180910390f35b61006d7f000000000000000000000000000000000000000000000000000000000000000081565b61006d6100be366004610351565b6000806000806000806000806100d38961022e565b9650965096509650965096509650600063b63e800d60e01b8c8c8a858b8b8a8c60405160240161010a98979695949392919061047b565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909416939093179092529051631688f0b960e01b81529091506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690631688f0b9906101db907f00000000000000000000000000000000000000000000000000000000000000009085908890600401610537565b6020604051808303816000875af11580156101fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061021e9190610569565b9c9b505050505050505050505050565b6000806000806000806060600088511115610277575050855160148701516028880151603c89015160508a015160708b015160908c0151958c0151949a50929850909650945092505b919395979092949650565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156102c1576102c1610282565b604052919050565b6001600160a01b03811681146102de57600080fd5b50565b600082601f8301126102f257600080fd5b813567ffffffffffffffff81111561030c5761030c610282565b61031f601f8201601f1916602001610298565b81815284602083860101111561033457600080fd5b816020850160208301376000918101602001919091529392505050565b60008060006060848603121561036657600080fd5b833567ffffffffffffffff8082111561037e57600080fd5b818601915086601f83011261039257600080fd5b81356020828211156103a6576103a6610282565b8160051b6103b5828201610298565b928352848101820192828101908b8511156103cf57600080fd5b958301955b848710156103f957863592506103e9836102c9565b82825295830195908301906103d4565b98505050870135945050604086013591508082111561041757600080fd5b50610424868287016102e1565b9150509250925092565b6000815180845260005b8181101561045457602081850181015186830182015201610438565b81811115610466576000602083870101525b50601f01601f19169290920160200192915050565b6101008082528951908201819052600090610120830190602090818d01845b828110156104bf5781516001600160a01b03168552938301939083019060010161049a565b50505083018a90526001600160a01b038916604084015282810360608401526104e8818961042e565b91505061050060808301876001600160a01b03169052565b6001600160a01b03851660a08301528360c083015261052a60e08301846001600160a01b03169052565b9998505050505050505050565b6001600160a01b0384168152606060208201526000610559606083018561042e565b9050826040830152949350505050565b60006020828403121561057b57600080fd5b8151610586816102c9565b939250505056fea26469706673582212209c1f4278c73ec349d9a4e6a42f437e9e98177a52ff1db3584f23086723c3152964736f6c634300080f0033",
"bytecode": "0x60c060405234801561001057600080fd5b5060405161088f38038061088f83398101604081905261002f9161005e565b6001600160a01b039182166080521660a052610098565b6001600160a01b038116811461005b57600080fd5b50565b6000806040838503121561007157600080fd5b825161007c81610046565b602084015190925061008d81610046565b809150509250929050565b60805160a0516107c66100c960003960008181607101526101fe01526000818160f4015261022b01526107c66000f3fe608060405234801561001057600080fd5b50600436106100675760003560e01c8063a84173ae11610050578063a84173ae146100ef578063f02fb77414610116578063f398dba81461012c57600080fd5b8063490b7a791461006c5780639f1a308d146100b0575b600080fd5b6100937f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b6100be63b63e800d60e01b81565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020016100a7565b6100937f000000000000000000000000000000000000000000000000000000000000000081565b61011e609081565b6040519081526020016100a7565b61009361013a3660046104e0565b60008060008060008060008061014f896102aa565b9650965096509650965096509650600063b63e800d60e01b8c8c8a858b8b8a8c60405160240161018698979695949392919061060a565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909416939093179092529051631688f0b960e01b81529091506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690631688f0b990610257907f000000000000000000000000000000000000000000000000000000000000000090859088906004016106c6565b6020604051808303816000875af1158015610276573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061029a91906106f8565b9c9b505050505050505050505050565b600080600080600080606060008851905060008111156104055760908110156102f457604051631a64813d60e11b8152609060048201526024810182905260440160405180910390fd5b601489015160288a0151603c8b015160508c015160708d01516090808f0151959d50939b5091995097509550909350811115610405576000610337609083610732565b90508067ffffffffffffffff81111561035257610352610411565b6040519080825280601f01601f19166020018201604052801561037c576020820181803683370190505b50925060005b81811015610402578a610396609083610749565b815181106103a6576103a6610761565b602001015160f81c60f81b8482815181106103c3576103c3610761565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506103fb81610777565b9050610382565b50505b50919395979092949650565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561045057610450610411565b604052919050565b6001600160a01b038116811461046d57600080fd5b50565b600082601f83011261048157600080fd5b813567ffffffffffffffff81111561049b5761049b610411565b6104ae601f8201601f1916602001610427565b8181528460208386010111156104c357600080fd5b816020850160208301376000918101602001919091529392505050565b6000806000606084860312156104f557600080fd5b833567ffffffffffffffff8082111561050d57600080fd5b818601915086601f83011261052157600080fd5b813560208282111561053557610535610411565b8160051b610544828201610427565b928352848101820192828101908b85111561055e57600080fd5b958301955b84871015610588578635925061057883610458565b8282529583019590830190610563565b9850505087013594505060408601359150808211156105a657600080fd5b506105b386828701610470565b9150509250925092565b6000815180845260005b818110156105e3576020818501810151868301820152016105c7565b818111156105f5576000602083870101525b50601f01601f19169290920160200192915050565b6101008082528951908201819052600090610120830190602090818d01845b8281101561064e5781516001600160a01b031685529383019390830190600101610629565b50505083018a90526001600160a01b0389166040840152828103606084015261067781896105bd565b91505061068f60808301876001600160a01b03169052565b6001600160a01b03851660a08301528360c08301526106b960e08301846001600160a01b03169052565b9998505050505050505050565b6001600160a01b03841681526060602082015260006106e860608301856105bd565b9050826040830152949350505050565b60006020828403121561070a57600080fd5b815161071581610458565b9392505050565b634e487b7160e01b600052601160045260246000fd5b6000828210156107445761074461071c565b500390565b6000821982111561075c5761075c61071c565b500190565b634e487b7160e01b600052603260045260246000fd5b6000600182016107895761078961071c565b506001019056fea2646970667358221220aeec25f6d5a9ba84978d729d37d2fa5d70a5d052dc0764959363db48561022f664736f6c634300080f0033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100675760003560e01c8063a84173ae11610050578063a84173ae146100ef578063f02fb77414610116578063f398dba81461012c57600080fd5b8063490b7a791461006c5780639f1a308d146100b0575b600080fd5b6100937f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b6100be63b63e800d60e01b81565b6040517fffffffff0000000000000000000000000000000000000000000000000000000090911681526020016100a7565b6100937f000000000000000000000000000000000000000000000000000000000000000081565b61011e609081565b6040519081526020016100a7565b61009361013a3660046104e0565b60008060008060008060008061014f896102aa565b9650965096509650965096509650600063b63e800d60e01b8c8c8a858b8b8a8c60405160240161018698979695949392919061060a565b60408051601f198184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909416939093179092529051631688f0b960e01b81529091506001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690631688f0b990610257907f000000000000000000000000000000000000000000000000000000000000000090859088906004016106c6565b6020604051808303816000875af1158015610276573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061029a91906106f8565b9c9b505050505050505050505050565b600080600080600080606060008851905060008111156104055760908110156102f457604051631a64813d60e11b8152609060048201526024810182905260440160405180910390fd5b601489015160288a0151603c8b015160508c015160708d01516090808f0151959d50939b5091995097509550909350811115610405576000610337609083610732565b90508067ffffffffffffffff81111561035257610352610411565b6040519080825280601f01601f19166020018201604052801561037c576020820181803683370190505b50925060005b81811015610402578a610396609083610749565b815181106103a6576103a6610761565b602001015160f81c60f81b8482815181106103c3576103c3610761565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506103fb81610777565b9050610382565b50505b50919395979092949650565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff8111828210171561045057610450610411565b604052919050565b6001600160a01b038116811461046d57600080fd5b50565b600082601f83011261048157600080fd5b813567ffffffffffffffff81111561049b5761049b610411565b6104ae601f8201601f1916602001610427565b8181528460208386010111156104c357600080fd5b816020850160208301376000918101602001919091529392505050565b6000806000606084860312156104f557600080fd5b833567ffffffffffffffff8082111561050d57600080fd5b818601915086601f83011261052157600080fd5b813560208282111561053557610535610411565b8160051b610544828201610427565b928352848101820192828101908b85111561055e57600080fd5b958301955b84871015610588578635925061057883610458565b8282529583019590830190610563565b9850505087013594505060408601359150808211156105a657600080fd5b506105b386828701610470565b9150509250925092565b6000815180845260005b818110156105e3576020818501810151868301820152016105c7565b818111156105f5576000602083870101525b50601f01601f19169290920160200192915050565b6101008082528951908201819052600090610120830190602090818d01845b8281101561064e5781516001600160a01b031685529383019390830190600101610629565b50505083018a90526001600160a01b0389166040840152828103606084015261067781896105bd565b91505061068f60808301876001600160a01b03169052565b6001600160a01b03851660a08301528360c08301526106b960e08301846001600160a01b03169052565b9998505050505050505050565b6001600160a01b03841681526060602082015260006106e860608301856105bd565b9050826040830152949350505050565b60006020828403121561070a57600080fd5b815161071581610458565b9392505050565b634e487b7160e01b600052601160045260246000fd5b6000828210156107445761074461071c565b500390565b6000821982111561075c5761075c61071c565b500190565b634e487b7160e01b600052603260045260246000fd5b6000600182016107895761078961071c565b506001019056fea2646970667358221220aeec25f6d5a9ba84978d729d37d2fa5d70a5d052dc0764959363db48561022f664736f6c634300080f0033",
"linkReferences": {},
"deployedLinkReferences": {}
}
38 changes: 29 additions & 9 deletions contracts/multisigs/GnosisSafeMultisig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ interface IGnosisSafeProxyFactory {
) external returns (address proxy);
}

/// @dev Provided incorrect data length.
/// @param expected Expected minimum data length.
/// @param provided Provided data length.
error IncorrectDataLength(uint256 expected, uint256 provided);

/// @title Gnosis Safe - Smart contract for Gnosis Safe multisig implementation of a generic multisig interface
/// @author Aleksandr Kuperman - <[email protected]>
contract GnosisSafeMultisig {
// Selector of the Gnosis Safe setup function
bytes4 internal constant _GNOSIS_SAFE_SETUP_SELECTOR = 0xb63e800d;
bytes4 public constant GNOSIS_SAFE_SETUP_SELECTOR = 0xb63e800d;
// Default data size to be parsed and passed to the Gnosis Safe Factory without payload
uint256 public constant DEFAULT_DATA_LENGTH = 144;
// Gnosis Safe
address payable public immutable gnosisSafe;
// Gnosis Safe Factory
Expand All @@ -33,15 +40,22 @@ contract GnosisSafeMultisig {
}

/// @dev Parses (unpacks) the data to gnosis safe specific parameters.
/// @notice If the provided data is not empty, its length must be at least 144 bytes to be parsed correctly.
/// @param data Packed data related to the creation of a gnosis safe multisig.
function _parseData(bytes memory data) internal pure
returns (address to, address fallbackHandler, address paymentToken, address payable paymentReceiver,
uint256 payment, uint256 nonce, bytes memory payload)
{
if (data.length > 0) {
uint256 dataSize = data.length;
uint256 dataLength = data.length;
if (dataLength > 0) {
// Check for the correct data length
if (dataLength < DEFAULT_DATA_LENGTH) {
revert IncorrectDataLength(DEFAULT_DATA_LENGTH, dataLength);
}

// Read the first 144 bytes of data
assembly {
// Read all the addresses first
// Read all the addresses first (80 bytes)
let offset := 20
to := mload(add(data, offset))
offset := add(offset, 20)
Expand All @@ -51,14 +65,20 @@ contract GnosisSafeMultisig {
offset := add(offset, 20)
paymentReceiver := mload(add(data, offset))

// Read all the uints
// Read all the uints (64 more bytes, a total of 144 bytes)
offset := add(offset, 32)
payment := mload(add(data, offset))
offset := add(offset, 32)
nonce := mload(add(data, offset))
}

// Read the payload data
payload := mload(add(data, dataSize))
// Read the payload, if provided
if (dataLength > DEFAULT_DATA_LENGTH) {
uint256 payloadLength = dataLength - DEFAULT_DATA_LENGTH;
payload = new bytes(payloadLength);
for (uint256 i = 0; i < payloadLength; ++i) {
payload[i] = data[i + DEFAULT_DATA_LENGTH];
}
}
}
}
Expand All @@ -78,8 +98,8 @@ contract GnosisSafeMultisig {
(address to, address fallbackHandler, address paymentToken, address payable paymentReceiver, uint256 payment,
uint256 nonce, bytes memory payload) = _parseData(data);

// Encode the gmosis setup function parameters
bytes memory safeParams = abi.encodeWithSelector(_GNOSIS_SAFE_SETUP_SELECTOR, owners, threshold,
// Encode the gnosis setup function parameters
bytes memory safeParams = abi.encodeWithSelector(GNOSIS_SAFE_SETUP_SELECTOR, owners, threshold,
to, payload, fallbackHandler, paymentToken, payment, paymentReceiver);

// Create a gnosis safe multisig via the proxy factory
Expand Down
Loading

0 comments on commit ed5f1d9

Please sign in to comment.