# addNewTranche() no authorization from borrower

Gondi's addNewTranche() only verifies the lender's signature, letting any lender append a malicious tranche with arbitrary APR and fee to a borrower's loan.

- Payout: Audit contest
- Severity: high
- Program: Gondi
- Found by: bin2chen
- Disclosed: 2024-07-25
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-04-gondi-findings/issues/29
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-gondi%3AH-12
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:access-control vuln:business-logic

**Target:** Gondi lending contract addNewTranche()
**Root cause:** addNewTranche() checks only the lender's signature via _checkSignature and never verifies msg.sender is the borrower, so any lender can unilaterally modify a loan by adding a tranche.
**Steps:**
1. Attacker (any lender) crafts a RenegotiationOffer for a victim's loanId with very high APR and fee == principalAmount.
2. Sign the offer as lender and call `addNewTranche(_renegotiationOffer, _loan, _renegotiationOfferSignature)`.
3. Contract passes _baseLoanChecks, _baseRenegotiationChecks and _checkSignature (lender sig valid), then _addNewTranche appends the malicious tranche and transfers principalAmount - fee to borrower.
4. Borrower's loan is now bound to the attacker-chosen tranche terms.
**How found:** Code review of addNewTranche() noticing only _checkSignature(lender) is enforced and no msg.sender == borrower check exists, unlike expected borrower-initiated flow.
**Exploitation:** Any lender calls addNewTranche on a victim's loan with a self-signed renegotiation offer setting an arbitrarily high APR and fee equal to principalAmount, forcing the borrower into unfavorable tranche terms without consent.
**Insight:** In refinancing/tranche functions, verify which party is authorized to mutate loan terms; a valid counterparty signature is not the same as consent from the party whose debt terms change.

## Proof of concept (copied exactly from the original report)

**addNewTranche function missing borrower authorization check**

```
function addNewTranche(
        RenegotiationOffer calldata _renegotiationOffer,
        Loan memory _loan,
        bytes calldata _renegotiationOfferSignature
    ) external nonReentrant returns (uint256, Loan memory) {
        uint256 loanId = _renegotiationOffer.loanId;

        _baseLoanChecks(loanId, _loan);
        _baseRenegotiationChecks(_renegotiationOffer, _loan);
@>      _checkSignature(_renegotiationOffer.lender, _renegotiationOffer.hash(), _renegotiationOfferSignature);
        if (_loan.tranche.length == getMaxTranches) {
            revert TooManyTranchesError();
        }

        uint256 newLoanId = _getAndSetNewLoanId();
        Loan memory loanWithTranche = _addNewTranche(newLoanId, _loan, _renegotiationOffer);
        _loans[newLoanId] = loanWithTranche.hash();
        delete _loans[loanId];

        ERC20(_loan.principalAddress).safeTransferFrom(
            _renegotiationOffer.lender, _loan.borrower, _renegotiationOffer.principalAmount - _renegotiationOffer.fee
        );
        if (_renegotiationOffer.fee > 0) {
            /// @dev Cached
            ProtocolFee memory protocolFee = _protocolFee;
            ERC20(_loan.principalAddress).safeTransferFrom(
                _renegotiationOffer.lender,
                protocolFee.recipient,
                _renegotiationOffer.fee.mulDivUp(protocolFee.fraction, _PRECISION)
            );
        }

        emit LoanRefinanced(
            _renegotiationOffer.renegotiationId, loanId, newLoanId, loanWithTranche, _renegotiationOffer.fee
        );

        return (newLoanId, loanWithTranche);
    }
```

