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

Wrong shareChange() function (vToken.sol) #26

Open
code423n4 opened this issue Apr 21, 2022 · 3 comments
Open

Wrong shareChange() function (vToken.sol) #26

code423n4 opened this issue Apr 21, 2022 · 3 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

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/vToken.sol#L160

Vulnerability details

Impact

Users can get the wrong amount of vToken
=> Make users lose their fund

Proof of Concept

Base on the code in function shareChange() in vToken.sol
Assume that if oldShare = totalSupply > 0,

  • newShares
    = (_amountInAsset * (_totalSupply - oldShares)) / (_assetBalance - availableAssets);
    = (_amountInAsset * (_totalSupply - _totalSupply)) / (_assetBalance - availableAssets);
    = 0

It make no sense, because if amountInAsset >> availableAssets, newShares should be bigger than oldShares, but in this case newShares = 0 < oldShares

Tools Used

manual review

Recommended Mitigation Steps

Modify the line from if (_totalSupply > 0) to if (_totalSupply - oldShares > 0)

@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 Apr 21, 2022
code423n4 added a commit that referenced this issue Apr 21, 2022
@olivermehr olivermehr added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label May 2, 2022
@jn-lp
Copy link
Collaborator

jn-lp commented May 13, 2022

Such a case is considered impossible due to the fact that it can only work with a 0xdead address

@moose-code
Copy link
Collaborator

Agree its not an issue as on initialization tokens are sent to the burn address making this unlikely.
image

However the orderer role could possibly burn the tokens held by the burn address causing this issue to happen

@JasoonS
Copy link
Collaborator

JasoonS commented May 25, 2022

Agree with mitigation step:

Modify the line from if (_totalSupply > 0) to if (_totalSupply - oldShares > 0)

If it were impossible for tokens to be burned from the 0xdead address then this wouldn't be a concern.

So although extremely unlikely, this is valid.

@JasoonS JasoonS removed the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label May 25, 2022
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
Projects
None yet
Development

No branches or pull requests

5 participants