Tadle

Tadle
DeFiFoundry
27,750 USDC
View results
Submission Details
Severity: low
Invalid

If Origin Offer or the Sub listed offer is Virgin then Will get always less collateralFee

Summary

The Virgin offer will always get less collateralFee than excepted which leads to loss to Offer Authority.

Vulnerability Details

Note :-

Virgin Check

  1. CloseOffer()

  2. CloseBidOffer()

  3. SettleAskMaker()

Virgin Update

  1. CreateOffer()

  2. ListOffer()

  3. reListOffer()

Settle check

  1. CloseBidTaker()

Settle Update

  1. AbortAskOffer()

  2. SettledAskOffer()

  3. CloseBidOffer()

  4. SettleAskMaker()

The above function will be needed to describe this issue

As we know that sell means ask and buy means bid ordr. Let's consider that CreateTaker() will be called to buy points from the targeted offer. Then the sublisted offer will be created through the listedOffer() function then called the closeOffer() function to close offer which not needed then settleAskMaker() function will be called main issue here in this settleAskOffer() function is called which sets the offer as Settled offer Status until here the offer was Virgin state.

https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/DeliveryPlace.sol#L310C1-L311C1

https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/PreMarkets.sol#L746C1-L746C53

perMarkets.settledAskOffer(
_offer,
_settledPoints,
settledPointTokenAmount
);
// In settledAskOffer()
function settledAskOffer(
address _offer,
uint256 _settledPoints,
uint256 _settledPointTokenAmount
) external onlyDeliveryPlace(tadleFactory, _msgSender()) {
OfferInfo storage offerInfo = offerInfoMap[_offer];
offerInfo.settledPoints = _settledPoints;
offerInfo.settledPointTokenAmount = _settledPointTokenAmount;
offerInfo.offerStatus = OfferStatus.Settled;
emit SettledAskOffer(_offer, _settledPoints, _settledPointTokenAmount);
}

The CloseBidTaker() function will only be called for offers that are in the Settled state, as shown in the code snippet below. Users can only call this function for offers that have entered the settled state. We also need to check that the collateral fee is calculated only if the offer is in the virgin state. However, since it is already in the settled state, it will enter the else block.

if (offerInfo.offerStatus != OfferStatus.Settled) { // @audit check here a
revert InvalidOfferStatus();
}
if (stockInfo.stockStatus != StockStatus.Initialized) {
revert InvalidStockStatus();
}
uint256 collateralFee;
if (offerInfo.usedPoints > offerInfo.settledPoints) {
if (offerInfo.offerStatus == OfferStatus.Virgin) { // @audit check here b
collateralFee = OfferLibraries.getDepositAmount(
offerInfo.offerType,
offerInfo.collateralRate,
offerInfo.amount,
true,
Math.Rounding.Floor
);
} else {
uint256 usedAmount = offerInfo.amount.mulDiv(
offerInfo.usedPoints,
offerInfo.points,
Math.Rounding.Floor
);
collateralFee = OfferLibraries.getDepositAmount(
offerInfo.offerType,
offerInfo.collateralRate,
usedAmount,
true,
Math.Rounding.Floor
);
}
}

The PreOffer or the Offer, once marked as Settled before it is Virgin, will have the collateral fee calculated using the offerInfo.amount. However, closeBidTaker() won't allow this and will always enter the else block. Consequently, the collateral fee amount will be calculated using usedAmount, which will always result in a loss for the user or the authority.

https://github.com/Cyfrin/2024-08-tadle/blob/main/src/core/DeliveryPlace.sol#L143C7-L173C40

Impact

If Origin Offer or the Sub listed offer is Virgin then Will get always less collateralFee due to settled and virgin both check in closeBidTaker() function.

Tools Used

Foundry , Manual View

Recommendations

Implement the addtional varaible to store the offer status before entering into an settled state if the virgin offer entered to settled state means after settle as maker then stored variable can be indicate that it was virgin then the collateral amount will be calculated as intended.

Updates

Lead Judging Commences

0xnevi Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

[invalid] finding-PreMarkets-closeBidTaker-Virgin-Settled-unreachable

Borderline informational/low severity, taker bid offers can only be closed after settlement by original makers, so the check for `Settled` offer status is correct but the initial `if` block is dead code and will never be reached i.e., even if original maker offer was not settled, this issue cannot be exploited. Additionally, makers are incentivized to settle original offers to earn maker bonuses from subsequent trades from the original maker offers by takers. Some issues such as 612, 1774 and 1775 have no impact described but I am duplicating anyways since I am invalidating this issue. Assigning as informational severity since I believe this can be seen as simply a waste of gas and confusing code logic.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.