Skip to content

Commit c45d73b

Browse files
authored
Merge pull request #189 from 0xcellmint/master
Update Not So Cosmos for Miss Error Handler
2 parents 9b770b1 + f2b88ab commit c45d73b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

not-so-smart-contracts/cosmos/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Each _Not So Smart Cosmos_ includes a standard set of information:
2424
| [Broken bookkeeping](broken_bookkeeping) | Exploit mismatch between different modules' views on balances |
2525
| [Rounding errors](rounding_errors) | Bugs related to imprecision of finite precision arithmetic |
2626
| [Unregistered message handler](unregistered_msg_handler) | Broken functionality because of unregistered msg handler |
27-
27+
| [Missing error handler](missing_error_handler) | Missing error handling leads to successful execution of a transaction that should have failed |
2828
## Credits
2929

3030
These examples are developed and maintained by [Trail of Bits](https://www.trailofbits.com/).
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Missing error handler
2+
3+
The idiomatic way of handling errors in `Go` is to compare the returned error to nil. This way of checking for errors gives the programmer a lot of control. However, when error handling is ignored it can also lead to numerous problems. The impact of this is most obvious in method calls in the `bankKeeper` module, which even causes some accounts with insufficient balances to perform `SendCoin` operations normally without triggering a transaction failure.
4+
5+
6+
## Example
7+
In the following code, `k.bankKeeper.SendCoins(ctx, sender, receiver, amount)` does not have any return values being used, including `err`. This results in `SendCoin` not being able to prevent the transaction from executing even if there is an `error` due to insufficient balance in `SendCoin`.
8+
```golang
9+
func (k msgServer) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.MsgTransferResponse, error) {
10+
...
11+
k.bankKeeper.SendCoins(ctx, sender, receiver, amount)
12+
...
13+
return &types.MsgTransferResponse{}, nil
14+
}
15+
```
16+
## Mitigations
17+
18+
- Implement the error handling process instead of missing it
19+
20+
## External examples
21+
- [ignite's tutorials](https://github.com/ignite/cli/issues/2828).
22+
- [Fadeev's Loan Project](https://github.com/fadeev/loan/blob/master/x/loan/keeper/msg_server_approve_loan.go)
23+
- [JackalLabs](https://github.com/JackalLabs/canine-chain/issues/8).
24+
- [OllO](https://github.com/OllO-Station/ollo/issues/20)

0 commit comments

Comments
 (0)