-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a475d3
commit c276a15
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Title | ||
`state::update_token_balance` in interchain-token-service reports an incorrect error | ||
|
||
## Description | ||
In case of an underflow, the error is wrongly reported as `Error::MissingConfig`. Instead the error reported should be `Error::InsufficientBalance`. | ||
|
||
```solidity | ||
pub fn update_token_balance( | ||
storage: &mut dyn Storage, | ||
token_id: TokenId, | ||
chain: ChainName, | ||
amount: Uint256, | ||
is_deposit: bool, | ||
) -> Result<(), Error> { | ||
let key = TokenChainPair { token_id, chain }; | ||
let token_balance = TOKEN_BALANCES.may_load(storage, key.clone())?; | ||
match token_balance { | ||
Some(TokenBalance::Tracked(balance)) => { | ||
let token_balance = if is_deposit { | ||
balance | ||
.checked_add(amount) | ||
.map_err(|_| Error::MissingConfig)? | ||
} else { | ||
balance | ||
.checked_sub(amount) | ||
.map_err(|_| Error::MissingConfig)? //@audit -> wrong error | ||
} | ||
.then(TokenBalance::Tracked); | ||
TOKEN_BALANCES.save(storage, key.clone(), &token_balance)?; | ||
} | ||
Some(_) | None => (), | ||
} | ||
Ok(()) | ||
} | ||
``` |