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

Pool for native tokens #62

Merged
merged 11 commits into from
Apr 7, 2023
Merged

Pool for native tokens #62

merged 11 commits into from
Apr 7, 2023

Conversation

AlexSaplin
Copy link
Collaborator

No description provided.

@AlexSaplin AlexSaplin changed the base branch from master to develop March 29, 2023 20:20
src/zkbob/ZkBobDirectDepositQueue.sol Outdated Show resolved Hide resolved
src/zkbob/ZkBobDirectDepositQueueETH.sol Outdated Show resolved Hide resolved
src/zkbob/ZkBobPool.sol Outdated Show resolved Hide resolved
src/zkbob/ZkBobPool.sol Outdated Show resolved Hide resolved
function _withdrawNative(address user, uint256 tokenAmount) internal override returns (uint256 spentAmount) {
IWETH9(token).withdraw(tokenAmount);
if (!payable(user).send(tokenAmount)) {
new Sacrifice{value: tokenAmount}(user);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to start thinking about another approach, since self-destruct is gonna be deprecated this or next year - https://eips.ethereum.org/EIPS/eip-4760

So far, the only reasonable approach I can suggest is to allow native withdrawals only for EOA addresses.

@akolotov wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, did you see if any of popular protocols use an approach like we use with the selfdestruct?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen such.
Just took a quick look at Aztec codebase, ETH from such failed withdrawals is kept on the contract balance, seems like with no way to recover it - https://github.com/AztecProtocol/aztec-connect/blob/a601e38f2866babae785fd9e0313ee02f208a754/contracts/src/core/processors/RollupProcessor.sol#L1262-L1269

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of WETH pool, acceptable solution might be to transfer WETH as a fallback in case of ETH transfer failure. I think we should go with that option for now.

As for the TokenSeller, I think we should wait until the concrete self-destruct deprecation EIP will be chosen and finalized.

test/zkbob/ZkBobPoolETH.t.sol Outdated Show resolved Hide resolved
function _withdrawNative(address user, uint256 tokenAmount) internal override returns (uint256 spentAmount) {
IWETH9(token).withdraw(tokenAmount);
if (!payable(user).send(tokenAmount)) {
new Sacrifice{value: tokenAmount}(user);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, did you see if any of popular protocols use an approach like we use with the selfdestruct?

}

function testSimpleTransaction() public {
bytes memory data1 = _encodePermitDeposit(0.5 ether, 0.01 ether);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the order of permit deposits does not mater with permit2 consider to make an explicit test for this. For example, there could be like this:

bytes memory data2 = _encodePermitDeposit(0.75 ether, 0.01 ether);
bytes memory data1 = _encodePermitDeposit(0.5 ether, 0.01 ether);

_transact(data1);
_transact(data2);

src/zkbob/ZkBobPool.sol Outdated Show resolved Hide resolved
function _withdrawNative(address user, uint256 tokenAmount) internal override returns (uint256 spentAmount) {
IWETH9(token).withdraw(tokenAmount);
if (!payable(user).send(tokenAmount)) {
new Sacrifice{value: tokenAmount}(user);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of WETH pool, acceptable solution might be to transfer WETH as a fallback in case of ETH transfer failure. I think we should go with that option for now.

As for the TokenSeller, I think we should wait until the concrete self-destruct deprecation EIP will be chosen and finalized.

src/zkbob/ZkBobPoolETH.sol Outdated Show resolved Hide resolved
Co-authored-by: Kirill Fedoseev <[email protected]>
@akolotov akolotov changed the title ZkBobETHPool Pool for native tokens Apr 7, 2023
@akolotov akolotov merged commit 682e28a into develop Apr 7, 2023
@akolotov akolotov deleted the feat/zkbobethpool branch April 7, 2023 10:30
akolotov added a commit that referenced this pull request Apr 7, 2023
This merge contains the following set of changes:
  - Pool for native tokens (#62)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants