Skip to content

Commit

Permalink
Update forceExit
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill-fedoseev committed Aug 17, 2023
1 parent 63cce9f commit 3bf899f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/zkbob/ZkBobPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,9 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Zk
/**
* @dev Performs a forced withdrawal by irreversibly killing an account.
* Callable only by the zk account owner.
* Account cannot be recoverd after such forced exit,
* Account cannot be recovered after such forced exit,
* any remaining or newly sent funds would be lost forever.
* Accumulated account energy is forfeited.
* @param _to withdrawn funds receiver.
* @param _amount total account balance to withdraw.
* @param _index index of the merkle root used within proof.
Expand All @@ -350,7 +351,7 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Zk
)
external
{
require(_amount < type(uint64).max, "ZkBobPool: amount too large");
require(_amount <= 1 << 63, "ZkBobPool: amount too large");
require(_index < type(uint48).max, "ZkBobPool: index too large");

uint256 root = roots[_index];
Expand All @@ -361,15 +362,15 @@ abstract contract ZkBobPool is IZkBobPool, EIP1967Admin, Ownable, Parameters, Zk
root,
_nullifier,
_out_commit,
(pool_id << (transfer_delta_size * 8)) + (_index << 176) + _amount,
(pool_id << 224) + (_index << 176) + uint64(-int64(uint64(_amount))),
uint256(keccak256(abi.encodePacked(_to))) % R
];
require(transfer_verifier.verifyProof(transfer_pub, _transfer_proof), "ZkBobPool: bad transfer proof");

uint256 poolIndex = _recordForceExit(_amount) << 7;
nullifiers[_nullifier] = poolIndex | uint256(0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddeaddead0000000000000000);

IERC20(token).safeTransfer(_to, _amount * TOKEN_DENOMINATOR);
IERC20(token).safeTransfer(_to, _amount * TOKEN_DENOMINATOR / TOKEN_NUMERATOR);

emit ForcedExit(poolIndex, _nullifier, _to, _amount);
}
Expand Down
2 changes: 1 addition & 1 deletion test/zkbob/ZkBobPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ abstract contract AbstractZkBobPoolTest is AbstractForkTest {
assertEq(IERC20(token).balanceOf(user3), 0.02 ether / D);
}

function testForcedExit() public {
function testForceExit() public {
bytes memory data = _encodePermitDeposit(int256(0.5 ether / D), 0.01 ether / D);
_transact(data);

Expand Down

0 comments on commit 3bf899f

Please sign in to comment.