Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mitigation Confirmed for M-04 #22

Open
code423n4 opened this issue Mar 20, 2023 · 1 comment
Open

Mitigation Confirmed for M-04 #22

code423n4 opened this issue Mar 20, 2023 · 1 comment
Labels
mitigation-confirmed MR-M-04 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Mitigation of M-04: Fully Alleviated

The sponsor implemented the recommended course of action to address this exhibit, evaluating whether the _maxCoupons value has been reached solely when a new coupon is introduced to the exchange. A snippet of the contract with the remediated code showcased can be found below:

/**
 * @notice Sells a bond against KIBToken.
 * @param tokenId Sold bond tokenId.
 */
function sellBond(uint256 tokenId) external override whenNotPaused whenNotDeprecated {
    IKUMAAddressProvider KUMAAddressProvider = _KUMAAddressProvider;
    IKUMABondToken KUMABondToken = IKUMABondToken(KUMAAddressProvider.getKUMABondToken());
    IKUMABondToken.Bond memory bond = KUMABondToken.getBond(tokenId);

    /**
     * MITIGATION BLOCK OF M-04 START
     */

    if (!_coupons.contains(bond.coupon) && _coupons.length() == _maxCoupons) {
        revert Errors.MAX_COUPONS_REACHED();
    }

    /**
     * MITIGATION BLOCK OF M-04 END
     */

    if (bond.riskCategory != _riskCategory) {
        revert Errors.WRONG_RISK_CATEGORY();
    }
    if (bond.maturity <= block.timestamp) {
        revert Errors.CANNOT_SELL_MATURED_BOND();
    }
    IKIBToken KIBToken = IKIBToken(KUMAAddressProvider.getKIBToken(_riskCategory));
    uint256 referenceRate = IMCAGRateFeed(KUMAAddressProvider.getRateFeed()).getRate(_riskCategory);
    if (bond.coupon < referenceRate) {
        revert Errors.COUPON_TOO_LOW();
    }
    if (_coupons.length() == 0) {
        _minCoupon = bond.coupon;
        _coupons.add(bond.coupon);
    } else {
        if (bond.coupon < _minCoupon) {
            _minCoupon = bond.coupon;
        }
        if (!_coupons.contains(bond.coupon)) {
            _coupons.add(bond.coupon);
        }
    }
    _couponInventory[bond.coupon]++;
    _bondReserve.add(tokenId);
    uint256 bondValue = _getBondValue(bond.issuance, bond.term, bond.coupon, bond.principal);
    _bondBaseValue[tokenId] = bondValue.wadToRay().rayDiv(KIBToken.getUpdatedCumulativeYield());
    uint256 fee = _calculateFees(bondValue);
    uint256 mintAmount = bondValue;
    if (fee > 0) {
        mintAmount = bondValue - fee;
        KIBToken.mint(KUMAAddressProvider.getKUMAFeeCollector(_riskCategory), fee);
    }
    KIBToken.mint(msg.sender, mintAmount);
    KUMABondToken.safeTransferFrom(msg.sender, address(this), tokenId);
    emit FeeCharged(fee);
    emit BondSold(tokenId, mintAmount, msg.sender);
}

As such, the contract will correctly permit the sale of a bond whose coupon is already in the _coupons list when the _maxCoupon value has been reached. An accompanying test was introduced to the codebase's KUMASwap.sellBond.t.sol file that ensures the sale of a bond whose coupon is in the list goes through regardless of whether _maxCoupons was reached.

code423n4 added a commit that referenced this issue Mar 20, 2023
@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Mar 23, 2023
@c4-judge
Copy link

GalloDaSballo marked the issue as satisfactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mitigation-confirmed MR-M-04 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants