Orders from other market makers can be invalidated
The checkOrder() function marks an order's nonce as used, so anyone can invalidate a pre-signed order by calling it. An attacker could front-run orders submitted to the auction functions and cause those auctions to fail.
bin2chen Follow with hyh, hansfriese and 20 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-11-opyn-judging/issues/6
Found by
bin2chen, hyh, hansfriese, aviggiano, caventa, thec00n, indijanc, rotcivegaf, kaliberpoziomka, chainNue, John, adriro, Atarpara, cccz, __141345__, Haruxe, zimu, minhtrng, HonorLt, ctf_sec, imare, reassor, jonatascm
Summary
The checkOrder() function performs verification of pre-signed orders. This function allows anyone to set the status of an order as used by storing the nonce contained in the order. Orders and their respective nonce can only be used once.
Vulnerability Detail
The _useNonce() function is called as called as part of the checkOrder() function. It checks that the nonce of a trader has not already been used, marks the nonce as used and performs other order verification checks. Orders and their respective nonce are also checked by the same implementation as part of the auction functions withdrawAuction() and depositAuction(). An order that has been invalidated once can not be used anymore and by calling checkOrder() any user can invalidate existing orders.
Impact
A malicious user could perform a grieving attack and invalidate any presigned orders by monitoring the mempool and front run any orders that are submitted to withdrawAuction() and depositAuction() and send them to checkOrder(). One invalidated order can cause the auction functions to fail.
Code Snippet
https://github.com/sherlock-audit/2022-11-opyn/blob/main/crab-netting/src/CrabNetting.sol#L447-L476
https://github.com/sherlock-audit/2022-11-opyn/blob/main/crab-netting/src/CrabNetting.sol#L756-L759
Tool used
Manual Review
Recommendation
1.) Change the checkOrder() and _checkOrder() to a view function
2.) Remove _useNonce() from _checkOrder()
3.) Use _useNonce() and _checkOrder() in withdrawAuction() and depositAuction()
Discussion
sanandnarayan
fix https://github.com/opynfinance/squeeth-monorepo/pull/806
thec00n
Fix lgtm.
SecurityDat
Escalate for 10 USDC
I have two issues classfied to https://github.com/sherlock-audit/2022-11-opyn-judging/issues/60. I think one of them (https://github.com/sherlock-audit/2022-11-opyn-judging/issues/51) is exactly about this issue https://github.com/sherlock-audit/2022-11-opyn-judging/issues/6.
Please rejudge https://github.com/sherlock-audit/2022-11-opyn-judging/issues/51. It is about submitting calls to checkorder() to make orders from other market makers invalid.
sherlock-admin
Escalate for 10 USDC
I have two issues classfied to https://github.com/sherlock-audit/2022-11-opyn-judging/issues/60. I think one of them (https://github.com/sherlock-audit/2022-11-opyn-judging/issues/51) is exactly about this issue https://github.com/sherlock-audit/2022-11-opyn-judging/issues/6.
Please rejudge https://github.com/sherlock-audit/2022-11-opyn-judging/issues/51. It is about submitting calls to
checkorder()to make orders from other market makers invalid.
You've created a valid escalation for 10 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.
kaliberpoziomka
Escalate for 10 USDC
The issue #132 I've submitted was classified to #60. I think it is this issue #6.
Please rejudge #132, since it is about function checkOrder(....) marking nonces as used.
sherlock-admin
Escalate for 10 USDC The issue #132 I've submitted was classified to #60. I think it is this issue #6. Please rejudge #132, since it is about function
checkOrder(....)marking nonces as used.
You've created a valid escalation for 10 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.
hrishibhat
Escalation accepted
sherlock-admin
Escalation accepted
This issue's escalations have been accepted!
Contestants' payouts and scores will be updated according to the changes made on this issue.
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 order-checking function both verifies and consumes the nonce, so a read-only check has a side effect that invalidates the order.
Impact
A malicious user could perform a grieving attack and invalidate any presigned orders, causing the auction functions to fail.
What the attacker needed
Access to the mempool; ability to front-run transactions
The fix
The checkOrder() and _checkOrder() functions should be view functions, _useNonce() should be removed from _checkOrder(), and _useNonce() and _checkOrder() should be used in withdrawAuction() and depositAuction().
How it was found
- Monitor the mempool for orders submitted to withdrawAuction() or depositAuction().
- Front-run the order by sending it to checkOrder().
- The nonce is marked as used, so the original auction call fails.
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 nonce is a one-time number that stops the same order being used twice. Here, a function meant only to check an order also permanently marks its nonce as used, so anyone can burn someone else's order before it is used.
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.