fix: verify real token-balance delta in TokenVault deposit/withdraw - #476
Open
Promessa1 wants to merge 3 commits into
Open
Conversation
|
@Promessa1 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR fixes the
TokenVaultbalance-tracking bug by makingdeposit()andwithdraw()verify the real token-balance delta before updating the trackedBalancekey, mirroringDripFactory::create_stream. The vault now readstk.balance(contract)before and after eachtoken::transferand records only the observed delta in storage — if the transfer didn't move exactly the expected funds (fee-on-transfer, rebasing, or failure), the operation reverts with a dedicated error, so the tracked balance can never drift above the real on-chain balance.Related Issue
Closes the reported bounty issue: Bug:
TokenVault::deposit/withdrawdon't verify the real token-balance delta (unlikeDripFactory::create_stream)Changes
🔍 Real-Balance Verification in TokenVault
[MODIFY]
contracts/token-vault/src/lib.rsdeposit(): snapshottk.balance(contract)before and after the transfer, then updateBalancefrom the observed delta instead of the nominalamount; returnError::DepositTransferFailedwhen the delta doesn't match.withdraw(): snapshottk.balance(contract)before and after the transfer, then updateBalancefrom the observed delta instead of the requestedamount; returnError::WithdrawTransferFailedwhen the token sends less than expected.[MODIFY]
contracts/token-vault/src/errors.rsError::WithdrawTransferFailed(and reuse/exportError::DepositTransferFailed) so both vault paths report balance-delta verification failures without panicking inside the SAC.[MODIFY]
contracts/token-vault/src/storage.rsBalancehelpers to apply a verified on-chain delta rather than blindlychecked_add/checked_sub; document the invariant that tracked balance must never exceed the real token balance.Verification Results
depositupdates trackedBalancefrom the real token-balance deltawithdrawupdates trackedBalancefrom the real token-balance deltaCloses #411