Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setting one multisig proxy and updating deployment scripts #127

Merged
merged 11 commits into from
Oct 13, 2023
23 changes: 23 additions & 0 deletions .gitleaksignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,26 @@ d780294b8dccf047391a71b75dade50a6b89003b:scripts/deployment/l2/globals_gnosis_ch
7bb76e80382eff3c538af340289ed8241f4e4551:scripts/deployment/l2/globals_gnosis_mainnet.json:generic-api-key:1
7bb76e80382eff3c538af340289ed8241f4e4551:scripts/deployment/l2/globals_gnosis_mainnet.json:generic-api-key:2
233a57ccda8d5d84a86133422daa99807801d9fc:scripts/deployment/l2/globals_gnosis_mainnet.json:generic-api-key:2
1b4ec3abe37c5a421a210e8a05a5b958bcc7cfb0:scripts/deployment/globals_goerli.json:generic-api-key:1
1b4ec3abe37c5a421a210e8a05a5b958bcc7cfb0:scripts/deployment/globals_mainnet.json:generic-api-key:1
1b4ec3abe37c5a421a210e8a05a5b958bcc7cfb0:scripts/deployment/l2/globals_gnosis_chiado.json:generic-api-key:1
1b4ec3abe37c5a421a210e8a05a5b958bcc7cfb0:scripts/deployment/l2/globals_polygon_mumbai.json:generic-api-key:1
1b4ec3abe37c5a421a210e8a05a5b958bcc7cfb0:scripts/deployment/l2/globals_gnosis_mainnet.json:generic-api-key:1
2e77fa04c7a0ed385634fc898d732e1f6b23c1c9:scripts/deployment/globals_goerli.json:generic-api-key:2
2e77fa04c7a0ed385634fc898d732e1f6b23c1c9:scripts/deployment/globals_mainnet.json:generic-api-key:2
2e77fa04c7a0ed385634fc898d732e1f6b23c1c9:scripts/deployment/l2/globals_gnosis_mainnet.json:generic-api-key:2
2e77fa04c7a0ed385634fc898d732e1f6b23c1c9:scripts/deployment/l2/globals_polygon_mumbai.json:generic-api-key:2
2e77fa04c7a0ed385634fc898d732e1f6b23c1c9:scripts/deployment/l2/globals_gnosis_chiado.json:generic-api-key:2
b655baf97c240fe09ce8c33cb311cb8cc90d181d:scripts/deployment/l2/globals_polygon_mumbai.json:generic-api-key:1
4bbbf2f312aea50f56a717bdca1dcba20b7c65f7:scripts/deployment/globals_goerli.json:generic-api-key:1
4bbbf2f312aea50f56a717bdca1dcba20b7c65f7:scripts/deployment/l2/globals_gnosis_chiado.json:generic-api-key:1
b655baf97c240fe09ce8c33cb311cb8cc90d181d:scripts/deployment/l2/globals_polygon_mumbai.json:generic-api-key:2
5b94e8e28b716f44772e31a5861b990288b0a52d:scripts/deployment/l2/globals_gnosis_chiado.json:generic-api-key:2
5b94e8e28b716f44772e31a5861b990288b0a52d:scripts/deployment/globals_goerli.json:generic-api-key:2
1b4ec3abe37c5a421a210e8a05a5b958bcc7cfb0:scripts/deployment/globals_mainnet.json:generic-api-key:2
1b4ec3abe37c5a421a210e8a05a5b958bcc7cfb0:scripts/deployment/globals_goerli.json:generic-api-key:2
1b4ec3abe37c5a421a210e8a05a5b958bcc7cfb0:scripts/deployment/l2/globals_gnosis_mainnet.json:generic-api-key:2
1b4ec3abe37c5a421a210e8a05a5b958bcc7cfb0:scripts/deployment/l2/globals_polygon_mumbai.json:generic-api-key:2
1b4ec3abe37c5a421a210e8a05a5b958bcc7cfb0:scripts/deployment/l2/globals_gnosis_chiado.json:generic-api-key:2
4bbbf2f312aea50f56a717bdca1dcba20b7c65f7:scripts/deployment/globals_goerli.json:generic-api-key:2
4bbbf2f312aea50f56a717bdca1dcba20b7c65f7:scripts/deployment/l2/globals_gnosis_chiado.json:generic-api-key:2
163 changes: 163 additions & 0 deletions abis/0.8.21/GnosisSafeSameAddressMultisig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "GnosisSafeSameAddressMultisig",
"sourceName": "contracts/multisigs/GnosisSafeSameAddressMultisig.sol",
"abi": [
{
"inputs": [
{
"internalType": "bytes32",
"name": "_proxyHash",
"type": "bytes32"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "expected",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "provided",
"type": "uint256"
}
],
"name": "IncorrectDataLength",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "provided",
"type": "address"
}
],
"name": "MultisigExecFailed",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "multisig",
"type": "address"
}
],
"name": "UnauthorizedMultisig",
"type": "error"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "expected",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "provided",
"type": "uint256"
}
],
"name": "WrongNumOwners",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "provided",
"type": "address"
}
],
"name": "WrongOwner",
"type": "error"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "expected",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "provided",
"type": "uint256"
}
],
"name": "WrongThreshold",
"type": "error"
},
{
"inputs": [],
"name": "ZeroValue",
"type": "error"
},
{
"inputs": [],
"name": "DEFAULT_DATA_LENGTH",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address[]",
"name": "owners",
"type": "address[]"
},
{
"internalType": "uint256",
"name": "threshold",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "data",
"type": "bytes"
}
],
"name": "create",
"outputs": [
{
"internalType": "address",
"name": "multisig",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "proxyHash",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
}
],
"bytecode": "0x60a060405234801561000f575f80fd5b5060405161087338038061087383398101604081905261002e91610054565b8061004c57604051637c946ed760e01b815260040160405180910390fd5b60805261006b565b5f60208284031215610064575f80fd5b5051919050565b6080516107ea6100895f395f81816048015261012101526107ea5ff3fe608060405234801561000f575f80fd5b506004361061003f575f3560e01c8063809cee2f14610043578063f02fb7741461007d578063f398dba814610085575b5f80fd5b61006a7f000000000000000000000000000000000000000000000000000000000000000081565b6040519081526020015b60405180910390f35b61006a601481565b6100986100933660046105a7565b6100b0565b6040516001600160a01b039091168152602001610074565b80515f9060148110156100e8578251604051631a64813d60e11b81526014600482015260248101919091526044015b60405180910390fd5b601483015191505f826001600160a01b0316803b806020016040519081016040528181525f908060200190933c805190602001209050807f0000000000000000000000000000000000000000000000000000000000000000146101685760405162a2307960e51b81526001600160a01b03841660048201526024016100df565b60148211156102d0575f61017d601484610684565b90505f8167ffffffffffffffff811115610199576101996104bc565b6040519080825280601f01601f1916602001820160405280156101c3576020820181803683370190505b5090505f5b8281101561024757866101dc60148361069d565b815181106101ec576101ec6106b0565b602001015160f81c60f81b828281518110610209576102096106b0565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a905350610240816106c4565b90506101c8565b505f856001600160a01b03168260405161026191906106dc565b5f604051808303815f865af19150503d805f811461029a576040519150601f19603f3d011682016040523d82523d5f602084013e61029f565b606091505b50509050806102cc57604051632aacb4bd60e21b81526001600160a01b03871660048201526024016100df565b5050505b5f836001600160a01b031663a0e67e2b6040518163ffffffff1660e01b81526004015f60405180830381865afa15801561030c573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526103339190810190610708565b90505f846001600160a01b031663e75235b86040518163ffffffff1660e01b8152600401602060405180830381865afa158015610372573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610396919061079d565b90508087146103c257604051635372461560e01b815260048101829052602481018890526044016100df565b8751825181146103f257825160405163f720290d60e01b81526004810191909152602481018290526044016100df565b5f5b818110156104af578360016104098385610684565b6104139190610684565b81518110610423576104236106b0565b60200260200101516001600160a01b03168a8281518110610446576104466106b0565b60200260200101516001600160a01b03161461049f5789818151811061046e5761046e6106b0565b60200260200101516040516374dba67360e01b81526004016100df91906001600160a01b0391909116815260200190565b6104a8816106c4565b90506103f4565b5050505050509392505050565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f1916810167ffffffffffffffff811182821017156104f9576104f96104bc565b604052919050565b5f67ffffffffffffffff82111561051a5761051a6104bc565b5060051b60200190565b6001600160a01b0381168114610538575f80fd5b50565b5f82601f83011261054a575f80fd5b813567ffffffffffffffff811115610564576105646104bc565b610577601f8201601f19166020016104d0565b81815284602083860101111561058b575f80fd5b816020850160208301375f918101602001919091529392505050565b5f805f606084860312156105b9575f80fd5b833567ffffffffffffffff808211156105d0575f80fd5b818601915086601f8301126105e3575f80fd5b813560206105f86105f383610501565b6104d0565b82815260059290921b8401810191818101908a841115610616575f80fd5b948201945b8386101561063d57853561062e81610524565b8252948201949082019061061b565b9750508701359450506040860135915080821115610659575f80fd5b506106668682870161053b565b9150509250925092565b634e487b7160e01b5f52601160045260245ffd5b8181038181111561069757610697610670565b92915050565b8082018082111561069757610697610670565b634e487b7160e01b5f52603260045260245ffd5b5f600182016106d5576106d5610670565b5060010190565b5f82515f5b818110156106fb57602081860181015185830152016106e1565b505f920191825250919050565b5f6020808385031215610719575f80fd5b825167ffffffffffffffff81111561072f575f80fd5b8301601f8101851361073f575f80fd5b805161074d6105f382610501565b81815260059190911b8201830190838101908783111561076b575f80fd5b928401925b8284101561079257835161078381610524565b82529284019290840190610770565b979650505050505050565b5f602082840312156107ad575f80fd5b505191905056fea264697066735822122092efac4e2475d70b802a8e95325bc947ca36adb8b352d0b0446335903ef9b60564736f6c63430008150033",
"deployedBytecode": "0x608060405234801561000f575f80fd5b506004361061003f575f3560e01c8063809cee2f14610043578063f02fb7741461007d578063f398dba814610085575b5f80fd5b61006a7f000000000000000000000000000000000000000000000000000000000000000081565b6040519081526020015b60405180910390f35b61006a601481565b6100986100933660046105a7565b6100b0565b6040516001600160a01b039091168152602001610074565b80515f9060148110156100e8578251604051631a64813d60e11b81526014600482015260248101919091526044015b60405180910390fd5b601483015191505f826001600160a01b0316803b806020016040519081016040528181525f908060200190933c805190602001209050807f0000000000000000000000000000000000000000000000000000000000000000146101685760405162a2307960e51b81526001600160a01b03841660048201526024016100df565b60148211156102d0575f61017d601484610684565b90505f8167ffffffffffffffff811115610199576101996104bc565b6040519080825280601f01601f1916602001820160405280156101c3576020820181803683370190505b5090505f5b8281101561024757866101dc60148361069d565b815181106101ec576101ec6106b0565b602001015160f81c60f81b828281518110610209576102096106b0565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a905350610240816106c4565b90506101c8565b505f856001600160a01b03168260405161026191906106dc565b5f604051808303815f865af19150503d805f811461029a576040519150601f19603f3d011682016040523d82523d5f602084013e61029f565b606091505b50509050806102cc57604051632aacb4bd60e21b81526001600160a01b03871660048201526024016100df565b5050505b5f836001600160a01b031663a0e67e2b6040518163ffffffff1660e01b81526004015f60405180830381865afa15801561030c573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f191682016040526103339190810190610708565b90505f846001600160a01b031663e75235b86040518163ffffffff1660e01b8152600401602060405180830381865afa158015610372573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610396919061079d565b90508087146103c257604051635372461560e01b815260048101829052602481018890526044016100df565b8751825181146103f257825160405163f720290d60e01b81526004810191909152602481018290526044016100df565b5f5b818110156104af578360016104098385610684565b6104139190610684565b81518110610423576104236106b0565b60200260200101516001600160a01b03168a8281518110610446576104466106b0565b60200260200101516001600160a01b03161461049f5789818151811061046e5761046e6106b0565b60200260200101516040516374dba67360e01b81526004016100df91906001600160a01b0391909116815260200190565b6104a8816106c4565b90506103f4565b5050505050509392505050565b634e487b7160e01b5f52604160045260245ffd5b604051601f8201601f1916810167ffffffffffffffff811182821017156104f9576104f96104bc565b604052919050565b5f67ffffffffffffffff82111561051a5761051a6104bc565b5060051b60200190565b6001600160a01b0381168114610538575f80fd5b50565b5f82601f83011261054a575f80fd5b813567ffffffffffffffff811115610564576105646104bc565b610577601f8201601f19166020016104d0565b81815284602083860101111561058b575f80fd5b816020850160208301375f918101602001919091529392505050565b5f805f606084860312156105b9575f80fd5b833567ffffffffffffffff808211156105d0575f80fd5b818601915086601f8301126105e3575f80fd5b813560206105f86105f383610501565b6104d0565b82815260059290921b8401810191818101908a841115610616575f80fd5b948201945b8386101561063d57853561062e81610524565b8252948201949082019061061b565b9750508701359450506040860135915080821115610659575f80fd5b506106668682870161053b565b9150509250925092565b634e487b7160e01b5f52601160045260245ffd5b8181038181111561069757610697610670565b92915050565b8082018082111561069757610697610670565b634e487b7160e01b5f52603260045260245ffd5b5f600182016106d5576106d5610670565b5060010190565b5f82515f5b818110156106fb57602081860181015185830152016106e1565b505f920191825250919050565b5f6020808385031215610719575f80fd5b825167ffffffffffffffff81111561072f575f80fd5b8301601f8101851361073f575f80fd5b805161074d6105f382610501565b81815260059190911b8201830190838101908783111561076b575f80fd5b928401925b8284101561079257835161078381610524565b82529284019290840190610770565b979650505050505050565b5f602082840312156107ad575f80fd5b505191905056fea264697066735822122092efac4e2475d70b802a8e95325bc947ca36adb8b352d0b0446335903ef9b60564736f6c63430008150033",
"linkReferences": {},
"deployedLinkReferences": {}
}
31 changes: 10 additions & 21 deletions contracts/multisigs/GnosisSafeSameAddressMultisig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,18 @@ contract GnosisSafeSameAddressMultisig {
// This exact size suggests that all the changes to the multisig have been performed and only validation is needed
uint256 public constant DEFAULT_DATA_LENGTH = 20;

// Map of approved multisig proxy hashes
mapping(bytes32 => bool) public mapMultisigHashes;
// Approved multisig proxy hash
bytes32 public immutable proxyHash;

/// @dev GnosisSafeSameAddressMultisig constructor.
/// @param _multisigProxyHashes Multisig proxy hashes.
constructor(bytes32[] memory _multisigProxyHashes) {
// There must be at least one multisig proxy hash
uint256 size = _multisigProxyHashes.length;
if (size == 0) {
/// @param _proxyHash Approved multisig proxy hash.
constructor(bytes32 _proxyHash) {
if (_proxyHash == bytes32(0)) {
revert ZeroValue();
}

// Record provided multisig proxy bytecode hashes
for (uint256 i = 0; i < size; ++i) {
bytes32 proxyHash = _multisigProxyHashes[i];
// Check for the zero hash
if (proxyHash == bytes32(0)) {
revert ZeroValue();
}

// Hash the proxy bytecode
mapMultisigHashes[proxyHash] = true;
}
// Record provided multisig proxy bytecode hash
proxyHash = _proxyHash;
}

/// @dev Updates and/or verifies the existent gnosis safe multisig for changed owners and threshold.
Expand Down Expand Up @@ -110,9 +99,9 @@ contract GnosisSafeSameAddressMultisig {
multisig := mload(add(data, DEFAULT_DATA_LENGTH))
}

// Check that the multisig address corresponds to the authorized multisig proxy
bytes32 proxyHash = keccak256(multisig.code);
if (!mapMultisigHashes[proxyHash]) {
// Check that the multisig address corresponds to the authorized multisig proxy bytecode hash
bytes32 multisigProxyHash = keccak256(multisig.code);
if (proxyHash != multisigProxyHash) {
revert UnauthorizedMultisig(multisig);
}

Expand Down
32 changes: 11 additions & 21 deletions contracts/staking/ServiceStakingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ abstract contract ServiceStakingBase is ERC721TokenReceiver, IErrorsRegistries {
bytes32 public immutable configHash;
// ServiceRegistry contract address
address public immutable serviceRegistry;
// Approved multisig proxy hash
bytes32 public immutable proxyHash;

// Token / ETH balance
uint256 public balance;
Expand All @@ -156,14 +158,12 @@ abstract contract ServiceStakingBase is ERC721TokenReceiver, IErrorsRegistries {
mapping (uint256 => ServiceInfo) public mapServiceInfo;
// Set of currently staking serviceIds
uint256[] public setServiceIds;
// Map of approved multisig proxy hashes
mapping(bytes32 => bool) public mapMultisigHashes;

/// @dev ServiceStakingBase constructor.
/// @param _stakingParams Service staking parameters.
/// @param _serviceRegistry ServiceRegistry contract address.
/// @param _multisigProxyHashes Multisig proxy hashes.
constructor(StakingParams memory _stakingParams, address _serviceRegistry, bytes32[] memory _multisigProxyHashes) {
/// @param _proxyHash Approved multisig proxy hash.
constructor(StakingParams memory _stakingParams, address _serviceRegistry, bytes32 _proxyHash) {
// Initial checks
if (_stakingParams.maxNumServices == 0 || _stakingParams.rewardsPerSecond == 0 ||
_stakingParams.livenessPeriod == 0 || _stakingParams.livenessRatio == 0 ||
Expand Down Expand Up @@ -201,23 +201,13 @@ abstract contract ServiceStakingBase is ERC721TokenReceiver, IErrorsRegistries {
agentIds.push(agentId);
}

// There must be at least one multisig proxy hash
uint256 size = _multisigProxyHashes.length;
if (size == 0) {
// Check for the multisig proxy bytecode hash value
if (_proxyHash == bytes32(0)) {
revert ZeroValue();
}

// Record provided multisig proxy bytecode hashes
for (uint256 i = 0; i < size; ++i) {
bytes32 proxyHash = _multisigProxyHashes[i];

// Check for the zero value
if (proxyHash == bytes32(0)) {
revert ZeroValue();
}

mapMultisigHashes[proxyHash] = true;
}
// Record provided multisig proxy bytecode hash
proxyHash = _proxyHash;

// Set the checkpoint timestamp to be the deployment one
tsCheckpoint = block.timestamp;
Expand Down Expand Up @@ -272,9 +262,9 @@ abstract contract ServiceStakingBase is ERC721TokenReceiver, IErrorsRegistries {
revert WrongServiceState(uint256(service.state), serviceId);
}

// Check that the multisig address corresponds to the authorized multisig proxy
bytes32 proxyHash = keccak256(service.multisig.code);
if (!mapMultisigHashes[proxyHash]) {
// Check that the multisig address corresponds to the authorized multisig proxy bytecode hash
bytes32 multisigProxyHash = keccak256(service.multisig.code);
if (proxyHash != multisigProxyHash) {
revert UnauthorizedMultisig(service.multisig);
}

Expand Down
Loading
Loading