Skip to content
Business logic Audit finding Intermediate

liquidationAccountant can be claimed at any time

The liquidation accountant's claim function checks a final auction timestamp that was set to the auction duration rather than the actual end time, so the check always passes. Anyone could call claim before the auction finished, corrupting the vault's accounting.

obront Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-astaria-judging/issues/46

Found by

obront

Summary

New liquidations are sent to the liquidationAccountant with a finalAuctionTimestamp value, but the actual value that is passed in is simply the duration of an auction. The claim() function uses this value in a require check, so this error will allow it to be called before the auction is complete.

Vulnerability Detail

When a lien is liquidated, AstariaRouter.sol:liquidate() is called. If the lien is set to end in a future epoch, we call handleNewLiquidation() on the liquidationAccountant.

One of the values passed in this call is the finalAuctionTimestamp, which updates the finalAuctionEnd variable in the liquidationAccountant. This value is then used to protect the claim() function from being called too early.

However, when the router calls handleLiquidationAccountant(), it passes the duration of an auction rather than the final timestamp:

Solidity
LiquidationAccountant(accountant).handleNewLiquidation(
  lien.amount,
  COLLATERAL_TOKEN.auctionWindow() + 1 days
);

As a result, finalAuctionEnd will be set to 259200 (3 days).

When claim() is called, it requires the final auction to have ended for the function to be called:

Solidity
require(
  block.timestamp > finalAuctionEnd || finalAuctionEnd == uint256(0),
  "final auction has not ended"
);

Because of the error above, block.timestamp will always be greater than finalAuctionEnd, so this will always be permitted.

Impact

Anyone can call claim() before an auction has ended. This can cause many problems, but the clearest is that it can ruin the protocol's accounting by decreasing the Y intercept of the vault.

For example, if claim() is called before the auction, the returned value will be 0, so the Y intercept will be decreased as if there was an auction that returned no funds.

Code Snippet

https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/AstariaRouter.sol#L407-L410

https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/LiquidationAccountant.sol#L113-L120

https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/LiquidationAccountant.sol#L65-L69

Tool used

Manual Review

Recommendation

Adjust the call from the router to use the ending timestamp as the argument, rather than the duration:

Solidity
LiquidationAccountant(accountant).handleNewLiquidation(
  lien.amount,
  block.timestamp + COLLATERAL_TOKEN.auctionWindow() + 1 days
);

Discussion

IAmTurnipBoy

Escalate for 1 USDC

Touched on the same idea as #135. Tough call on duplication. This issue + #47 combine represent the same vulnerability fixed in both #135 and #188. In this issue it addresses being called too early and in #47 it addresses being called multiple times. The fix proposed in #135 and #188 address both issues by permissioning the function. IMHO this and 47 should be duped with #135 and #188, but up to judges.

ALSO little bit of a conflict of interest that @zobront validated his own issue here.

sherlock-admin

Escalate for 1 USDC

Touched on the same idea as #135. Tough call on duplication. This issue + #47 combine represent the same vulnerability fixed in both #135 and #188. In this issue it addresses being called too early and in #47 it addresses being called multiple times. The fix proposed in #135 and #188 address both issues by permissioning the function. IMHO this and 47 should be duped with #135 and #188, but up to judges.

ALSO little bit of a conflict of interest that @zobront validated his own issue here.

You've created a valid escalation for 1 USDC!

To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

Evert0x

Escalation accepted.

#135 and #188 are already duplicates. This issue and #47 touch on the same core issue that claim() is not safe to be publicly callable.

sherlock-admin

Escalation accepted.

#135 and #188 are already duplicates. This issue and #47 touch on the same core issue that claim() is not safe to be publicly callable.

This issue's escalations have been accepted!

Contestants' payouts and scores will be updated according to the changes made on this issue.

zobront

Escalate for 5 USDC

This isn’t a dup of #135 or #188. Those two issues are talking about access control for the function. This calls out that there is a specific time enforcement mechanism (finalAuctionTimestamp) that is calculated incorrectly, allowing it to be called early.

Yes, I agree that adding access controls (their solution) would reduce the harm from this issue, but they are unrelated issues that just happen to have overlapping solutions. The real solution to this one is to do the calculation properly.

NOTE: The other issue of mine that was dup’d with these is #47, which focuses on that there aren’t restrictions to stop claim() being called multiple times. I probably wouldn’t consider that a dup of theirs either, but it’s on the fence so I’m ok with it — but this one is clearly different.

sherlock-admin

Escalate for 5 USDC

This isn’t a dup of #135 or #188. Those two issues are talking about access control for the function. This calls out that there is a specific time enforcement mechanism (finalAuctionTimestamp) that is calculated incorrectly, allowing it to be called early.

Yes, I agree that adding access controls (their solution) would reduce the harm from this issue, but they are unrelated issues that just happen to have overlapping solutions. The real solution to this one is to do the calculation properly.

NOTE: The other issue of mine that was dup’d with these is #47, which focuses on that there aren’t restrictions to stop claim() being called multiple times. I probably wouldn’t consider that a dup of theirs either, but it’s on the fence so I’m ok with it — but this one is clearly different.

You've created a valid escalation for 5 USDC!

To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

Evert0x

Escalation accepted. at the initial escalation we misinterpreted the https://github.com/sherlock-audit/2022-10-astaria-judging/issues/135 / https://github.com/sherlock-audit/2022-10-astaria-judging/issues/188 as it was thought they described both issues.

sherlock-admin

Escalation accepted. at the initial escalation we misinterpreted the https://github.com/sherlock-audit/2022-10-astaria-judging/issues/135 / https://github.com/sherlock-audit/2022-10-astaria-judging/issues/188 as it was thought they described both issues.

This issue's escalations have been accepted!

Contestants' payouts and scores will be updated according to the changes made on this issue.

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

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

The router passed the auction duration instead of the final timestamp when initialising the liquidation accountant, so the time check in claim always succeeded.

Impact

Anyone could call claim before the auction ended, which could ruin the protocol's accounting by decreasing the vault's Y intercept as if an auction had returned no funds.

What the attacker needed

A lien is liquidated; no special access needed

The fix

The router should pass the ending timestamp (block.timestamp plus the auction window plus one day) rather than the duration.

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.

When a loan is liquidated, the protocol starts an auction and records when it should end. A function that lets someone claim the auction proceeds is supposed to wait until that end time. Here the recorded time was just the length of the auction (a few days) instead of the actual end date, so the wait check always passed and anyone could claim early.

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 by obront

View all

46 more disclosed reports, best first.

More from Astaria

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.