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

Rebasing tokens are not supported #87

Closed
code423n4 opened this issue Jan 30, 2023 · 2 comments
Closed

Rebasing tokens are not supported #87

code423n4 opened this issue Jan 30, 2023 · 2 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-263 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-01-numoen/blob/main/src/core/Lendgine.sol#L144
https://github.com/code-423n4/2023-01-numoen/blob/main/src/core/libraries/Position.sol#L51

Vulnerability details

Impact

Rebasing tokens are not supported. Pool can be insolvent.

Proof of Concept

When depositor accrues interests, his tokensOwed amount is updated inside Position.update function.
https://github.com/code-423n4/2023-01-numoen/blob/main/src/core/libraries/Position.sol#L38-L65

  function update(
    mapping(address => Position.Info) storage self,
    address owner,
    int256 sizeDelta,
    uint256 rewardPerPosition
  )
    internal
  {
    Position.Info storage positionInfo = self[owner];
    Position.Info memory _positionInfo = positionInfo;


    uint256 tokensOwed;
    if (_positionInfo.size > 0) {
      tokensOwed = newTokensOwed(_positionInfo, rewardPerPosition);
    }


    uint256 sizeNext;
    if (sizeDelta == 0) {
      if (_positionInfo.size == 0) revert NoPositionError();
      sizeNext = _positionInfo.size;
    } else {
      sizeNext = PositionMath.addDelta(_positionInfo.size, sizeDelta);
    }


    if (sizeDelta != 0) positionInfo.size = sizeNext;
    positionInfo.rewardPerPositionPaid = rewardPerPosition;
    if (tokensOwed > 0) positionInfo.tokensOwed = _positionInfo.tokensOwed + tokensOwed;
  }

As you can see interests are accrued as newTokensOwed and they are saved as collateral token value that should be paid for user.
Later he can call Lendgine.collect in order to receive interests.
https://github.com/code-423n4/2023-01-numoen/blob/main/src/core/Lendgine.sol#L194-L206

  function collect(address to, uint256 collateralRequested) external override nonReentrant returns (uint256 collateral) {
    Position.Info storage position = positions[msg.sender]; // SLOAD
    uint256 tokensOwed = position.tokensOwed;


    collateral = collateralRequested > tokensOwed ? tokensOwed : collateralRequested;


    if (collateral > 0) {
      position.tokensOwed = tokensOwed - collateral; // SSTORE
      SafeTransferLib.safeTransfer(token1, to, collateral);
    }


    emit Collect(msg.sender, to, collateral);
  }

In case when rebasing token will be used as collateral such approach will not work as at the moment when tokensOwed was increased by value X of rebasing token, this value can become Y < X, when user calls collect. As result he will receive more tokens from the pool that he should. In case if token increased in price, then user will receive less tokens as interests.

Tools Used

VsCode

Recommended Mitigation Steps

I believe that factory should have list if whitelisted tokens that can be used by protocol. Currently any token can be used.

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Jan 30, 2023
code423n4 added a commit that referenced this issue Jan 30, 2023
@c4-judge c4-judge closed this as completed Feb 6, 2023
@c4-judge
Copy link

c4-judge commented Feb 6, 2023

berndartmueller marked the issue as duplicate of #263

@c4-judge
Copy link

berndartmueller marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-263 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants