Function: withdraw(address token, uint256 amount, bool unwrap)

The function can be utilized for withdrawing tokens from the escrow contract.

Inputs

  • token

    • Control: Fully controlled by the caller.

    • Constraints: No constraints.

    • Impact: This token is withdrawn from the contract.

  • amount

    • Control: Fully controlled by the caller.

    • Constraints: Should not be 0, and user's deposit balance should be greater than or equal to this value.

    • Impact: The amount of token to be withdrawn.

  • unwrap

    • Control: Fully controlled by the caller.

    • Constraints: Should be a boolean.

    • Impact: Unwraps and then transfers the token to the user if true; transfers directly without unwrapping if false.

Branches and code coverage

Intended branches

  • If unwrap is true, then unwrap the token and transfer the unwrapped token to the caller.

  • If unwrap is false, directly transfer the token to the caller.

  • Decrease the usersBalance of the user and totalStaked for that token by amount.

Negative behavior

  • Revert if amount is 0.

  • Revert if balance of the user is less than the withdrawal amount requested.

  • Revert if unwrap is true and the address of rebase for that token is address(0).

  • Revert if rebase token is ETH and the transfer of ETH to msg.sender fails.

Function call analysis

  • this._getStorage()

    • What is controllable? N/A.

    • If the return value is controllable, how is it used and how can it go wrong? Returns the storage slot.

    • What happens if it reverts, reenters or does other unusual control flow? N/A.

  • SafeERC20.safeTransfer(IERC20(tokenInfo.rebase), msg.sender, finalAmt)

    • What is controllable? msg.sender and finalAmt (partially controllable).

    • If the return value is controllable, how is it used and how can it go wrong? N/A.

    • What happens if it reverts, reenters or does other unusual control flow? If it reverts, the entire transaction would revert — no reentrancy scenario.

  • SafeERC20.safeTransfer(IERC20(token), msg.sender, amount)

    • What is controllable? token, msg.sender, and amount.

    • If the return value is controllable, how is it used and how can it go wrong? N/A.

    • What happens if it reverts, reenters or does other unusual control flow? If it reverts, the entire transaction would revert — no reentrancy scenario.

Zellic © 2024Back to top ↑