setBeforeSendHook can never delete an existing store due to vulnerable validate
The setBeforeSendHook function is intended to allow deleting an existing token transfer hook by setting an empty cosmwasmAddress, but the validation logic rejects empty addresses, so the deletion always fails. An attacker cannot exploit this to cause harm; it is a functionality bug that prevents legitimate hook removal.
Submitted by oakcobalt, also found by 0xAlix2 and gxh191
Finding description
setBeforeSendHook allows disabling an existing token transfer hook (deleting a store) by setting an empty cosmwasmAddress. However, this functionality is not available due to a vulnerable validate flow.
Proof of Concept
We see the intention of allowing empty cosmwasmAddress to disable a hook in before_send::setBeforeSendHook. This is also consistent with osmosis token factory where empty cosmwasmAddress is a valid input to delete the current store.
//miniwasm/x/tokenfactory/keeper/before_send.go
func (k Keeper) setBeforeSendHook(ctx context.Context, denom string, cosmwasmAddress string) error {
...
// delete the store for denom prefix store when cosmwasm address is nil
|> if cosmwasmAddress == "" {
return k.DenomHookAddr.Remove(ctx, denom) //@audit empty cosmwasmAddress is used to delete the store
} else {
// if a contract is being set, call the contract using cache context
// to test if the contract is an existing, valid contract.
cacheCtx, _ := sdk.UnwrapSDKContext(ctx).CacheContext()
However, we see in msg_server::SetBeforeSendHook -> msgs::validate, empty cosmwasmAddress will always return error in validate.
//miniwasm/x/tokenfactory/keeper/msg_server.go
func (server msgServer) SetBeforeSendHook(ctx context.Context, msg *types.MsgSetBeforeSendHook) (*types.MsgSetBeforeSendHookResponse, error) {
//@audit when msg.cosmwasmAddress is empty, Validate will always return error.
|> if err := msg.Validate(server.ac); err != nil {
return nil, err
}
...
//miniwasm/x/tokenfactory/types/msgs.go
func (m MsgSetBeforeSendHook) Validate(accAddrCodec address.Codec) error {
...
if addr, err := accAddrCodec.StringToBytes(m.CosmwasmAddress); err != nil {
return err
} else if len(addr) == 0 {
return ErrEmptySender
}
...
Impact
Deleting an existing before send hook will always error out.
Recommended mitigation steps
In func (m MsgSetBeforeSendHook) Validate, add a bypass for m.CosmwasmAddress == “”.
hoon (Initia) confirmed and commented via duplicate issue S-18:
It was fixed in this commit. Since address validation is handled in
setBeforeSendHook, it seems good to remove it.
Delete
cosmwasmaddress validation.
Status: Mitigation confirmed. Full details in reports from berndartmueller, 0xAlix2 and Franfran.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The validation function MsgSetBeforeSendHook.Validate rejects an empty cosmwasmAddress, even though the keeper's setBeforeSendHook function treats an empty address as a signal to delete the hook.
Impact
Deleting an existing before send hook will always error out, preventing the removal of a hook.
What the attacker needed
None
The fix
The validation was fixed by removing the cosmwasm address check, as confirmed in the mitigation.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This is a smart contract bug where a function meant to remove a hook (a piece of code that runs before token transfers) cannot be used because the input validation incorrectly rejects an empty address. As a result, once a hook is set, it cannot be removed, which could be a problem if the hook becomes malicious or outdated.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.