Skip to content

Code4rena

Marginswap

Every publicly disclosed report for Marginswap and what kind of bugs they were.

disclosed reports
19
most reported class
Business logic
bug classes found
4
first disclosure
2021
Find Marginswap on bugbounty.fyi Current scope, rewards and status, if it runs a public program.

Disclosed reports

Newest first. Only what Marginswap chose to make public.

Smart contracts

Price feed can be manipulated

The price feed derives prices by simulating a trade against Uniswap pair reserves, which an attacker can shift drastically with flash loans to produce almost arbitrary prices. Wrong prices break core contract functions such as margin borrowing and liquidations.

Marginswap

High
Business logic

Rewards cannot be withdrawn

Rewards are credited to a margin trader's account but the withdrawal function checks the caller against the incentive reporter role, so the trader can never withdraw. As a result, nobody can withdraw the accrued rewards.

Marginswap

High
Business logic

No default liquidationThresholdPercent

The IsolatedMarginTrading contract lacks a default liquidationThresholdPercent, leaving it at zero. As a result, the belowMaintenanceThreshold function always returns true, allowing anyone to be liquidated immediately.

Marginswap

Medium
Audit finding

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.

MarginSwap's internal price oracle only updates when a borrow or liquidation occurs for an account lending or borrowing that token, so for less popular tokens the price can become stale. An attacker can exploit this by making undercollateralized borrows when the Uniswap price has moved more than 10%, draining funds from the contract.

Marginswap

Medium
Audit finding

PriceAware uses prices from getAmountsOut

The PriceAware contract derives prices from an AMM's getAmountsOut function, whose returned values can be manipulated by an attacker using large capital or flash loans. Peg amount limits reduce but do not fully remove the impact of such manipulation.

Marginswap

Medium
Business logic

Wrong liquidation logic

The liquidation check in a cross-margin lending contract used an inverted comparison, so the condition for being liquidatable was reversed. As a result, healthy traders could be liquidated while under-collateralised traders could not be.

Marginswap

High
Business logic

diffMaxMinRuntime gets default value of 0

A state variable in a smart contract is declared but never initialised or updated, so it keeps its default value of zero. Calculations that use it for bucket indexes or sizes therefore either always return zero when multiplying or fail when dividing.

Marginswap

Medium
Business logic

Add a timelock to functions that set key variables

The owner-controlled functions that set leverage and liquidation threshold percentages could be called at any time, so a user's position could become liquidatable from one block to the next. An attacker with owner access could change these values abruptly to force liquidations.

Marginswap

Medium
Business logic

account.holdsToken is never set

The addHolding function fails to update the holdsToken map, so depositing the same token multiple times pushes duplicate entries into the holdingTokens array. This causes getHoldingAmounts to return the same balance multiple times, allowing an attacker to withdraw more tokens than they deposited and steal funds.

Marginswap

High
Smart contracts

Re-entrancy bug allows inflating balance

The MarginRouter contract trusted token amounts returned by a caller-supplied fake pair contract and credited them before completing the real swap, and the swap callback allowed re-entering the router. An attacker could therefore be credited several times for a single real trade and eventually drain tokens.

Marginswap

High
Business logic

Missing fromToken != toToken check

The contract fails to check that the input and output tokens are different, allowing an attacker to call a swap function with the same token and a fake pair contract that returns zero output. This lets the attacker withdraw funds from the contract without proper accounting, bypassing a time-lock.

Marginswap

High
Access control

Several function have no entry check

The report lists several smart contract functions that appear to lack access checks, suggesting that very large input values might disrupt internal accounting and possibly lock functions or produce wrong rates. The project's response found most functions were already protected or safe by design, but agreed one function deserved an extra guard against a malicious token contract.

Marginswap

Medium
Access control

maintainer can be pushed out

The liquidate function in two contracts can be called by anyone, and repeated calls by an unauthorised address increase the maintainer's failure count. Once the count exceeds a threshold, the maintainer is marked as failing and the attacker can withdraw the maintainer's cut of liquidation revenues.

Marginswap

Medium
Access control

No entry checks in crossSwap[Exact]TokensFor[Exact]Tokens

Two swap functions on the MarginRouter contract lack caller authorisation and do not validate the supplied pair and token arrays. An attacker could trade on behalf of the protocol, supply self-constructed pair contracts to run arbitrary code, and reenter the protocol, potentially losing funds.

Marginswap

Medium
Business logic

Missing checks if pairs equal tokens

Several library and contract functions do not verify that the length of a token path matches the number of tokens, nor that the tokens actually correspond to the pair. An attacker or careless caller could set a faulty liquidation path that causes liquidation transactions to revert.

Marginswap

Medium
DoS

lastUpdatedDay not initialized

The variable lastUpdatedDay in IncentiveDistribution.sol is not initialised, so when updateDayTotals is called it computes a huge day difference and enters a very long loop that runs out of gas. Even if the loop finished, the daily distribution variable would be updated incorrectly, making the incentive distribution inaccurate or non-functional.

Marginswap

High