Cancellation refunds should return tokens to order creator, not recipient
The cancellation refund function sends the refund to the order recipient instead of the order creator, even though the creator paid the tokens. An attacker could cancel an order and have the refund go to a different address, causing irreversible loss of funds for the creator.
0x007 Follow with ArmedGoose, Kodyvim and 5 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-06-dinari-judging/issues/61
Found by
0x007, ArmedGoose, Kodyvim, ctf_sec, dirk_y, james_wu, osmanozdemir1, shtesesamoubiq
Summary
When an order is cancelled, the refund is sent to order.recipient instead of the order creator because it is the order creator (requestor) pay the payment token for buy order or pay the dShares for sell order
As is the standard in many L1/L2 bridges, cancelled deposits should be returned to the order creator instead of the recipient. In Dinari's current implementation, a refund acts as a transfer with a middle-man.
Vulnerability Detail
Simply, the _cancelOrderAccounting() function returns the refund to the order.recipient:
function _cancelOrderAccounting(OrderRequest calldata orderRequest, bytes32 orderId, OrderState memory orderState)
internal
virtual
override
{
...
uint256 refund = orderState.remainingOrder + feeState.remainingPercentageFees;
...
if (refund + feeState.feesEarned == orderRequest.quantityIn) {
_closeOrder(orderId, orderRequest.paymentToken, 0);
// Refund full payment
refund = orderRequest.quantityIn;
} else {
// Otherwise close order and transfer fees
_closeOrder(orderId, orderRequest.paymentToken, feeState.feesEarned);
}
// Return escrow
IERC20(orderRequest.paymentToken).safeTransfer(orderRequest.recipient, refund);
}
Refunds should be returned to the order creator in cases where the input recipient was an incorrect address or simply the user changed their mind prior to the order being filled.
Impact
- Potential for irreversible loss of funds
- Inability to truly cancel order
Code Snippet
Tool used
Manual Review
Recommendation
Return the funds to the order creator, not the recipient.
Discussion
bizzyvinci
Escalate
This issue ought to be high because it doesn't require external conditions or specific states for users to lose a significant amount.
It is very likely that msg.sender != recipient cause msg.sender and recipient could be different entities trying to have a deal either EOA-EOA or contract-EOA or contract-contract. Canceling order is meant to be a perfect unwind as mentioned by the sponsor.
This issue affects every single cancelled order, both buy, direct buy and sell orders.
sherlock-admin
Escalate
This issue ought to be high because it doesn't require external conditions or specific states for users to lose a significant amount. It is very likely that
msg.sender != recipientcause msg.sender and recipient could be different entities trying to have a deal either EOA-EOA or contract-EOA or contract-contract. Canceling order is meant to be a perfect unwind as mentioned by the sponsor.This issue affects every single cancelled order, both buy, direct buy and sell orders.
The escalation could not be created because you are not exceeding the escalation threshold.
You can view the required number of additional valid issues/judging contest payouts in your Profile page, in the Sherlock webapp.
jaketimothy
Fixed in
ctf-sec
Fix looks good
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 cancellation function transfers the refund to orderRequest.recipient instead of the order creator (msg.sender).
Impact
Cancelled orders may result in irreversible loss of funds for the order creator, and the cancellation does not truly unwind the order.
What the attacker needed
Order creator and recipient differ; order is cancelled
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 you place an order, you pay tokens upfront. If you cancel, you expect your tokens back. Here, the refund goes to the recipient address on the order, which might not be you, so you could lose your money.
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.