Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
AllFi committed Jan 4, 2024
1 parent 266c118 commit ec8b5c1
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 98 deletions.
8 changes: 6 additions & 2 deletions script/scripts/DeployZkBobPoolModules.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ contract DeployZkBobPoolModules is Script, Test {
vm.startBroadcast();

ZkBobPoolUSDC impl = new ZkBobPoolUSDC(
pool.pool_id(), pool.token(), pool.transfer_verifier(), pool.tree_verifier(),
pool.batch_deposit_verifier(), address(pool.direct_deposit_queue())
pool.pool_id(),
pool.token(),
pool.transfer_verifier(),
pool.tree_verifier(),
pool.batch_deposit_verifier(),
address(pool.direct_deposit_queue())
);
Migrator mig = new Migrator();
ZkBobAccounting acc = new ZkBobAccounting(address(pool), 1_000_000_000);
Expand Down
7 changes: 1 addition & 6 deletions script/scripts/Local.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ contract DeployLocal is Script {
EIP1967Proxy queueProxy = new EIP1967Proxy(tx.origin, mockImpl, "");

ZkBobPoolBOB poolImpl = new ZkBobPoolBOB(
zkBobPoolId,
address(bob),
transferVerifier,
treeVerifier,
batchDepositVerifier,
address(queueProxy)
zkBobPoolId, address(bob), transferVerifier, treeVerifier, batchDepositVerifier, address(queueProxy)
);
{
bytes memory initData = abi.encodeWithSelector(ZkBobPool.initialize.selector, zkBobInitialRoot);
Expand Down
28 changes: 16 additions & 12 deletions script/scripts/ZkBobPool.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,31 @@ contract DeployZkBobPool is Script {

if (zkBobPoolType == PoolType.ETH) {
vars.poolImpl = new ZkBobPoolETH(
zkBobPoolId, zkBobToken,
transferVerifier, treeVerifier, batchDepositVerifier,
address(vars.queueProxy), permit2
zkBobPoolId,
zkBobToken,
transferVerifier,
treeVerifier,
batchDepositVerifier,
address(vars.queueProxy),
permit2
);
} else if (zkBobPoolType == PoolType.BOB) {
vars.poolImpl = new ZkBobPoolBOB(
zkBobPoolId, zkBobToken,
transferVerifier, treeVerifier, batchDepositVerifier,
address(vars.queueProxy)
zkBobPoolId, zkBobToken, transferVerifier, treeVerifier, batchDepositVerifier, address(vars.queueProxy)
);
} else if (zkBobPoolType == PoolType.USDC) {
vars.poolImpl = new ZkBobPoolUSDC(
zkBobPoolId, zkBobToken,
transferVerifier, treeVerifier, batchDepositVerifier,
address(vars.queueProxy)
zkBobPoolId, zkBobToken, transferVerifier, treeVerifier, batchDepositVerifier, address(vars.queueProxy)
);
} else if (zkBobPoolType == PoolType.ERC20) {
vars.poolImpl = new ZkBobPoolERC20(
zkBobPoolId, zkBobToken,
transferVerifier, treeVerifier, batchDepositVerifier,
address(vars.queueProxy), permit2,
zkBobPoolId,
zkBobToken,
transferVerifier,
treeVerifier,
batchDepositVerifier,
address(vars.queueProxy),
permit2,
vars.denominator
);
} else {
Expand Down
13 changes: 4 additions & 9 deletions test/libraries/PriorityQueue.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract PriorityQueueTest is Test {
assertEq(0, ops.length);
}

function testPushBackPopFront() external {
function testPushBackPopFront() external {
for (uint256 i = 0; i < 100; i++) {
_queue.pushBack(_newOp(i));

Expand All @@ -48,19 +48,14 @@ contract PriorityQueueTest is Test {
}
}

function _newOp(
uint256 id
) internal pure returns (PendingCommitment memory) {
function _newOp(uint256 id) internal pure returns (PendingCommitment memory) {
address prover = address(uint160(uint256(keccak256(abi.encodePacked("prover", id)))));
uint64 fee = uint64(uint256(keccak256(abi.encodePacked("fee", id))));
uint64 timestamp = uint64(uint256(keccak256(abi.encodePacked("timestamp", id))));
return PendingCommitment(id, prover, fee, timestamp);
}

function _verifyOp(
uint256 id,
PendingCommitment memory op
) internal {
function _verifyOp(uint256 id, PendingCommitment memory op) internal {
address prover = address(uint160(uint256(keccak256(abi.encodePacked("prover", id)))));
uint64 fee = uint64(uint256(keccak256(abi.encodePacked("fee", id))));
uint64 timestamp = uint64(uint256(keccak256(abi.encodePacked("timestamp", id))));
Expand Down Expand Up @@ -110,4 +105,4 @@ contract DummyQueue {
function popFront() external returns (PendingCommitment memory pendingCommitments) {
return PriorityQueue.popFront(_queue);
}
}
}
142 changes: 99 additions & 43 deletions test/zkbob/ZkBobPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,42 @@ abstract contract AbstractZkBobPoolTestBase is AbstractForkTest {
ZkBobPool impl;
if (poolType == PoolType.ETH) {
impl = new ZkBobPoolETH(
0, token,
new TransferVerifierMock(), new TreeUpdateVerifierMock(), new BatchDepositVerifierMock(),
address(queueProxy), permit2
0,
token,
new TransferVerifierMock(),
new TreeUpdateVerifierMock(),
new BatchDepositVerifierMock(),
address(queueProxy),
permit2
);
} else if (poolType == PoolType.BOB) {
impl = new ZkBobPoolBOB(
0, token,
new TransferVerifierMock(), new TreeUpdateVerifierMock(), new BatchDepositVerifierMock(),
0,
token,
new TransferVerifierMock(),
new TreeUpdateVerifierMock(),
new BatchDepositVerifierMock(),
address(queueProxy)
);
} else if (poolType == PoolType.USDC) {
impl = new ZkBobPoolUSDC(
0, token,
new TransferVerifierMock(), new TreeUpdateVerifierMock(), new BatchDepositVerifierMock(),
0,
token,
new TransferVerifierMock(),
new TreeUpdateVerifierMock(),
new BatchDepositVerifierMock(),
address(queueProxy)
);
} else if (poolType == PoolType.ERC20) {
impl = new ZkBobPoolERC20(
0, token,
new TransferVerifierMock(), new TreeUpdateVerifierMock(), new BatchDepositVerifierMock(),
address(queueProxy), permit2, 1_000_000_000
0,
token,
new TransferVerifierMock(),
new TreeUpdateVerifierMock(),
new BatchDepositVerifierMock(),
address(queueProxy),
permit2,
1_000_000_000
);
}

Expand Down Expand Up @@ -187,7 +202,16 @@ abstract contract AbstractZkBobPoolTestBase is AbstractForkTest {
}
}

function _encodeDeposit(int256 _amount, uint256 _transactFee, uint256 _treeUpdateFee, address prover) internal view returns (bytes memory) {
function _encodeDeposit(
int256 _amount,
uint256 _transactFee,
uint256 _treeUpdateFee,
address prover
)
internal
view
returns (bytes memory)
{
bytes32 nullifier = bytes32(_randFR());
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk1, ECDSA.toEthSignedMessageHash(nullifier));
bytes memory data = abi.encodePacked(
Expand All @@ -202,13 +226,13 @@ abstract contract AbstractZkBobPoolTestBase is AbstractForkTest {
data = abi.encodePacked(data, _randFR());
}
data = abi.encodePacked(
data,
uint16(0),
uint16(72),
prover,
uint64(_transactFee / denominator),
uint64(_treeUpdateFee / denominator),
bytes4(0x01000000),
data,
uint16(0),
uint16(72),
prover,
uint64(_transactFee / denominator),
uint64(_treeUpdateFee / denominator),
bytes4(0x01000000),
_randFR()
);
return abi.encodePacked(data, r, uint256(s) + (v == 28 ? (1 << 255) : 0));
Expand Down Expand Up @@ -237,11 +261,7 @@ abstract contract AbstractZkBobPoolTestBase is AbstractForkTest {
data = abi.encodePacked(data, _randFR());
}

data = abi.encodePacked(
data,
uint16(2),
uint16(100)
);
data = abi.encodePacked(data, uint16(2), uint16(100));

return abi.encodePacked(
data,
Expand All @@ -255,21 +275,34 @@ abstract contract AbstractZkBobPoolTestBase is AbstractForkTest {
);
}

function _encodeTransfer(uint256 _transactFee, uint256 _treeUpdateFee, address prover) internal view returns (bytes memory) {
function _encodeTransfer(
uint256 _transactFee,
uint256 _treeUpdateFee,
address prover
)
internal
view
returns (bytes memory)
{
bytes memory data = abi.encodePacked(
ZkBobPool.transact.selector, _randFR(), _randFR(), uint48(0), uint112(0), -int64(uint64((_transactFee + _treeUpdateFee) / denominator))
ZkBobPool.transact.selector,
_randFR(),
_randFR(),
uint48(0),
uint112(0),
-int64(uint64((_transactFee + _treeUpdateFee) / denominator))
);
for (uint256 i = 0; i < 8; i++) {
data = abi.encodePacked(data, _randFR());
}
return abi.encodePacked(
data,
uint16(1),
data,
uint16(1),
uint16(72),
prover,
uint64(_transactFee / denominator),
uint64(_treeUpdateFee / denominator),
bytes4(0x01000000),
prover,
uint64(_transactFee / denominator),
uint64(_treeUpdateFee / denominator),
bytes4(0x01000000),
_randFR()
);
}
Expand All @@ -282,7 +315,7 @@ abstract contract AbstractZkBobPoolTestBase is AbstractForkTest {

function _proveTreeUpdate() internal {
vm.startPrank(user2);
(uint256 commitment, , , ) = pool.pendingCommitment();
(uint256 commitment,,,) = pool.pendingCommitment();
pool.proveTreeUpdate(commitment, _randProof(), _randFR());
vm.stopPrank();
}
Expand All @@ -303,7 +336,15 @@ abstract contract AbstractZkBobPoolTestBase is AbstractForkTest {
return [_randFR(), _randFR(), _randFR(), _randFR(), _randFR(), _randFR(), _randFR(), _randFR()];
}

function _encodePermitDeposit(int256 _amount, uint256 _transactFee, uint256 _treeUpdateFee, address prover) internal returns (bytes memory) {
function _encodePermitDeposit(
int256 _amount,
uint256 _transactFee,
uint256 _treeUpdateFee,
address prover
)
internal
returns (bytes memory)
{
if (permitType == PermitType.Permit2) {
vm.prank(user1);
IERC20(token).approve(permit2, type(uint256).max);
Expand All @@ -316,11 +357,29 @@ abstract contract AbstractZkBobPoolTestBase is AbstractForkTest {
{
bytes32 digest;
if (permitType == PermitType.BOBPermit) {
digest = _digestSaltedPermit(user1, address(pool), uint256(_amount + int256(_transactFee) + int256(_treeUpdateFee)), expiry, nullifier);
digest = _digestSaltedPermit(
user1,
address(pool),
uint256(_amount + int256(_transactFee) + int256(_treeUpdateFee)),
expiry,
nullifier
);
} else if (permitType == PermitType.Permit2) {
digest = _digestPermit2(user1, address(pool), uint256(_amount + int256(_transactFee) + int256(_treeUpdateFee)), expiry, nullifier);
digest = _digestPermit2(
user1,
address(pool),
uint256(_amount + int256(_transactFee) + int256(_treeUpdateFee)),
expiry,
nullifier
);
} else if (permitType == PermitType.USDCPermit) {
digest = _digestUSDCPermit(user1, address(pool), uint256(_amount + int256(_transactFee) + int256(_treeUpdateFee)), expiry, nullifier);
digest = _digestUSDCPermit(
user1,
address(pool),
uint256(_amount + int256(_transactFee) + int256(_treeUpdateFee)),
expiry,
nullifier
);
}
(uint8 v, bytes32 r, bytes32 s) = vm.sign(pk1, digest);
signature = abi.encodePacked(r, uint256(s) + (v == 28 ? (1 << 255) : 0));
Expand All @@ -338,11 +397,7 @@ abstract contract AbstractZkBobPoolTestBase is AbstractForkTest {
data = abi.encodePacked(data, _randFR());
}

data = abi.encodePacked(
data,
uint16(3),
uint16(100)
);
data = abi.encodePacked(data, uint16(3), uint16(100));

data = abi.encodePacked(
data,
Expand Down Expand Up @@ -433,7 +488,6 @@ abstract contract AbstractZkBobPoolTestBase is AbstractForkTest {
}

abstract contract AbstractZkBobPoolTest is AbstractZkBobPoolTestBase {

function setUp() public override {
super.setUp();
}
Expand Down Expand Up @@ -555,7 +609,9 @@ abstract contract AbstractZkBobPoolTest is AbstractZkBobPoolTestBase {
function testMultiplePermitDeposits() public {
for (uint256 i = 1; i < 10; i++) {
deal(address(token), user1, 0.101 ether / D * i);
bytes memory data = _encodePermitDeposit(int256(0.1 ether / D) * int256(i), 0.0005 ether / D * i, 0.0005 ether / D * i, user2);
bytes memory data = _encodePermitDeposit(
int256(0.1 ether / D) * int256(i), 0.0005 ether / D * i, 0.0005 ether / D * i, user2
);
_transact(data);
_proveTreeUpdate();
}
Expand Down
Loading

0 comments on commit ec8b5c1

Please sign in to comment.