From 25d442bf6f254c99d9b46660469cdc22c47d88ef Mon Sep 17 00:00:00 2001 From: vladimir Date: Fri, 15 Dec 2023 13:48:28 +0400 Subject: [PATCH] fixes --- .../manager/{MPCWrapper.sol => MPCGuard.sol} | 27 ++++++++++--------- test/zkbob/ZkBobPool.t.sol | 16 +++++------ .../{MPCWrapper.t.sol => MPCGuard.t.sol} | 21 +++++++-------- 3 files changed, 32 insertions(+), 32 deletions(-) rename src/zkbob/manager/{MPCWrapper.sol => MPCGuard.sol} (84%) rename test/zkbob/manager/{MPCWrapper.t.sol => MPCGuard.t.sol} (88%) diff --git a/src/zkbob/manager/MPCWrapper.sol b/src/zkbob/manager/MPCGuard.sol similarity index 84% rename from src/zkbob/manager/MPCWrapper.sol rename to src/zkbob/manager/MPCGuard.sol index 0469f01..41a62ff 100644 --- a/src/zkbob/manager/MPCWrapper.sol +++ b/src/zkbob/manager/MPCGuard.sol @@ -5,13 +5,16 @@ import "../utils/CustomABIDecoder.sol"; import "../../interfaces/IZkBobPool.sol"; -contract MPCWrapper is Ownable, CustomABIDecoder { - address[] private signers; +contract MPCGuard is Ownable, CustomABIDecoder { + + address[] private guards; address operator; address public immutable pool; + uint256 constant SIGNATURE_SIZE = 64; + constructor(address _operator, address _pool) { pool = _pool; _setOperator(_operator); @@ -33,31 +36,30 @@ contract MPCWrapper is Ownable, CustomABIDecoder { _setOperator(_operator); } - function setSigners(address[] calldata _signers) external onlyOwner { - signers = _signers; + function setGuards(address[] calldata _guards) external onlyOwner { + guards = _guards; } modifier calldataVerified() { (uint8 count, bytes calldata signatures) = _mpc_signatures(); - require(count == signers.length, "MPCWrapper: wrong quorum"); + require(count == guards.length, "MPCWrapper: wrong quorum"); bytes32 digest = ECDSA.toEthSignedMessageHash( keccak256(_mpc_message()) ); - require(checkQuorum(count, signatures, digest)); + require(checkQuorum(signatures, digest)); _; } function checkQuorum( - uint8 count, bytes calldata signatures, bytes32 _digest - ) internal returns (bool) { + ) internal view returns (bool) { uint256 offset = 0; assembly { offset := signatures.offset } - for (uint256 index = 0; index < signers.length; index++) { + for (uint256 index = 0; index < guards.length; index++) { bytes32 r; bytes32 vs; assembly { @@ -66,7 +68,7 @@ contract MPCWrapper is Ownable, CustomABIDecoder { offset := add(offset, 64) } address signer = ECDSA.recover(_digest, r, vs); - if (signer != signers[index]) { + if (signer != guards[index]) { return false; } } @@ -87,10 +89,9 @@ contract MPCWrapper is Ownable, CustomABIDecoder { uint256 _out_commit, uint256[8] calldata _batch_deposit_proof, uint256[8] memory _tree_proof, - uint8 mpc_count, bytes calldata signatures ) external { - require(mpc_count == signers.length, "MPCWrapper: wrong quorum"); + require(signatures.length == guards.length * SIGNATURE_SIZE, "MPCWrapper: wrong quorum"); bytes memory mpc_message = abi.encodePacked( _root_after, @@ -102,7 +103,7 @@ contract MPCWrapper is Ownable, CustomABIDecoder { bytes32 digest = ECDSA.toEthSignedMessageHash(keccak256(mpc_message)); - require(checkQuorum(mpc_count, signatures, digest)); + require(checkQuorum(signatures, digest)); IZkBobPool(pool).appendDirectDeposits( _root_after, _indices, diff --git a/test/zkbob/ZkBobPool.t.sol b/test/zkbob/ZkBobPool.t.sol index 6048257..0ea7041 100644 --- a/test/zkbob/ZkBobPool.t.sol +++ b/test/zkbob/ZkBobPool.t.sol @@ -17,7 +17,7 @@ import "../mocks/DummyImpl.sol"; import "../../src/proxy/EIP1967Proxy.sol"; import "../../src/zkbob/ZkBobPool.sol"; import "../../src/zkbob/ZkBobDirectDepositQueue.sol"; -import "../../src/zkbob/manager/MPCWrapper.sol"; +import "../../src/zkbob/manager/MPCGuard.sol"; import "../../src/zkbob/manager/MutableOperatorManager.sol"; import "../../src/zkbob/manager/kyc/SimpleKYCProviderManager.sol"; import "../interfaces/IZkBobDirectDepositsAdmin.sol"; @@ -147,15 +147,15 @@ abstract contract AbstractZkBobPoolTest is AbstractForkTest { 0 ); pool.setAccounting(accounting); - address operatorEOA = makeAddr("operatorEOA"); if(isMPC) { - address operatorContract = address(new MPCWrapper(operatorEOA, address(pool))); + address operatorEOA = makeAddr("operatorEOA"); + address operatorContract = address(new MPCGuard(operatorEOA, address(pool))); operatorManager = new MutableOperatorManager(operatorContract, user3, "https://example.com"); - (address signer1Addr, uint256 signer1Key) = makeAddrAndKey("signer1"); - (address signer2Addr, uint256 signer2Key) = makeAddrAndKey("signer2"); - signers.push(signer1Addr); - signers.push(signer2Addr); - MPCWrapper(operatorContract).setSigners(signers); + (address guard1Addr, ) = makeAddrAndKey("guard1"); + (address guard2Addr, ) = makeAddrAndKey("guard2"); + signers.push(guard1Addr); + signers.push(guard2Addr); + MPCGuard(operatorContract).setGuards(signers); } else { operatorManager = new MutableOperatorManager(user2, user3, "https://example.com"); } diff --git a/test/zkbob/manager/MPCWrapper.t.sol b/test/zkbob/manager/MPCGuard.t.sol similarity index 88% rename from test/zkbob/manager/MPCWrapper.t.sol rename to test/zkbob/manager/MPCGuard.t.sol index 3b32642..e017028 100644 --- a/test/zkbob/manager/MPCWrapper.t.sol +++ b/test/zkbob/manager/MPCGuard.t.sol @@ -6,7 +6,7 @@ import "../../shared/Env.t.sol"; import "../../shared/ForkTests.t.sol"; -import "../../../src/zkbob/manager/MPCWrapper.sol"; +import "../../../src/zkbob/manager/MPCGuard.sol"; contract MPCOperatorManagerTest is AbstractZkBobPoolTest, @@ -48,14 +48,14 @@ contract MPCOperatorManagerTest is } function withMPC(bytes memory data) internal returns (bytes memory) { - (address signer1Addr, uint256 signer1Key) = makeAddrAndKey("signer1"); - (address signer2Addr, uint256 signer2Key) = makeAddrAndKey("signer2"); + (address guard1Addr, uint256 guard1Key) = makeAddrAndKey("guard1"); + (address guard2Addr, uint256 guard2Key) = makeAddrAndKey("guard2"); return abi.encodePacked( data, uint8(2), //753 - sign(data, signer1Key), //817 - sign(data, signer2Key) //881 + sign(data, guard1Key), //817 + sign(data, guard2Key) //881 ); } @@ -127,18 +127,17 @@ contract MPCOperatorManagerTest is tree_proof ); - (, uint256 signer1Key) = makeAddrAndKey("signer1"); - (, uint256 signer2Key) = makeAddrAndKey("signer2"); + (, uint256 guard1Key) = makeAddrAndKey("guard1"); + (, uint256 guard2Key) = makeAddrAndKey("guard2"); - MPCWrapper(wrapper).appendDirectDepositsMPC( + MPCGuard(wrapper).appendDirectDepositsMPC( root_afer, indices, outCommitment, batch_deposit_proof, tree_proof, - 2, - abi.encodePacked(sign(mpcMessage, signer1Key), sign(mpcMessage, signer2Key)) + abi.encodePacked(sign(mpcMessage, guard1Key), sign(mpcMessage, guard2Key)) ); } @@ -146,7 +145,7 @@ contract MPCOperatorManagerTest is function sign( bytes memory data, uint256 key - ) internal returns (bytes memory signatureData) { + ) internal pure returns (bytes memory signatureData) { bytes32 digest = ECDSA.toEthSignedMessageHash(keccak256(data)); (uint8 v, bytes32 r, bytes32 s) = vm.sign(key, digest);