additional validations / checks #14
Open
+967
−795
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change Summary
What does this PR change?
This PR addresses some vulnerabilities and implements gas optimizations across the Aqua Protocol core contracts. Fixes include input validation (array length checks, zero address validation, duplicate token detection), integer overflow prevention in AMM pricing formulas, and protection against msg.value reuse in multicall operations.
Detailed Changes
Security Fixes
HIGH Risk Vulnerabilities (3 fixed)
Array Length Mismatch (
src/Aqua.sol:53)require(tokens.length == amounts.length)Zero Address Validation (
src/Aqua.sol:52, 63, 92, 106)ship(),pull(),push()functionsmsg.value Reuse in Multicall (
src/libs/Multicall.sol:11-13)MEDIUM Risk Vulnerabilities (4 fixed)
Duplicate Token Detection (
src/Aqua.sol:65-68)Insufficient Balance Checks (
src/Aqua.sol:96-97)Integer Overflow in Pricing (
examples/apps/XYCSwap.sol:128, 138)(a * b) / cwithMath.mulDiv(a, b, c)Redundant Hash Calculation (
examples/apps/XYCSwap.sol:53-85, 87-119)Gas Optimizations (8 applied)
Estimated Gas Savings:
ship(): ~86 gas (2 tokens)dock(): ~86 gas (2 tokens)swapExactIn/Out(): ~200-300 gas eachmulticall(): ~43 gas per iterationFiles Changed
Modified Files
src/Aqua.solship(),dock(),pull(),push()examples/apps/XYCSwap.solswapExactIn(),swapExactOut(),_quoteExactIn(),_quoteExactOut()_swapExactIn(),_swapExactOut()private helperssrc/libs/Multicall.solmulticall()