多签验证问题

pragma solidity ^0.8.2;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";

contract Pool is Ownable {

    address[] public singOwners;

    event IsValidSignatureNow(address indexed owner, bytes32 hash, bytes signature, bool bo);

    //验证多签 signature的顺序需要保证和singOwners一致
    function multipleSignatures(bytes32 _root, bytes[] calldata signature)
    external
    onlyOwner
    {
        for (uint256 i = 0; i < singOwners.length; i++) {
            bool b = _isValidSignatureNow(singOwners[i], _root, signature[i]);
            require(b, "Signature failed");
        }
    }

    //验证多签
    function _isValidSignatureNow(
        address signer,
        bytes32 hash,
        bytes calldata signature
    ) private returns (bool){

        bool bo = SignatureChecker.isValidSignatureNow(signer, hash, signature);
        emit IsValidSignatureNow(signer, hash, signature, bo);
        return bo;
    }

    //添加多签地址
    function addSingOwners(address[] memory _owners)
    external
    onlyOwner {
        require(_owners.length > 0, "owners require");
        for (uint i; i < _owners.length; i++) {
            address owner = _owners[i];

            require(owner != address(0), "Cannot be 0 address");
            singOwners.push(owner);
        }
    }
}

我写了一个多签的功能。效果可以达到多签的效果,但是不知道这样写是否合理。哪位大佬指点一下。

请先 登录 后评论

1 个回答

Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
  • 1 关注
  • 0 收藏,2196 浏览
  • 天才威 提出于 2023-01-12 18:24