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

perf: slither analysis #24

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
src = "src"
out = "out"
libs = ["lib"]
solc = "0.8.27"
solc = "0.8.20"

[fmt]
tab_width = 2
Expand Down
2 changes: 1 addition & 1 deletion script/MultiSigEnterpriseVault.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import {Script, console} from 'forge-std/Script.sol';
import {MultiSigEnterpriseVault} from '../src/MultiSigEnterpriseVault.sol';
Expand Down
2 changes: 1 addition & 1 deletion src/MultiSigEnterpriseVault.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import {MultiSigTransaction} from './components/MultiSigTransaction.sol';
import {AddressUtils} from './libraries/AddressUtils.sol';
Expand Down
6 changes: 3 additions & 3 deletions src/components/MultiSigTimelock.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import '../libraries/Counters.sol';
import {User} from './user/User.sol';
Expand Down Expand Up @@ -181,9 +181,9 @@ abstract contract MultiSigTimelock is User, IMultiSigTimelock {
) public validSigner validAction(actionId) pendingAction(actionId) {
Action storage action = _actions[actionId];
if (action.signatures.contains(_msgSender())) revert ActionNotApproved(actionId);
if (!action.signatures.add(_msgSender())) revert ActionNotApproved(actionId);

action.approvals.increment();
action.signatures.add(_msgSender());
emit ActionApproved(actionId, _msgSender(), block.timestamp);
}

Expand All @@ -196,9 +196,9 @@ abstract contract MultiSigTimelock is User, IMultiSigTimelock {
) public validSigner validAction(actionId) pendingAction(actionId) {
Action storage action = _actions[actionId];
if (!action.signatures.contains(_msgSender())) revert ActionNotApproved(actionId);
if (!action.signatures.remove(_msgSender())) revert ActionNotApproved(actionId);

action.approvals.decrement();
action.signatures.remove(_msgSender());
emit ActionRevoked(actionId, _msgSender(), block.timestamp);
}

Expand Down
15 changes: 8 additions & 7 deletions src/components/MultiSigTransaction.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import '../libraries/Counters.sol';
import '../libraries/AddressUtils.sol';
Expand Down Expand Up @@ -84,14 +84,15 @@ abstract contract MultiSigTransaction is MultiSigTimelock, IMultiSigTransaction
* @inheritdoc IMultiSigTransaction
*/
function depositToken(address token, uint256 amount) external payable nonReentrant {
uint256 allowance = IERC20(token).allowance(_msgSender(), address(this));
IERC20 erc20Token = IERC20(token);
uint256 allowance = erc20Token.allowance(_msgSender(), address(this));

if (allowance < amount) {
uint256 remainingAllowance = amount.subtract(allowance);
revert ERC20InsufficientAllowance(_msgSender(), allowance, remainingAllowance);
uint256 neededAllowance = amount.subtract(allowance);
revert ERC20InsufficientAllowance(_msgSender(), allowance, neededAllowance);
}

IERC20(token).transferFrom(_msgSender(), address(this), amount);
SafeERC20.safeTransferFrom(erc20Token, _msgSender(), address(this), amount);
emit FundsReceived(_msgSender(), token, amount);
}

Expand Down Expand Up @@ -141,9 +142,9 @@ abstract contract MultiSigTransaction is MultiSigTimelock, IMultiSigTransaction
) public validSigner validTransaction(txId) pendingTransaction(txId) {
Transaction storage txn = _transactions[txId];
if (txn.signatures.contains(_msgSender())) revert TransactionNotApproved(txId);
if (!txn.signatures.add(_msgSender())) revert TransactionNotApproved(txId);

txn.approvals.increment();
txn.signatures.add(_msgSender());
emit TransactionApproved(txId, _msgSender(), block.timestamp);
}

