Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

kutugu - The vault interest was miscalculated #38

Closed
sherlock-admin opened this issue Jul 5, 2023 · 0 comments
Closed

kutugu - The vault interest was miscalculated #38

sherlock-admin opened this issue Jul 5, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Jul 5, 2023

kutugu

high

The vault interest was miscalculated

Summary

_update_debt implementation error, can not realize the interest calculation, interest is always zero.

Vulnerability Detail

@internal
def _update_debt(_debt_token: address):
    """
    @notice
        Accounts for any accrued interest since the last update.
    """
    if block.timestamp == self.last_debt_update[_debt_token]:
        return  # already up to date, nothing to do

    self.last_debt_update[_debt_token] = block.timestamp
    
    if self.total_debt_amount[_debt_token] == 0:
        return # no debt, no interest

    self.total_debt_amount[_debt_token] += self._debt_interest_since_last_update(
        _debt_token
    )

@internal
@view
def _debt_interest_since_last_update(_debt_token: address) -> uint256:
    return (
        (block.timestamp - self.last_debt_update[_debt_token])
        * self._current_interest_per_second(_debt_token)
        * self.total_debt_amount[_debt_token]
        / PERCENTAGE_BASE
        / PRECISION
    )

_update_debt will set self.last_debt_update[_debt_token] = block.timestamp, so _debt_interest_since_last_update always return 0

Impact

Unable to achieve interest calculation, users can borrow interest-free, affecting the protocol and staking users income.
This will also affect the internal accounting system, because amount_per_debt_share / debt_shares_to_amount all contain correctly calculated interest, which will lead to bookkeeping confusion.

Code Snippet

Tool used

Manual Review

Recommendation

Calculate the interest first, and then update 'self.last_debt_update[_debt_token] = block.timestamp'

Duplicate of #167

@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Jul 10, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Jul 19, 2023
@sherlock-admin2 sherlock-admin2 added High A valid High severity issue and removed Medium A valid Medium severity issue labels Aug 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

2 participants