Hunt prep
Before you test Marginswap
What 19 disclosed reports say about Marginswap: what was found and paid, what was fixed, and where it may be worth looking next.
- with a public bounty
- 0
- median public bounty
- –
- highest public bounty
- –
Gaps worth testing
Not written yet for this program. The numbers below are up to date.
What was found and what it paid
Public bounties only; many reports disclose without the amount.
| Class | Reports | Paid | Median | Highest | In all |
|---|---|---|---|---|---|
| Business logic lesson | 10 | 0 | – | – | $0 |
| Access control lesson | 3 | 0 | – | – | $0 |
| DoS lesson | 2 | 0 | – | – | $0 |
| Smart contracts lesson | 2 | 0 | – | – | $0 |
What was fixed
All reportsThe newest fixes, in our words. A fixed bug is not worth re-reporting, but a sibling feature, an older API version or a regression may be.
-
Price feed can be manipulated
The price oracle should be replaced with a TWAP oracle built on the cumulative price variables rather than the spot reserves.
Disclosed
-
Users are credited more tokens when paying back debt with registerTradeAndBorrow
The adjustAmounts call should credit only the trade output left after debt repayment, as registerDeposit already does.
Disclosed
-
Rewards cannot be withdrawn
The `isIncentiveReporter(msg.sender)` check should be removed from `withdrawReward` so the reward owner can withdraw.
Disclosed
-
No default liquidationThresholdPercent
A default liquidation threshold should be set, as is done in the CrossMarginTrading contracts.
Disclosed
-
Users Can Drain Funds From MarginSwap By Making Undercollateralized Borrows If The Price Of A Token Has Moved More Than 10% Since The Last MarginSwap Borrow/Liquidation Involving Accounts Holding That Token.
The real solution is to use UniswapV2/SushiSwap/UniswapV3’s built in TWAP price oracle, and the protocol should consider adding an additional buffer around immediate withdrawals and rewards for updating the price.
Disclosed
-
PriceAware uses prices from getAmountsOut
The contract should use a time-weighted average price oracle as recommended by Uniswap v2 instead of the spot getAmountsOut value.
Disclosed
-
Wrong liquidation logic
The comparison should be flipped so that liquidation triggers only when holdings are at or below the threshold relative to the loan.
Disclosed
-
diffMaxMinRuntime gets default value of 0
It should be fixed by setting an appropriate value for the variable and updating it whenever the min or max runtime variables change.
Disclosed
-
Add a timelock to functions that set key variables
The setters should be placed behind a timelock so parameter changes are announced in advance; the project said governance would handle this.
Disclosed
-
account.holdsToken is never set
The holdsToken map should be correctly set in the addHolding function to prevent duplicate entries.
Disclosed
-
Re-entrancy bug allows inflating balance
Re-entrancy guards should be added to all external functions of MarginRouter, and the estimation step should be dropped so registerTrade is called only with the actual amounts returned by the real trade.
Disclosed
-
Missing fromToken != toToken check
The fund withdrawal should be moved to after the starting balance is recorded, and a check should be added to ensure the input and output tokens are different.
Disclosed
-
Several function have no entry check
The project said it would add comments and an extra guard so that one function can only be called from an isolated margin trading contract.
Disclosed
-
maintainer can be pushed out
The report recommends adding authorisation to the liquidate function and reviewing the maintainer punishment scheme.
Disclosed
-
No entry checks in crossSwap[Exact]TokensFor[Exact]Tokens
The functions should be restricted to authorised callers, with the pair and token contents whitelisted or vetted and their array lengths checked to match.
Disclosed