-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Describe The Bug
There exists no negative check forAmount
field in MsgLockCoinData
when handling lockcoins.The attacker can lock a negative coin, and then his spendable coin
will increase. Although the spendable coin
is temporarily in the testing stage, this can be understood as the user's available assets, that is, the attacker can mint coins at will.
By exploiting this vulnerability, the attacker could lock a large negative coin to the account of himself, which disasterly destroy the whole ecosystem.
Code Snippets (Optional)
/x/asset/type/types.pb.go:L254-261:
type MsgLockCoinData struct {
// Id lock account
Id types.AccountID `protobuf:"bytes,1,opt,name=id,proto3" json:"id" yaml:"id"`
// Amount coins to lock
Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount" yaml:"amount"`
// UnlockBlockHeight the block height the coins unlock
UnlockBlockHeight int64 `protobuf:"varint,3,opt,name=unlockBlockHeight,proto3" json:"unlockBlockHeight,omitempty" yaml:"unlockBlockHeight"`
}
TheAmount
filed of the MsgLockCoinData
struct can be set as a negative value.
To reproduce the vulnerability, we need to modify the source code a little bit.
Modify the client code to make the amount set as negative when constructing the lockcoins transction.
/x/asset/client/cli/lock.go:L20:60
func LockCoin(cdc *codec.Codec) *cobra.Command {
...
amount, err := sdk.ParseCoins(args[2])
if err != nil {
return err
}
amount[0].Amount = amount[0].Amount.Neg()
...
}
Input/Output
- Craft a
MsgLockCoinData
: '{"id":"kratos","amount":["-1000kratos/kts"],"UnlockBlockHeight":"9"}' - Output: None
Steps to reproduce the behavior:
- Modify the source code as shown in the Code Snippets.
- make
- ./scripts/boot-testnet.sh ./
- ./build/ktscli query asset coins kratos
- ./build/ktscli tx asset lock kratos 9 1000kratos/kts --keyring-backend test --chain-id testing --home ./testing/cli/ --from kratos
- ./build/ktscli query asset locked kratos
Expected Behavior
Return an error "The amount of coin cannot be negative."
Screenshots
after the lockcoin transaction:
Desktop (please complete the following information):
OS: [macOS Catalina 10.15.6]
Additional Context (Optional)
Note: This problem not only exists in lockcoin(), many other places also have this problem.