Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tron deploy beta #2

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
45 changes: 35 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
export POOL_ID=16776966
export ADMIN=TASrJ76QANNPRgdDHHikWWApQzxh3HPku4
export OWNER=TASrJ76QANNPRgdDHHikWWApQzxh3HPku4
export USE_STAGE_VERIFIERS=TRUE
# all addresses in base58

export INITIAL_ROOT=11469701942666298368112882412133877458305516134926649826543144744382391691533
export RELAYER=TASrJ76QANNPRgdDHHikWWApQzxh3HPku4
export FEE_RECEIVER=TASrJ76QANNPRgdDHHikWWApQzxh3HPku4
export RELAYER_URL=https://relayer-mvp.zkbob.com
export POOL_ID=16776966

# possible values: stage (default), prod, offchain
export VERIFIERS=offchain
# underlaying token
export TOKEN=TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf

export TOKEN=41abdbbd1e6728e236097f2a2b7f9b4eb8b115c1eb
# admin of the pool and direct deposit queue proxies
export ADMIN=
# owner of the pool, direct deposit queue, operator manager, and mpc guard
export OWNER=

# address of the master relayer
export RELAYER=
# address of the fee receiver
export FEE_RECEIVER=
export RELAYER_URL=https://relayer-mvp.zkbob.com
# list of mpc guards (comma separated)
export MPC_GUARDS="TS8zrYZH2yNiiTNvn4GKJWcp1nJqQQFg3G,TK3Gx9Yy4tDJhYznm8QXAssLzdtpx3J2Yr,TE4BvV4sczfo4q82eF5qkHwv8gTTD2ccry"

export PRIVATE_KEY=
export PRIVATE_KEY_NILE=
export PRIVATE_KEY_MAINNET=

#limits
export POOL_CAP=144115188075855871
export DAILY_DEPOSIT_CAP=8589934591
export DAILY_WITHDRAWAL_CAP=8589934591
export DAILY_USER_DEPOSIT_CAP=8589934591
export DEPOSIT_CAP=8589934591
export DAILY_USER_DIRECT_DEPOSIT_CAP=0
export DIRECT_DEPOSIT_CAP=0


