setSymbolsPrice() can use the priceSig from a long time ago
The setSymbolsPrice function only checks that the price signature timestamp is not too far in the future, but does not check that it is recent enough. An attacker could reuse an old price signature with a large negative unrealised profit and loss value to trigger a liquidation of partyB.
Ruhum Follow with berndartmueller, bin2chen and 10 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-06-symmetrical-judging/issues/113
Found by
Ruhum, berndartmueller, bin2chen, cergyk, kutugu, libratus, mstpr-brainbot, pengun, rvierdiiev, shaka, simon135, sinarette, xiaoming90
Summary
setSymbolsPrice() only restricts the maximum value of priceSig.timestamp, but not the minimum time
This allows a malicious user to choose a malicious priceSig from a long time ago
A malicious priceSig.upnl can seriously harm partyB
Vulnerability Detail
setSymbolsPrice() only restricts the maximum value of priceSig.timestamp, but not the minimum time
function setSymbolsPrice(address partyA, PriceSig memory priceSig) internal {
MAStorage.Layout storage maLayout = MAStorage.layout();
AccountStorage.Layout storage accountLayout = AccountStorage.layout();
@> LibMuon.verifyPrices(priceSig, partyA);
require(
@> priceSig.timestamp <=
maLayout.liquidationTimestamp[partyA] + maLayout.liquidationTimeout,
"LiquidationFacet: Expired signature"
);
LibMuon.verifyPrices only check sign, without check the time range
function verifyPrices(PriceSig memory priceSig, address partyA) internal view {
MuonStorage.Layout storage muonLayout = MuonStorage.layout();
require(priceSig.prices.length == priceSig.symbolIds.length, "LibMuon: Invalid length");
bytes32 hash = keccak256(
abi.encodePacked(
muonLayout.muonAppId,
priceSig.reqId,
address(this),
partyA,
priceSig.upnl,
priceSig.totalUnrealizedLoss,
priceSig.symbolIds,
priceSig.prices,
priceSig.timestamp,
getChainId()
)
);
verifyTSSAndGateway(hash, priceSig.sigs, priceSig.gatewaySignature);
}
In this case, a malicious user may pick any priceSig from a long time ago, and this priceSig may have a large negative unpl, leading to LiquidationType.OVERDUE, severely damaging partyB
We need to restrict priceSig.timestamp to be no smaller than maLayout.liquidationTimestamp[partyA] to avoid this problem
Impact
Maliciously choosing the illegal PriceSig thus may hurt others user
Code Snippet
Tool used
Manual Review
Recommendation
restrict priceSig.timestamp to be no smaller than maLayout.liquidationTimestamp[partyA]
function setSymbolsPrice(address partyA, PriceSig memory priceSig) internal {
MAStorage.Layout storage maLayout = MAStorage.layout();
AccountStorage.Layout storage accountLayout = AccountStorage.layout();
LibMuon.verifyPrices(priceSig, partyA);
require(maLayout.liquidationStatus[partyA], "LiquidationFacet: PartyA is solvent");
require(
priceSig.timestamp <=
maLayout.liquidationTimestamp[partyA] + maLayout.liquidationTimeout,
"LiquidationFacet: Expired signature"
);
+ require(priceSig.timestamp >= maLayout.liquidationTimestamp[partyA],"invald price timestamp");
Discussion
MoonKnightDev
Fixed code PR link: https://github.com/SYMM-IO/symmio-core/pull/22
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 contract fails to enforce a lower bound on the price signature timestamp, allowing old signatures to be reused.
Impact
A malicious user could choose an old price signature with a large negative unrealised profit and loss, potentially causing a liquidation that harms partyB.
What the attacker needed
Access to a valid old price signature
The fix
The fix is to require that the price signature timestamp is not earlier than the liquidation timestamp for partyA.
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 smart contract function that sets prices for liquidation accepts a signed price update but only checks that the timestamp is not too far in the future. It does not check that the timestamp is recent, so someone can reuse an old signed price that shows a big loss and cause an unfair liquidation.
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.