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

Losing 1 share worth of assets upon deposit #22

Open
MichaelMorami opened this issue Mar 2, 2023 · 1 comment
Open

Losing 1 share worth of assets upon deposit #22

MichaelMorami opened this issue Mar 2, 2023 · 1 comment
Assignees
Labels

Comments

@MichaelMorami
Copy link
Collaborator

MichaelMorami commented Mar 2, 2023

deposit function allows a user to call it with a certain amount of assets, end up transferring more than that amount, and get 1 less share in return.
An example can be seen here (report)

Summary:

Suppose the user calls the deposit function with an asset amount equivalent to anywhere in the range [x.5, x+1) AToken. In that case, the deposit function will round up the amount of Atokens that needs to be transferred from the sender but will round down the number of staticAToken shares the receiver gets in return, i.e. the user send x+1 Atokens, but receive only x staticAtokens.

Detailed Scenario:

  1. User calls deposit function with an asset amount of 9 underlying tokens. The fromUnderlying flag is false so the AToken.transferFrom function is called.

  2. AToken.transferFrom function eventually calls AToken._transfer function. This function converts the user specified underlying asset amount to the number of ATokens by calling the rayDiv function with the current rate and asset amount.

  3. Due to round-up, rayDiv returns 1 AToken, which is equivalent to 18 underlying tokens.

  4. 1 AToken is transferred from the user to the staticAToken contract.

  5. Deposit function proceeds to calculate the shares to be minted to the user. rayDivRoundDown is called with the rate and the asset amount (9). Due to round-down, rayDivRoundDown returns 0.

  6. User gets 0 shares in return for the 1 AToken deposited in the vault.

@PierrickGT
Copy link

Fixed in the following PR I believe: #25

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants