A secure and gas-optimized implementation of a multisignature wallet smart contract built with Solidity and Foundry.
- Multiple signers (minimum 3)
- Configurable confirmation threshold (minimum 2)
- Transaction submission and execution
- Signer management (add/remove)
- No external dependencies
- 100% test coverage
- Gas optimized
- Foundry
- Solidity 0.8.28
- Git
- Clone the repository:
git clone <repository-url>
cd multisig-wallet
- Install dependencies:
forge install
- Build the project:
forge build
Run the test suite:
forge test
Run tests with coverage report:
forge coverage
Run tests with gas report:
forge test --gas-report
- Set up your environment variables:
cp .env.example .env
# Edit .env with your configuration
- Deploy using Foundry script:
# Local deployment
forge script script/Deploy.s.sol:DeployLocal --broadcast --verify
# Mainnet deployment
forge script script/Deploy.s.sol:DeployMainnet --rpc-url $MAINNET_RPC_URL --broadcast --verify
# Testnet deployment
forge script script/Deploy.s.sol:DeployGoerli --rpc-url $GOERLI_RPC_URL --broadcast --verify
constructor(address[] memory _initialSigners, uint256 _requiredConfirmations)
_initialSigners
: Array of initial signer addresses (minimum 3)_requiredConfirmations
: Number of required confirmations (minimum 2)
- Transaction Management:
function submitTransaction(address to, uint256 value, bytes calldata data) external returns (uint256 txId)
function confirmTransaction(uint256 txId) external
function revokeConfirmation(uint256 txId) external
function executeTransaction(uint256 txId) external
- Signer Management:
function addSigner(address newSigner) external
function removeSigner(address signer) external
- View Functions:
function getSignerCount() external view returns (uint256)
function isSigner(address account) external view returns (bool)
function getConfirmationCount(uint256 txId) external view returns (uint256)
function isConfirmed(uint256 txId, address signer) external view returns (bool)
-
Input Validation:
- Zero address checks
- Signer count validations
- Confirmation threshold checks
-
Access Control:
- Only signers can submit/confirm transactions
- Only signers can manage other signers
- Minimum signer requirement enforced
-
Security Features:
- Reentrancy protection
- Check-Effects-Interactions pattern
- Events for transparency
- Custom errors for gas efficiency
The contract implements several gas optimization techniques:
- Custom errors instead of revert strings
- Minimal storage operations
- Efficient data structures
- Unchecked math where safe
- Proper validation order
├── src/
│ ├── MultisigWallet.sol # Main contract
│ └── interfaces/
│ └── IMultisigWallet.sol # Interface
├── test/
│ ├── MultisigWallet.t.sol # Tests
│ └── helpers/
│ └── RevertingContract.sol # Test helper
├── script/
│ └── Deploy.s.sol # Deployment scripts
└── foundry.toml # Foundry configuration
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.