export POOL_IMPL=41fa7f6e7f0d58744de29fd86a63f4b9ee9a520cab
export QUEUE_PROXY=41c85435d9c9094f2d7c210763b589fa44c96a39ce
# this values should be filled after 2_pool_impl.js migration
export POOL_IMPL=
export QUEUE_PROXY=
8 changes: 8 additions & 0 deletions contracts/src/interfaces/IZkBobPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ interface IZkBobPool {
function pool_id() external view returns (uint256);

function recordDirectDeposit(address _sender, uint256 _amount) external;

function appendDirectDeposits(
uint256 _root_after,
uint256[] calldata _indices,
uint256 _out_commit,
uint256[8] memory _batch_deposit_proof,
uint256[8] memory _tree_proof
) external;
}
2 changes: 1 addition & 1 deletion contracts/src/utils/UniswapV3Seller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ contract UniswapV3Seller is ITokenSeller {
uint256 remainingBalance = IERC20(token0).balanceOf(address(this));
if (remainingBalance + _amount > balance) {
uint256 refund = remainingBalance + _amount - balance;
IERC20(token0).safeTransfer(msg.sender, refund);
IERC20(token0).transfer(msg.sender, refund);
return (amountOut, refund);
}
return (amountOut, 0);
Expand Down
45 changes: 0 additions & 45 deletions contracts/src/zkbob/ZkBobPermit2Mixin.sol

This file was deleted.

41 changes: 15 additions & 26 deletions contracts/src/zkbob/ZkBobPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Zk
{
require(__pool_id <= MAX_POOL_ID, "ZkBobPool: exceeds max pool id");
require(Address.isContract(_token), "ZkBobPool: not a contract");
require(Address.isContract(address(_transfer_verifier)), "ZkBobPool: not a contract");
require(Address.isContract(address(_tree_verifier)), "ZkBobPool: not a contract");
require(Address.isContract(address(_batch_deposit_verifier)), "ZkBobPool: not a contract");

// require(Address.isContract(address(_transfer_verifier)), "ZkBobPool: not a contract");
// require(Address.isContract(address(_tree_verifier)), "ZkBobPool: not a contract");
// require(Address.isContract(address(_batch_deposit_verifier)), "ZkBobPool: not a contract");
require(Address.isContract(_direct_deposit_queue), "ZkBobPool: not a contract");
pool_id = __pool_id;
token = _token;
Expand Down Expand Up @@ -175,14 +176,6 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Zk
*/
function _withdrawNative(address _user, uint256 _tokenAmount) internal virtual returns (uint256);

/**
* @dev Performs token transfer using a signed permit signature.
* @param _user token depositor address, should correspond to the signature author.
* @param _nullifier nullifier and permit signature salt to avoid transaction data manipulation.
* @param _tokenAmount amount to tokens to deposit.
*/
function _transferFromByPermit(address _user, uint256 _nullifier, int256 _tokenAmount) internal virtual;

/**
* @dev Perform a zkBob pool transaction.
* Callable only by the current operator.
Expand Down Expand Up @@ -214,10 +207,10 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Zk

require(nullifiers[nullifier] == 0, "ZkBobPool: doublespend detected");
require(_transfer_index() <= _pool_index, "ZkBobPool: transfer index out of bounds");
require(transfer_verifier.verifyProof(_transfer_pub(), _transfer_proof()), "ZkBobPool: bad transfer proof");
require(
tree_verifier.verifyProof(_tree_pub(roots[_pool_index]), _tree_proof()), "ZkBobPool: bad tree proof"
);
// require(transfer_verifier.verifyProof(_transfer_pub(), _transfer_proof()), "ZkBobPool: bad transfer proof");
// require(
// tree_verifier.verifyProof(_tree_pub(roots[_pool_index]), _tree_proof()), "ZkBobPool: bad tree proof"
// );

nullifiers[nullifier] = uint256(keccak256(abi.encodePacked(_transfer_out_commit(), _transfer_delta())));
_pool_index += 128;
Expand All @@ -238,7 +231,7 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Zk
if (txType == 0) {
// Deposit
require(transfer_token_delta > 0 && energy_amount == 0, "ZkBobPool: incorrect deposit amounts");
IERC20(token).safeTransferFrom(user, address(this), uint256(token_amount) * TOKEN_DENOMINATOR);
IERC20(token).transferFrom(user, address(this), uint256(token_amount) * TOKEN_DENOMINATOR);
} else if (txType == 1) {
// Transfer
require(token_amount == 0 && energy_amount == 0, "ZkBobPool: incorrect transfer amounts");
Expand All @@ -262,10 +255,6 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Zk
if (energy_amount < 0) {
revert("ZkBobPool: XP claiming is not yet enabled");
}
} else if (txType == 3) {
// Permittable token deposit
require(transfer_token_delta > 0 && energy_amount == 0, "ZkBobPool: incorrect deposit amounts");
_transferFromByPermit(user, nullifier, token_amount);
} else {
revert("ZkBobPool: Incorrect transaction type");
}
Expand Down Expand Up @@ -301,12 +290,12 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Zk
uint256 _pool_index = txCount << 7;

// verify that _out_commit corresponds to zero output account + 16 chosen notes + 111 empty notes
require(
batch_deposit_verifier.verifyProof([hashsum], _batch_deposit_proof), "ZkBobPool: bad batch deposit proof"
);
// require(
// batch_deposit_verifier.verifyProof([hashsum], _batch_deposit_proof), "ZkBobPool: bad batch deposit proof"
// );

uint256[3] memory tree_pub = [roots[_pool_index], _root_after, _out_commit];
require(tree_verifier.verifyProof(tree_pub, _tree_proof), "ZkBobPool: bad tree proof");
// uint256[3] memory tree_pub = [roots[_pool_index], _root_after, _out_commit];
// require(tree_verifier.verifyProof(tree_pub, _tree_proof), "ZkBobPool: bad tree proof");

_pool_index += 128;
roots[_pool_index] = _root_after;
Expand Down Expand Up @@ -345,7 +334,7 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Zk
);
uint256 fee = accumulatedFee[_operator] * TOKEN_DENOMINATOR;
require(fee > 0, "ZkBobPool: no fee to withdraw");
IERC20(token).safeTransfer(_to, fee);
IERC20(token).transfer(_to, fee);
r0wdy1 marked this conversation as resolved.
Show resolved Hide resolved
accumulatedFee[_operator] = 0;
emit WithdrawFee(_operator, fee);
}
Expand Down
33 changes: 0 additions & 33 deletions contracts/src/zkbob/ZkBobPoolBOB.sol

This file was deleted.

4 changes: 1 addition & 3 deletions contracts/src/zkbob/ZkBobPoolERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ pragma solidity ^0.8.0;

import "./ZkBobPool.sol";
import "./ZkBobTokenSellerMixin.sol";
import "./ZkBobPermit2Mixin.sol";

/**
* @title ZkBobPoolERC20
* Shielded transactions pool for ERC20 tokens
*/
contract ZkBobPoolERC20 is ZkBobPool, ZkBobTokenSellerMixin, ZkBobPermit2Mixin {
contract ZkBobPoolERC20 is ZkBobPool, ZkBobTokenSellerMixin {
constructor(
uint256 __pool_id,
address _token,
Expand All @@ -32,6 +31,5 @@ contract ZkBobPoolERC20 is ZkBobPool, ZkBobTokenSellerMixin, ZkBobPermit2Mixin {
_denominator,
_precision
)
ZkBobPermit2Mixin(_permit2)
{}
}
35 changes: 0 additions & 35 deletions contracts/src/zkbob/ZkBobPoolETH.sol

This file was deleted.

33 changes: 0 additions & 33 deletions contracts/src/zkbob/ZkBobPoolUSDC.sol

This file was deleted.

18 changes: 0 additions & 18 deletions contracts/src/zkbob/ZkBobSaltedPermitMixin.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/src/zkbob/ZkBobTokenSellerMixin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract contract ZkBobTokenSellerMixin is ZkBobPool {
function _withdrawNative(address _user, uint256 _tokenAmount) internal override returns (uint256) {
ITokenSeller seller = tokenSeller;
if (address(seller) != address(0)) {
IERC20(token).safeTransfer(address(seller), _tokenAmount);
IERC20(token).transfer(address(seller), _tokenAmount);
(, uint256 refunded) = seller.sellForETH(_user, _tokenAmount);
return _tokenAmount - refunded;
}
Expand Down
27 changes: 0 additions & 27 deletions contracts/src/zkbob/ZkBobUSDCPermitMixin.sol

This file was deleted.

Loading