Skip to content
Verified contractExactMIT

SimpleMultiSig

Address0x9cbdbd7fa768ad6e9546ff57238722fa9b925329
Balance

10,500.227084 ETH

 

Transactions

9,123

 

Compiler

solc 0.8.28

 

Same code

6 more contracts

 

Details

Compiler
solc 0.8.28+commit.7893614a
Language
solidity
Optimization
No
EVM version
cancun
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
21,846,094
Creation transaction
0x950b33ed3d…0195978700

source/SimpleMultiSig-v2.0.1.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

contract SimpleMultiSig {
    // EIP712 Precomputed hashes:
    // keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract,bytes32 salt)")
    bytes32 constant EIP712DOMAINTYPE_HASH = 0xd87cd6ef79d4e2b95e15ce8abf732db51ec771f1ca2edccf22a46c729ac56472;

    // keccak256("Simple MultiSig")
    bytes32 constant NAME_HASH = 0xb7a0bfa1b79f2443f4d73ebb9259cddbcd510b18be6fc4da7d1aa7b1786e73e6;

    // keccak256("1")
    bytes32 constant VERSION_HASH = 0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6;

    // keccak256("MultiSigTransaction(address destination,uint256 value,bytes data,uint256 nonce,address executor,uint256 gasLimit)")
    bytes32 constant TXTYPE_HASH = 0x3ee892349ae4bbe61dce18f95115b5dc02daf49204cc602458cd4c1f540d56d7;

    bytes32 constant SALT = 0x251543af6a222378665a76fe38dbceae4871a070b7fdaf5c6c30cf758dc33cc0;

    uint256 public nonce;                 // (only) mutable state
    uint256 public threshold;             // immutable state
    mapping(address => bool) public isOwner; // immutable state
    address[] public ownersArr;           // immutable state

    event EthDeposit(address indexed from, address indexed to, uint256 value);
    event Execute(address indexed from, address indexed to, uint256 value, bytes data);

    error InvalidOwners();
    error InvalidThreshold();
    error OwnersNotInIncreasingOrder();
    error HighSValue();
    error InsufficientSignatures();
    error InvalidSignature();
    error SignerNotOwner();
    error MismatchedSignatureComponents();
    error InvalidExecutor();
    error NestedTransactionFailed();

    // Owners must be strictly increasing to prevent duplicates
    constructor(uint256 threshold_, address[] memory owners_) {
        if (owners_.length == 0 || owners_.length > 10) {
            revert InvalidOwners();
        }
        if (threshold_ < owners_.length / 2 || threshold_ > owners_.length) {
            revert InvalidThreshold();
        }

        address lastAdd = address(0);
        for (uint256 i = 0; i < owners_.length; i++) {
            if (owners_[i] <= lastAdd) {
                revert OwnersNotInIncreasingOrder();
            }
            isOwner[owners_[i]] = true;
            lastAdd = owners_[i];
        }
        ownersArr = owners_;
        threshold = threshold_;
    }

    function validateSignatures(
        bytes32 totalHash,
        uint8[] calldata sigV,
        bytes32[] calldata sigR,
        bytes32[] calldata sigS
    ) internal view {
        address lastAdd = address(0); // Cannot have address(0) as an owner
        for (uint256 i = 0; i < sigR.length; i++) {
            if (uint256(sigS[i]) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
                revert HighSValue();
            }
            address recovered = ecrecover(totalHash, sigV[i], sigR[i], sigS[i]);
            if (recovered <= lastAdd) {
                revert InvalidSignature();
            }
            if (!isOwner[recovered]) {
                revert SignerNotOwner();
            }
            lastAdd = recovered;
        }
    }

    function execute(
        uint8[] calldata sigV,
        bytes32[] calldata sigR,
        bytes32[] calldata sigS,
        address destination,
        uint256 value,
        bytes calldata data,
        address executor,
        uint256 gasLimit
    ) external {
        if (sigR.length < threshold) {
            revert InsufficientSignatures();
        }
        if (sigR.length != sigS.length || sigR.length != sigV.length) {
            revert MismatchedSignatureComponents();
        }
        if (executor != msg.sender && executor != address(0)) {
            revert InvalidExecutor();
        }

        // EIP-712 suggests that the domain separator should be recomputed when necessary to ensure it's always consistent with the current chain context.
        bytes32 domainSeparator = keccak256(
            abi.encode(
                EIP712DOMAINTYPE_HASH,
                NAME_HASH,
                VERSION_HASH,
                block.chainid,
                address(this),
                SALT
            )
        );
        bytes32 txInputHash = keccak256(abi.encode(TXTYPE_HASH, destination, value, keccak256(data), nonce, executor, gasLimit));
        bytes32 totalHash = keccak256(abi.encodePacked("\x19\x01", domainSeparator, txInputHash));

        validateSignatures(totalHash, sigV, sigR, sigS);

        nonce++;
        (bool success,) = destination.call{value: value, gas: gasLimit}(data);
        if (!success) {
            revert NestedTransactionFailed();
        }
        emit Execute(address(this), destination, value, data);
    }

    receive() external payable {
        emit EthDeposit(msg.sender, address(this), msg.value);
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "evmVersion": "cancun",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.