Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
r0wdy1 committed Dec 14, 2023
1 parent 6ea2546 commit c0108de
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
5 changes: 0 additions & 5 deletions src/zkbob/manager/MPCWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,12 @@ contract MPCWrapper is Ownable, CustomABIDecoder {
vs := calldataload(add(32, offset))
offset := add(offset, 64)
}
console2.log("step", index);
console2.logBytes32(r);
console2.logBytes32(vs);
address signer = ECDSA.recover(
ECDSA.toEthSignedMessageHash(keccak256(_mpc_message())),
r,
vs
);
if (signer != signers[index]) {
console2.log("signer", signer);
console2.log("signers[index]", signers[index]);
return false;
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/zkbob/utils/CustomABIDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ contract CustomABIDecoder {
message.length := message_length
}

console2.log("_mpc_message");
console2.logBytes(message);
}

uint256 constant signatures_count_size = 1;
Expand Down
23 changes: 13 additions & 10 deletions test/zkbob/ZkBobPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import "../../src/zkbob/ZkBobPoolBOB.sol";
import "../../src/zkbob/ZkBobPoolETH.sol";
import "../../src/infra/UniswapV3Seller.sol";
import {EnergyRedeemer} from "../../src/infra/EnergyRedeemer.sol";
import "forge-std/console2.sol";

abstract contract AbstractZkBobPoolTest is AbstractForkTest {
address constant permit2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
Expand All @@ -56,12 +55,12 @@ abstract contract AbstractZkBobPoolTest is AbstractForkTest {
address token;
address weth;
address tempToken;
address wrapper;
bool autoApproveQueue;
PoolType poolType;
PermitType permitType;
uint256 denominator;
uint256 precision;
bool isMPC = false;

bytes constant zkAddress = "QsnTijXekjRm9hKcq5kLNPsa6P4HtMRrc3RxVx3jsLHeo2AiysYxVJP86mriHfN";

Expand Down Expand Up @@ -148,14 +147,18 @@ abstract contract AbstractZkBobPoolTest is AbstractForkTest {
0
);
pool.setAccounting(accounting);
address relayer = makeAddr("relayer");
wrapper = address(new MPCWrapper(relayer, address(pool)));
(address signer1Addr, uint256 signer1Key) = makeAddrAndKey("signer1");
(address signer2Addr, uint256 signer2Key) = makeAddrAndKey("signer2");
signers.push(signer1Addr);
signers.push(signer2Addr);
MPCWrapper(wrapper).setSigners(signers);
operatorManager = new MutableOperatorManager(wrapper, user3, "https://example.com");
address operatorEOA = makeAddr("operatorEOA");
if(isMPC) {
address operatorContract = address(new MPCWrapper(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);
} else {
operatorManager = new MutableOperatorManager(operatorEOA, user3, "https://example.com");
}
pool.setOperatorManager(operatorManager);
queue.setOperatorManager(operatorManager);
queue.setDirectDepositFee(uint64(0.1 ether / D));
Expand Down
46 changes: 25 additions & 21 deletions test/zkbob/manager/MPCWrapper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import "../ZkBobPool.t.sol";
import "../../shared/Env.t.sol";

import "../../shared/ForkTests.t.sol";
import "forge-std/console2.sol";

contract MPCOperatorManagerTest is
AbstractZkBobPoolTest,
AbstractPolygonForkTest
{
// address[] signers;

constructor() {
isMPC = true;
D = 1;
token = address(0xB0B195aEFA3650A6908f15CdaC7D92F8a5791B0B);
weth = address(0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270);
Expand All @@ -25,34 +23,40 @@ contract MPCOperatorManagerTest is
precision = 1_000_000_000;
}

function testTransact() public {
bytes memory data = _encodeDeposit(1 ether, 0.1 ether); //752
// data = abi.encodePacked(data, ); //753
(address signer1Addr, uint256 signer1Key) = makeAddrAndKey("signer1");
(address signer2Addr, uint256 signer2Key) = makeAddrAndKey("signer2");
data = abi.encodePacked(
data,
uint8(2),
sign(data, signer1Key),
sign(data, signer2Key)
);
console2.log("full data length", data.length);
console2.logBytes(data);
address operator = makeAddr("operator");
function testDepositMPC() public {
vm.prank(user1);
IERC20(token).approve(address(pool),1 ether);
bytes memory data = withMPC(_encodeDeposit(0.1 ether, 0.01 ether)); //752
_transactMPC(data);
}
function testPermitDepositMPC() public {
bytes memory data = withMPC(_encodePermitDeposit(0.1 ether, 0.01 ether)); //752
_transactMPC(data);
}

function _transactMPC(bytes memory data) internal {
address operator = makeAddr("operatorEOA");
address wrapper = operatorManager.operator();
vm.prank(operator);
(bool status, ) = address(wrapper).call(data);
require(status, "transact() reverted");
}

function withMPC(bytes memory data) internal returns (bytes memory){
(address signer1Addr, uint256 signer1Key) = makeAddrAndKey("signer1");
(address signer2Addr, uint256 signer2Key) = makeAddrAndKey("signer2");
return abi.encodePacked(
data,
uint8(2),//753
sign(data, signer1Key),//817
sign(data, signer2Key)//881
);
}
function sign(
bytes memory data,
uint256 key
) internal returns (bytes memory signatureData) {
console2.log("data being sigend");
console2.logBytes(data);
bytes32 digest = ECDSA.toEthSignedMessageHash(keccak256(data));
console2.log("digest");
console2.logBytes32(digest);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(key, digest);
signatureData = abi.encodePacked(
r,
Expand Down

0 comments on commit c0108de

Please sign in to comment.