Expand All @@ -156,9 +157,9 @@ abstract contract MultiSigTransaction is MultiSigTimelock, IMultiSigTransaction
) public validSigner validTransaction(txId) pendingTransaction(txId) {
Transaction storage txn = _transactions[txId];
if (!txn.signatures.contains(_msgSender())) revert TransactionNotApproved(txId);
if (!txn.signatures.remove(_msgSender())) revert TransactionNotApproved(txId);

txn.approvals.decrement();
txn.signatures.remove(_msgSender());
emit TransactionRevoked(txId, _msgSender(), block.timestamp);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/user/User.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import '../../libraries/Counters.sol';
import '../../utilities/VaultConstants.sol';
Expand Down
2 changes: 1 addition & 1 deletion src/components/user/roles/ExecutorRole.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import {AccessControl} from '@openzeppelin/contracts/access/AccessControl.sol';
import {IExecutorRole} from '../../../interfaces/user/roles/IExecutorRole.sol';
Expand Down
14 changes: 7 additions & 7 deletions src/components/user/roles/OwnerRole.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import {AccessControl} from '@openzeppelin/contracts/access/AccessControl.sol';
import {IOwnerRole} from '../../../interfaces/user/roles/IOwnerRole.sol';
Expand All @@ -20,26 +20,26 @@ abstract contract OwnerRole is AccessControl, IOwnerRole {

/**
* @dev Initializes the Owner role and sets the initial owner override timelock.
* @param owner_ The address of the initial owner.
* @param initialOwner The address of the initial owner.
* @param initialOwnerOverrideTimelock The initial timelock value for owner override.
*/
constructor(address owner_, uint256 initialOwnerOverrideTimelock) {
AddressUtils.requireValidUserAddress(owner_);
constructor(address initialOwner, uint256 initialOwnerOverrideTimelock) {
AddressUtils.requireValidUserAddress(initialOwner);
if (initialOwnerOverrideTimelock <= 0) {
revert InvalidOwnerOverrideTimelockValue(initialOwnerOverrideTimelock);
}

// Grant DEFAULT_ADMIN_ROLE to the owner
_grantRole(DEFAULT_ADMIN_ROLE, owner_);
_grantRole(DEFAULT_ADMIN_ROLE, initialOwner);

// Now change the admin role of DEFAULT_ADMIN_ROLE to OWNER_ROLE
_setRoleAdmin(DEFAULT_ADMIN_ROLE, OWNER_ROLE);

// Grant OWNER_ROLE to the owner
_grantRole(OWNER_ROLE, owner_);
_grantRole(OWNER_ROLE, initialOwner);

ownerOverrideTimelock = initialOwnerOverrideTimelock;
_owner = owner_;
_owner = initialOwner;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/components/user/roles/SignerRole.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import {EnumerableSet} from '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';
import {AccessControl} from '@openzeppelin/contracts/access/AccessControl.sol';
Expand Down Expand Up @@ -83,9 +83,9 @@ abstract contract SignerRole is AccessControl, ISignerRole {
) internal virtual validExecutor {
_validateSignerAddress(newSigner);
if (isSigner(newSigner)) revert SignerAlreadyExists(newSigner);
if (!_signers.add(newSigner)) revert SignerAlreadyExists(newSigner);

_grantRole(SIGNER_ROLE, newSigner);
_signers.add(newSigner);
_signerCount.increment();
emit SignerAdded(newSigner);
}
Expand All @@ -99,9 +99,9 @@ abstract contract SignerRole is AccessControl, ISignerRole {
address signer
) internal virtual validExecutor {
if (!isSigner(signer)) revert SignerDoesNotExist(signer);
if (!_signers.remove(signer)) revert SignerDoesNotExist(signer);

_revokeRole(SIGNER_ROLE, signer);
_signers.remove(signer);
_signerCount.decrement();
emit SignerRemoved(signer);
}
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IMultiSigTimelock.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import {ActionType} from '../utilities/VaultEnums.sol';

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IMultiSigTransaction.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

/**
* @title IMultiSigTransaction Interface
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/user/IUser.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

/**
* @title IUser Interface
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/user/roles/IExecutorRole.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

/**
* @title IExecutorRole Interface
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/user/roles/IOwnerRole.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

/**
* @title IOwnerRole Interface
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/user/roles/ISignerRole.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

/**
* @title ISignerRole Interface
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/AddressUtils.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import '@openzeppelin/contracts/utils/Address.sol';

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Counters.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import './SafeMath.sol';

Expand Down
2 changes: 1 addition & 1 deletion src/libraries/SafeMath.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

/**
* @title SafeMath Library
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/VaultConstants.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

/// @dev Role identifier for the Owner role in bytes32
bytes32 constant OWNER_ROLE = keccak256('RoleType.OWNER');
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/VaultEnums.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

/**
* @title Vault RoleType Enum
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/VaultStructs.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';
import '../libraries/Counters.sol';
Expand Down
2 changes: 1 addition & 1 deletion test/MultiSigEnterpriseVault.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import {Test, console} from 'forge-std/Test.sol';
import {MultiSigEnterpriseVault} from '../src/MultiSigEnterpriseVault.sol';
Expand Down
2 changes: 1 addition & 1 deletion test/components/BaseMultiSigTest.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import '../MultiSigEnterpriseVault.t.sol';

Expand Down
6 changes: 2 additions & 4 deletions test/components/MultiSigFuzzTest.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {Address} from '@openzeppelin/contracts/utils/Address.sol';
Expand Down Expand Up @@ -61,9 +61,7 @@ contract MultiSigFuzzTest is BaseMultiSigTest {
&& recipient != vaultExecutor && recipient != vaultAddress
);

vm.deal(vaultOwner, 100 ether);
vm.prank(vaultOwner);
Address.sendValue(payable(vaultAddress), 10 ether);
vm.deal(vaultAddress, 100 ether);
uint256 initialRecipientBalance = recipient.balance;
uint256 initialVaultBalance = vaultAddress.balance;

Expand Down
2 changes: 1 addition & 1 deletion test/components/MultiSigTimelockTest.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import {ActionType} from '../../src/utilities/VaultEnums.sol';
import './BaseMultiSigTest.t.sol';
Expand Down
2 changes: 1 addition & 1 deletion test/components/MultiSigTransactionTest.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {Address} from '@openzeppelin/contracts/utils/Address.sol';
Expand Down
2 changes: 1 addition & 1 deletion test/components/roles/ExecutorRoleTest.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import '../../MultiSigEnterpriseVault.t.sol';
import {RoleType} from '../../../src/utilities/VaultEnums.sol';
Expand Down
2 changes: 1 addition & 1 deletion test/components/roles/OwnerRoleTest.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import '../../MultiSigEnterpriseVault.t.sol';
import {RoleType} from '../../../src/utilities/VaultEnums.sol';
Expand Down
2 changes: 1 addition & 1 deletion test/components/roles/SignerRoleTest.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import '../../MultiSigEnterpriseVault.t.sol';

Expand Down
2 changes: 1 addition & 1 deletion test/mocks/MockERC20Token.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.27;
pragma solidity ^0.8.20;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

Expand Down