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
Originally disclosed on Code4rena
The function liquidate (in both CrossMarginLiquidation.sol and IsolatedMarginLiquidation.sol) can be called by everyone. If an attacker calls this repeatedly then the maintainer will be punished and eventually be reported as maintainerIsFailing And then the attacker can take the payouts.
When a non authorized address repeatedly calls liquidate then the following happens: isAuthorized = false which means maintenanceFailures[currentMaintainer] increases. After sufficient calls it will be higher than the threshold and then maintainerIsFailing() will be true. This results in canTakeNow being true, which finally means the following will be executed:
Fund(fund()).withdraw(PriceAware.peg, msg.sender, maintainerCut);
An attacker can push out a maintainer and take over the liquidation revenues.
Recommend put authorization on who can call the liquidate function, review the maintainer punishment scheme.
I believe this issue is not a vulnerability, due to the checks in lines 326-335. Even if someone comes in first and claims the maintainer is failing they can do their job in the same or next block and get all / most of their failure record extinguished.
Acknowledging feedback from @werg, but maintaining the reported risk level of
mediumsince this has implications on token logic.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the liquidate function lacks access control, allowing any caller to increment the maintainer's failure count and trigger a payout to themselves.
What the attacker needed
Ability to call the liquidate function; no special privileges required
The fix
The report recommends adding authorisation to the liquidate function and reviewing the maintainer punishment scheme.
How it was found
- Call the liquidate function repeatedly from a non-authorised address.
- Each call sets isAuthorized to false and increases maintenanceFailures for the current maintainer.
- After enough calls, the failure count exceeds the threshold and maintainerIsFailing becomes true.
- This makes canTakeNow true, causing the contract to withdraw the maintainerCut to the attacker's address.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A maintainer is a trusted role that earns a fee for keeping a system running. The liquidate function, which anyone can call, also records failures for the current maintainer. By calling it many times, an attacker can make the system think the maintainer is failing and then claim the maintainer's fee.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.