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

audit: zap3 Fixed issues #8

Open
wants to merge 17 commits into
base: feat/zap3.0
Choose a base branch
from
Open

audit: zap3 Fixed issues #8

wants to merge 17 commits into from

Conversation

Doublo54
Copy link
Collaborator

@Doublo54 Doublo54 commented Jun 22, 2023

ApeSwap-hardhat-zap Paladin audit review

Issue 4: removeLiquidityGamma is flawed

Issue 23:

Issues to revisit

Issue 10: The amount parameter can differ from msg.value

  • Resolved
    Added check for msg.value >= amount in case there is a use case where wrap is less than msg.value (don’t know a use case yet)

Issue 17: msg.value is unchecked

  • Resolved: Added noNativeSurplus modifier to multicall to prevent excess BNB from being left in contract.

Issues 6, 11, 12, 13, 14, 15, 16, 18, 22, 24, 25, 27, 28

  • Resolved

Issues with comments (Resolved)

Issue 1: Token recipients can be address(this)

Fixed for all except ZapLiquidity because LPs can be zapped to pools, vaults etc

Issue 3: Lack of validation for constructor arguments

Fixed except for banana treasury because zero address is allowed if not bnb chain. Validation for bnb chain is in ApeSwapZapPool

Issue 8: Typographical issues

IGammaUniProxy and IGammaHypervisor are used. Renamed UniProxy and Hypervisor interfaces to match file name.
For AddLiquidityV2Params, lpRouter now defined as IV2LiquidityRouter02
Fixed IArrakisRouter lpRouter

Issue 19: GNANA logic is flawed

Fixed by adding check if inputToken == GNANA then transferIn Banana and else just the token like normal.

  • Resolved

Discussion (Not resolved)

Issue 2: Unnecessary payable functions

Payable necessary for multicall

Issue 5: Tokens with a fee on transfer will lose value

Aware and noted. Probably not planning to use such tokens here?

Issue 7: Several functions accept native value when they should not

Payable necessary for multicall

Issue 9: The unwrapNative function is flawed

Usage only meant in combination with other functions in multicall. Example: swap busd->wbnb, unwrap and withdraw. Maybe we just shouldn’t allow unwrap and keep in contract. First it could be used for zapping to lending but with changes not anymore.

Issue 20: estimateSwapReturns might run out of gas

No code changes. “Consider monitoring this issue and prepare a custom RPC node that can deal with a custom gas limit.”

Issue 21: Discrepancy between router and factory

We are aware and don’t think it’s a big deal. Just depends on the liquidity type that we need to pass.

Issue 26: getArrakisPool might run out of gas

“Due to the logic in the Arrakis contracts, there is no easy way to solve this issue“. Noted but not sure how much we can do here (and not using Arrakis (yet))

Issue 29: getLPAddRatio for Gamma can be different from result

We have to choose something here. Right in the middle makes the most sense to me. Least chance of reverting because of slippage.

Issue 30: Missing warning for payable modifier

Not added acknowledgment into the code yet. It’s only vulnerable to using msg.value in code which we have in 2 places. wrapNative and ApeSwapZapLending. In both places, you can steal eth if it’s in the contract. But zap is not designed to actually hold any eth and it’s recommended to only do multicalls where ALL funds are used and transferred back. So should not be a (big) issue? But let’s discuss.

@DeFiFoFum DeFiFoFum self-requested a review June 22, 2023 22:15
@DeFiFoFum DeFiFoFum changed the title audit: Fixed issues audit: zap3 Fixed issues Jun 28, 2023
contracts/lens/ZapAnalyzer.sol Outdated Show resolved Hide resolved
contracts/utils/TokenHelper.sol Outdated Show resolved Hide resolved
contracts/extensions/lending/ApeSwapZapLending.sol Outdated Show resolved Hide resolved
contracts/WrapNative.sol Outdated Show resolved Hide resolved
contracts/extensions/pools/ApeSwapZapPools.sol Outdated Show resolved Hide resolved
DeFiFoFum and others added 14 commits June 29, 2023 18:46
- removeLiquidityGamma: Resolve by transferring in tokens first
- Use `estimateSwapReturns` to estimate the amounts for Arrakis LP add
- Refactor check for ZapAnalyzer in constructor of Zap
- Refactor precision calculation in _getWeightedPrice
… balance left in contract

- This helps ensure that users don't send excess Native tokens to the contract they didn't intend on which could be captured by other users
- Refactored ApeSwapZapLending to allow for input amount over msg.value
- Organize functions to match similar flow for readability
- Protects against reentrancy attacks during multicall
- Protects against reentrancy attacks out of multicall
- Provides helper functions for validating checks depending on the state of the multicall
- Organize functions to match similar flow for readability
- Add `receive` function to protect against unwanted native deposits
- Rename SwapParams to be more clear
- Reset approvals after swap() call
- Update hardhat-etherscan to version 3
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.

2 participants