KUMASwap incorrectly reverts when when _maxCoupons has been reached
The KUMASwap contract reverts all bond sales once the number of unique coupons reaches the maximum, even if the bond being sold has a coupon that already exists. This prevents legitimate sales of bonds with existing coupons.
if (_coupons.length() == _maxCoupons) {
revert Errors.MAX_COUPONS_REACHED();
}
The above lines will cause ALL bonds sales to revert when _coupons.length has reached _maxCoupons. Since bonds may share the same coupon, the swap should continue to accept bonds with a coupon that already exist in the _coupons set.
Recommended Mitigation Steps
sellBond should only revert if the max length has been reached and bond.coupon doesn’t already exist:
- if (_coupons.length() == _maxCoupons) {
+ if (_coupons.length() == _maxCoupons && !_coupons.contains(bond.coupon)) {
revert Errors.MAX_COUPONS_REACHED();
}
The warden has shown a way in which the system could stop selling coupons due to the handling of duplicate coupons, this relies on a specific condition which may not always happen, for this reason, in lack of an attack that can be used to break the functionality, I agree with Medium Severity.
The original report as published on Code4rena, by 0x52. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
The check for maximum coupons does not account for the possibility that the bond's coupon already exists in the set, causing an unnecessary revert.
What the attacker needed
The contract must have reached the maximum number of…; A bond with an existing coupon must be available for sale.
The fix
The check should only revert if the maximum is reached and the bond's coupon is not already in the set.
How it was found
Sell a bond to add its coupon to the set.
Issue and sell 364 more bonds with unique coupons, reaching the maximum of 365 coupons.
Attempt to sell another bond that has the same coupon as the first bond.
The transaction reverts with MAX_COUPONS_REACHED error.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A smart contract for swapping bonds has a limit on how many different coupons it can track. When that limit is reached, it stops accepting any new bond sales, even if the bond's coupon is already known. This means users cannot sell bonds that should be allowed.
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.