Skip to content
Business logic Audit finding Beginner

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.

oakcobalt Follow with 0xAlix2 and gxh191

Originally disclosed on Code4rena

Submitted by oakcobalt, also found by 0xAlix2 and gxh191

https://github.com/initia-labs/miniwasm/blob/ed1728e2ad51f214ee0191dde62d96a074f55f1f/x/tokenfactory/types/msgs.go#L145-L148

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()

https://github.com/initia-labs/miniwasm/blob/ed1728e2ad51f214ee0191dde62d96a074f55f1f/x/tokenfactory/keeper/before_send.go#L26-L27

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
	}
...

https://github.com/initia-labs/miniwasm/blob/ed1728e2ad51f214ee0191dde62d96a074f55f1f/x/tokenfactory/keeper/msg_server.go#L198

//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
	}
...

https://github.com/initia-labs/miniwasm/blob/ed1728e2ad51f214ee0191dde62d96a074f55f1f/x/tokenfactory/types/msgs.go#L177-L180

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.

Initia mitigated:

Delete cosmwasm address validation.

Status: Mitigation confirmed. Full details in reports from berndartmueller, 0xAlix2 and Franfran.


The original report as published on Code4rena, by oakcobalt. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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.

More by oakcobalt

View all

50 more disclosed reports, best first.

More from Initia Cosmos

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.