-
Notifications
You must be signed in to change notification settings - Fork 0
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
The Vault data total_shares_minted can be manipulated #49
Comments
Thank you for your submission, but I couldn't figure out the impact. |
In my opinion it is a logical error to update the total_shares_minted before actually successfully minting them. Assuming we have total_shares_minted = N and we initiate the minting of M shares: what the current version of the code is doing is to update total_shares_minted = N+M and then trigger the minting. The minting could fail (which is effectively handled by an early exit). In this case total_shares_minted would be incorrect by as much as M shares. What I propose is to do the minting first and then update the number of total_shares_minted by the amount of successfully minted shares. The total_shares_minted is used in various material calculations and I think we should ensure it is accurate all the time. More generally, does this mean you are not interested in similar logic-related issues which do not confirm the impact explicitly? (I am new to competitions and still figuring out what are the expectations) |
i couldn't completely understand you, could you please provide me with more details and scenarios and a link to code. |
Yes, I will share more details later today when I get access to my PC. I have included the relevant code snippets in my submission to illustrate before (PoC) and after (Revised code). Calling the mint method on the shared token can fail because of authorisation issues (unlikely in the current code version) and a PSP22Error (possible to encounter in the current code version). In the latter case, the minting won't be successful, but total_shares_minted will be updated as if the minting was successful. |
if a transaction reverts, all state changes will revert to the state before that transaction.
if the process of minting reverts, total_shares_minted will revert as well. the steps in this case aren't important, if any step reverts all steps before that revert as well. |
I see, thanks for clarifying. I was thinking around the line illustrated in the following simplified snippet: if a public method returns an error, it is up to the consumer of this public method to decide what they do with the error. Hence, it all boils down to the lifetime of the Vault/Vault Data objects. In both test functions below we keep the vault/vault data alive after the error is encountered and in test_mint_shares we end up incorrectly counting the unsuccessfully minted shares, whereas in test_mint_shares_revised we only account for the successfully minted shares.
|
@veselinas if a function in ink! panics or returns error the state of the contract is not changed |
Github username: --
Twitter username: --
Submission hash (on-chain): 0x9e3fb92c28d2f53f2f5379f7cfd275c36695d90da1c00289f181fded901f8c3c
Severity: low
Description:
Description
In src/vault/lib.rs, the Vault's method mint_shares increments the total_shares_minted on the Vault data before actually minting them. The minting process (token.mint) can fail in which case the total_shares_minted will be incorrect. Similarly for the burn_shares method. This exposes future versions of the code to manipulation of the total number of minted shares with a direct impact on the redemption ratio.
Attack Scenario
When Self::env().caller() is different from the token owner, then token.mint would return an error. Alternatively, we could encounter a PSP22Error during the minting process itself. Both cases effectively imply that the tokens won't be minted. However, inside mint_shares the total_shares_minted was already incremented. Hence, the total_shares_minted will be incorrect. This has direct impact on the redemption ration. The same holds for token.burn where early exit with error is also possible, leading to an unsuccessful burn after the total_shares_minted have already been reduced inside burn_shares.
Attachments
Proof of Concept (PoC) File
Revised Code File (Optional)
Replacing the order in which these two operations take place is sufficient to make these methods more robust.
The text was updated successfully, but these errors were encountered: