Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mempool filter ibc spam #8409

Merged
merged 4 commits into from
Jun 18, 2024
Merged

fix: mempool filter ibc spam #8409

merged 4 commits into from
Jun 18, 2024

Conversation

czarcas7ic
Copy link
Member

@czarcas7ic czarcas7ic commented Jun 18, 2024

Closes: #XXX

What is the purpose of the change

Limits IBC Transfer messages to the following:

  • transferMsg.Size() > 500000 // 500KB
  • transferMsg.Memo> 400000 // 400KB
  • transferMsg.Receiver > 65000 // 65KB

Limit ICA Send message to the following:

  • icaMsg.PacketData.Size() > 500000 // 500KB
  • icaMsg.Owner > 65000 // 65KB

I opted to hard code these since adding them to the config would be deprecated in the next release. LMK if you think I should add them as config params.

@czarcas7ic czarcas7ic marked this pull request as ready for review June 18, 2024 17:15
Comment on lines +65 to +97
msgs := tx.GetMsgs()
for _, msg := range msgs {
// If one of the msgs is an IBC Transfer msg, limit it's size due to current spam potential.
// 500KB for entire msg
// 400KB for memo
// 65KB for receiver
if transferMsg, ok := msg.(*transfertypes.MsgTransfer); ok {
if transferMsg.Size() > 500000 { // 500KB
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "msg size is too large")
}

if len([]byte(transferMsg.Memo)) > 400000 { // 400KB
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "memo is too large")
}

if len(transferMsg.Receiver) > 65000 { // 65KB
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "receiver address is too large")
}
}

// If one of the msgs is from ICA, limit it's size due to current spam potential.
// 500KB for packet data
// 65KB for sender
if icaMsg, ok := msg.(*icacontrollertypes.MsgSendTx); ok {
if icaMsg.PacketData.Size() > 500000 { // 500KB
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "packet data is too large")
}

if len([]byte(icaMsg.Owner)) > 65000 { // 65KB
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "owner address is too large")
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider copying some of the violating message JSONs from mintscan and adding them as unit tests

There is an example with arbitrage filters to help with boilerplate setup for this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests added here 179d7e7

@czarcas7ic czarcas7ic merged commit 3f220fd into v25.x Jun 18, 2024
1 check passed
@czarcas7ic czarcas7ic deleted the adam/mempool-filter-ibc-spam branch June 18, 2024 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants