Skip to content

Commit

Permalink
Decentralized prover (#97)
Browse files Browse the repository at this point in the history
* Move tree update in a separate function

* Add grace period

* Refactor code, add tests

* adds tests for dd

* Fix message event, add comments

* adds tests for priority queue

* Add tests, minor fixes

* Add AllowListOperatorManager tests

* Minor refactoring

* Minor fixes

* Refactor PriorityQueue

* Fix formatting

* Fix formatting

* Fix formatting

* Rename transact, add calldata version

* Add commitment to RootUpdated event

* Return gracePeriodEnd from pendingCommitment

* Add memo message size

* Add extra data to tests

* Support new message prefix

* Remove forced exit related code

* Update src/zkbob/utils/PriorityQueue.sol

Co-authored-by: Kirill Fedoseev <[email protected]>

* Refactor AllowListOperatorManager

* Rename PriorityQueue, add copyright, uint32 timestamp

* Remove minTreeUpdateFeeIsSet modifier

* Pack fee reciever and allowed in a single struct

* Remove lastTreeUpdateTimestamp

* Add gaps, fix testNativeWithdrawal

* Fix formatting

* Update ZkBobPool.s.sol and Local.s.sol scripts

* Add script to deploy new operator, modify upgrade script

* Minor fixes

* Add privileged prover in calldata

* Update scripts

* Add decentralization upgrade script

* Modify migration script

* Update scripts

* Minor fixes

* Fix format

* Fix format

---------

Co-authored-by: vladimir <[email protected]>
Co-authored-by: Kirill Fedoseev <[email protected]>
  • Loading branch information
3 people authored Sep 10, 2024
1 parent 17f2adf commit 1677f1e
Show file tree
Hide file tree
Showing 22 changed files with 1,973 additions and 706 deletions.
1 change: 1 addition & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2021 ZeroPool
Copyright (c) 2019 Matter Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
48 changes: 48 additions & 0 deletions script/scripts/DeployAllowListOperatorManager.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: CC0-1.0

pragma solidity 0.8.15;

import "forge-std/Script.sol";
import {AllowListOperatorManager} from "../../src/zkbob/manager/AllowListOperatorManager.sol";

// TODO: Update this values before the deployment
address constant operatorManagerOwner = 0x14fc6a1a996A2EB889cF86e5c8cD17323bC85290;
address constant zkBobProxy1 = 0x7D2D146a7AD3F0Dc398AA718a9bFCa2Bc873a5FD;
address constant zkBobProxyFeeReceiver1 = 0x7D2D146a7AD3F0Dc398AA718a9bFCa2Bc873a5FD;
address constant zkBobProxy2 = 0xFec49782FE8e11De9Fb3Ba645a76FE914FFfe3cb;
address constant zkBobProxyFeeReceiver2 = 0xFec49782FE8e11De9Fb3Ba645a76FE914FFfe3cb;
address constant zkBobProver1 = 0x33a0b018340d6424870cfC686a4d02e1df792254;
address constant zkBobProverFeeReceiver1 = 0x33a0b018340d6424870cfC686a4d02e1df792254;
address constant zkBobProver2 = 0x63A88E69fa7adEf036fc6ED94394CC9295de2f99;
address constant zkBobProverFeeReceiver2 = 0x63A88E69fa7adEf036fc6ED94394CC9295de2f99;

bool constant allowListEnabled = true;

contract DeployAllowListOperatorManager is Script {
function run() external {
vm.startBroadcast();

address[] memory operators = new address[](4);
operators[0] = zkBobProxy1;
operators[1] = zkBobProver1;
operators[2] = zkBobProxy2;
operators[3] = zkBobProver2;

address[] memory feeReceivers = new address[](4);
feeReceivers[0] = zkBobProxyFeeReceiver1;
feeReceivers[1] = zkBobProverFeeReceiver1;
feeReceivers[2] = zkBobProxyFeeReceiver2;
feeReceivers[3] = zkBobProverFeeReceiver2;

AllowListOperatorManager operatorManager =
new AllowListOperatorManager(operators, feeReceivers, allowListEnabled);

operatorManager.transferOwnership(operatorManagerOwner);

vm.stopBroadcast();

assert(address(operatorManager.owner()) == operatorManagerOwner);

console2.log("AllowListOperatorManager address:", address(operatorManager));
}
}
85 changes: 0 additions & 85 deletions script/scripts/DeployZkBobPoolModules.s.sol

This file was deleted.

58 changes: 42 additions & 16 deletions script/scripts/Env.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ enum PoolType {
}

// common
address constant deployer = 0x39F0bD56c1439a22Ee90b4972c16b7868D161981;
address constant admin = 0xd4a3D9Ca00fa1fD8833D560F9217458E61c446d8;
address constant owner = 0xd4a3D9Ca00fa1fD8833D560F9217458E61c446d8;
address constant deployer = 0x37493bFe9c8c31fAbe8615C988e83D59D1a667a9;
address constant admin = 0x37493bFe9c8c31fAbe8615C988e83D59D1a667a9;
address constant owner = 0x37493bFe9c8c31fAbe8615C988e83D59D1a667a9;
address constant mockImpl = address(0xdead);

// bob
Expand All @@ -23,25 +23,51 @@ address constant bobVanityAddr = address(0xB0B195aEFA3650A6908f15CdaC7D92F8a5791
bytes32 constant bobSalt = bytes32(uint256(285834900769));

// zkbob
uint256 constant zkBobPoolId = 0; // 0 is reserved for Polygon MVP pool, do not use for other deployments
uint256 constant zkBobPoolId = 0xffff0a; // 0 is reserved for Polygon MVP pool, do not use for other deployments
PoolType constant zkBobPoolType = PoolType.BOB;
string constant zkBobVerifiers = "prodV1";
address constant zkBobToken = 0xB0B195aEFA3650A6908f15CdaC7D92F8a5791B0B;
string constant zkBobVerifiers = "stageV2";
address constant zkBobToken = 0x2C74B18e2f84B78ac67428d0c7a9898515f0c46f;
uint256 constant zkBobInitialRoot = 11469701942666298368112882412133877458305516134926649826543144744382391691533;
address constant zkBobRelayer = 0xc2c4AD59B78F4A0aFD0CDB8133E640Db08Fa5b90;
address constant zkBobRelayerFeeReceiver = 0x758768EC473279c4B1Aa61FA5450745340D4B17d;
string constant zkBobRelayerURL = "https://relayer-mvp.zkbob.com";
uint256 constant zkBobPoolCap = 1_000_000 ether;
uint256 constant zkBobDailyDepositCap = 100_000 ether;
uint256 constant zkBobDailyWithdrawalCap = 100_000 ether;
uint256 constant zkBobDailyUserDepositCap = 10_000 ether;
uint256 constant zkBobDepositCap = 10_000 ether;
uint256 constant zkBobDailyUserDirectDepositCap = 0;
uint256 constant zkBobDirectDepositCap = 0;
address constant zkBobProxy = 0xFec49782FE8e11De9Fb3Ba645a76FE914FFfe3cb;
address constant zkBobProxyFeeReceiver = 0xFec49782FE8e11De9Fb3Ba645a76FE914FFfe3cb;
address constant zkBobProver = 0x7D2D146a7AD3F0Dc398AA718a9bFCa2Bc873a5FD;
address constant zkBobProverFeeReceiver = 0x7D2D146a7AD3F0Dc398AA718a9bFCa2Bc873a5FD;
uint256 constant zkBobDirectDepositFee = 0.1 gwei;
uint256 constant zkBobDirectDepositTimeout = 1 days;
address constant permit2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;

// decentralized
uint64 constant gracePeriod = 3 minutes; // TODO
uint64 constant minTreeUpdateFee = 0.1 gwei;
bool constant allowListEnabled = true;

// accounting
address constant kycManager = address(0);

uint256 constant tier0TvlCap = 2_000_000 gwei;
uint256 constant tier0DailyDepositCap = 300_000 gwei;
uint256 constant tier0DailyWithdrawalCap = 300_000 gwei;
uint256 constant tier0DailyUserDepositCap = 10_000 gwei;
uint256 constant tier0DepositCap = 10_000 gwei;
uint256 constant tier0DailyUserDirectDepositCap = 10_000 gwei;
uint256 constant tier0DirectDepositCap = 1_000 gwei;

uint256 constant tier1TvlCap = 2_000_000 gwei;
uint256 constant tier1DailyDepositCap = 300_000 gwei;
uint256 constant tier1DailyWithdrawalCap = 300_000 gwei;
uint256 constant tier1DailyUserDepositCap = 100_000 gwei;
uint256 constant tier1DepositCap = 100_000 gwei;
uint256 constant tier1DailyUserDirectDepositCap = 10_000 gwei;
uint256 constant tier1DirectDepositCap = 1_000 gwei;

uint256 constant tier254TvlCap = 2_000_000 gwei;
uint256 constant tier254DailyDepositCap = 300_000 gwei;
uint256 constant tier254DailyWithdrawalCap = 300_000 gwei;
uint256 constant tier254DailyUserDepositCap = 20_000 gwei;
uint256 constant tier254DepositCap = 20_000 gwei;
uint256 constant tier254DailyUserDirectDepositCap = 10_000 gwei;
uint256 constant tier254DirectDepositCap = 1_000 gwei;

// new zkbob impl
address constant zkBobPool = 0x72e6B59D4a90ab232e55D4BB7ed2dD17494D62fB;

Expand Down
62 changes: 46 additions & 16 deletions script/scripts/Local.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "../../test/shared/EIP2470.t.sol";
import "../../src/BobToken.sol";
import "../../src/proxy/EIP1967Proxy.sol";
import "../../src/zkbob/ZkBobPoolBOB.sol";
import "../../src/zkbob/manager/MutableOperatorManager.sol";
import {AllowListOperatorManager} from "../../src/zkbob/manager/AllowListOperatorManager.sol";
import "../../src/zkbob/ZkBobDirectDepositQueue.sol";
import "../../src/zkbob/utils/ZkBobAccounting.sol";

Expand Down 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 All @@ -64,28 +59,63 @@ contract DeployLocal is Script {

{
ZkBobAccounting accounting = new ZkBobAccounting(address(pool), 1_000_000_000);
if (kycManager != address(0)) {
accounting.setKycProvidersManager(IKycProvidersManager(kycManager));
}
accounting.setLimits(
0,
zkBobPoolCap,
zkBobDailyDepositCap,
zkBobDailyWithdrawalCap,
zkBobDailyUserDepositCap,
zkBobDepositCap,
zkBobDailyUserDirectDepositCap,
zkBobDirectDepositCap
tier0TvlCap,
tier0DailyDepositCap,
tier0DailyWithdrawalCap,
tier0DailyUserDepositCap,
tier0DepositCap,
tier0DailyUserDirectDepositCap,
tier0DirectDepositCap
);
accounting.setLimits(
1,
tier1TvlCap,
tier1DailyDepositCap,
tier1DailyWithdrawalCap,
tier1DailyUserDepositCap,
tier1DepositCap,
tier1DailyUserDirectDepositCap,
tier1DirectDepositCap
);
accounting.setLimits(
254,
tier254TvlCap,
tier254DailyDepositCap,
tier254DailyWithdrawalCap,
tier254DailyUserDepositCap,
tier254DepositCap,
tier254DailyUserDirectDepositCap,
tier254DirectDepositCap
);
pool.setAccounting(accounting);
}

{
IOperatorManager operatorManager =
new MutableOperatorManager(zkBobRelayer, zkBobRelayerFeeReceiver, zkBobRelayerURL);
address[] memory operators = new address[](2);
operators[0] = zkBobProxy;
operators[1] = zkBobProver;

address[] memory feeReceivers = new address[](2);
feeReceivers[0] = zkBobProxyFeeReceiver;
feeReceivers[1] = zkBobProverFeeReceiver;

IOperatorManager operatorManager = new AllowListOperatorManager(operators, feeReceivers, allowListEnabled);
pool.setOperatorManager(operatorManager);
queue.setOperatorManager(operatorManager);
queue.setDirectDepositFee(uint64(zkBobDirectDepositFee));
queue.setDirectDepositTimeout(uint40(zkBobDirectDepositTimeout));
}

{
pool.setGracePeriod(gracePeriod);
pool.setMinTreeUpdateFee(minTreeUpdateFee);
}

{
if (owner != address(0)) {
bob.transferOwnership(owner);
Expand Down
Loading

0 comments on commit 1677f1e

Please sign in to comment.