Skip to content
Business logic Audit finding Intermediate

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

Originally disclosed on Code4rena

Functions like setLeveragePercent and setLiquidationThresholdPercent for both IsolatedMarginTrading and CrossMarginTrading should be put behind a timelock because they would give more trust to users. Currently, the owner could call them whenever they want and a position could become liquidable from a block to the other.

werg (Marginswap) acknowledged:

Timelock will be handled by governance

zscole commented:

Maintaining submission rating of 2 (Med Risk) because this presents a vulnerability at the time of review.

The original report as published on Code4rena. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 sensitive setter functions had no delay between being called and taking effect, so the owner could change risk parameters instantly.

Impact

A position could become liquidatable immediately after the owner changes a parameter, with no time for users to react; the report notes this is a trust and centralisation risk rather than a directly exploitable bug.

What the attacker needed

Owner or governance privileges

The fix

The setters should be placed behind a timelock so parameter changes are announced in advance; the project said governance would handle this.

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.

Some smart contracts have an owner who can change important settings. Here the owner could change the rules about when a trade gets closed out for losing too much, with no warning. That means a trader could suddenly be at risk of losing their position because of a decision made in the same moment.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from Marginswap

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.