Flawed Zero-Cost Trade Prevention
The smart contract used a bitwise AND to check for zero-value trades, which incorrectly flags valid trades where the two amounts share no set bits. An attacker could not exploit this; instead, legitimate trades would revert, blocking normal operation.
VulnViper Follow with 0xAura, 0xDeoGratias and 27 others
Originally disclosed on Code4rena
Submitted by VulnViper, also found by 0xAura, 0xDeoGratias, 0xDetermination, 0xhanu58, 0xPhantom, 0xterrah, Almanax, anonymousjoe, axelot, BenRai, boredpukar, ChainSentry, DDEENNY, dhank, EVDoc, Gosho, guri, jerry0422, lirezArAzAvi, lodelux, Neeloy, Pexy, random1106, Riceee, sharonphiliplima, solhhj, Tofu, v2110, and Zibounne
clob/CLOB.sol#L503-L505clob/CLOB.sol#L544-L546
In CLOB.sol, the validation logic incorrectly uses bitwise operations to detect zero-value trades, creating two critical issues: If baseTokenAmountReceived = 1 and quoteTokenAmountSent = 2, then baseTokenAmountReceived & quoteTokenAmountSent = 0.
https://github.com/code-423n4/2025-07-gte-clob/blob/main/contracts/clob/CLOB.sol#L503-L505
@> if (baseTokenAmountReceived != quoteTokenAmountSent && baseTokenAmountReceived & quoteTokenAmountSent == 0) {
revert ZeroCostTrade();
}
https://github.com/code-423n4/2025-07-gte-clob/blob/main/contracts/clob/CLOB.sol#L544-L546
@> if (baseTokenAmountSent != quoteTokenAmountReceived && baseTokenAmountSent & quoteTokenAmountReceived == 0) {
revert ZeroCostTrade();
}
Impact
Occurrence Probability: Low (requires specific value alignment)
Operational Impact: High (instant revert blocks valid trade)
Recommended Mitigation Steps
- if (baseTokenAmountReceived != quoteTokenAmountSent && baseTokenAmountReceived & quoteTokenAmountSent == 0) {
+ if (baseTokenAmountReceived != quoteTokenAmountSent && (baseTokenAmountReceived == 0 || quoteTokenAmountSent == 0)) {
revert ZeroCostTrade();
}
- if (baseTokenAmountSent != quoteTokenAmountReceived && baseTokenAmountSent & quoteTokenAmountReceived == 0) {
+ if (baseTokenAmountSent != quoteTokenAmountReceived && (baseTokenAmountSent == 0 || quoteTokenAmountReceived == 0)) {
revert ZeroCostTrade();
}
View detailed Proof of Concept
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
Likely the developer used a bitwise AND instead of a logical OR to test whether either amount was zero.
Impact
Valid trades could revert, blocking normal trading, but the text does not claim any theft or loss of funds.
What the attacker needed
None
The fix
The check should be replaced with a logical OR comparing each amount to zero, as shown in the mitigation.
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 is a program on a blockchain. It used a bitwise AND (a way to compare binary digits) to check if either trade amount was zero, but that check wrongly rejects trades where the two numbers have no overlapping 1-bits. This means some normal trades fail and are blocked.
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.