Skip to content

fix: return error when transfer memo has no provider field - #2704

Open
amalsaidov wants to merge 2 commits into
cosmos:mainfrom
amalsaidov:fix/reward-memo-missing-provider-error
Open

amalsaidov wants to merge 2 commits into
cosmos:mainfrom
amalsaidov:fix/reward-memo-missing-provider-error

Conversation

@amalsaidov

Copy link
Copy Markdown

Description

GetRewardMemoFromTransferMemo in x/ccv/types/wire.go is meant to return the reward memo embedded under the provider field of an ICS reward transfer memo, or an error when the memo is not a reward transfer memo.

When the parsed memo did not contain a provider field, the function returned RewardMemo{}, err where err was already nil (the preceding json.Unmarshal had succeeded). It therefore reported success with an empty RewardMemo instead of signaling that no reward memo was present.

The provider IBC middleware (x/ccv/provider/ibc_middleware.go) relies on this error to decide whether to fall back to identifying the consumer from the IBC packet:

if rewardMemo, err := ccvtypes.GetRewardMemoFromTransferMemo(data.Memo); err != nil {
    // fall back to identifying the consumer from the packet
} else {
    consumerId = rewardMemo.ConsumerId
}

Because the function returned a nil error for a valid JSON memo without a provider field, the middleware took the else branch with an empty consumerId and skipped the packet-based fallback entirely for those transfers.

This change returns a descriptive error when the provider field is absent, which restores the intended fallback behavior. The middleware already handles a non-nil error, so no change is needed there.

Note: this is a behavior change on the provider for transfers to the consumer rewards pool whose memo is valid JSON without a provider field, so it is flagged as a bug fix in the changelog. Legitimate ICS reward transfers built by CreateTransferMemo always include the provider field and are unaffected.

Testing

Added TestGetRewardMemoFromTransferMemo in x/ccv/types/wire_test.go covering a valid provider memo, a valid JSON object without a provider field, an empty JSON object, a non-JSON memo, an empty memo, and a provider field that is not a reward-memo object. The absent and empty-object cases fail before the fix and pass after it.

go test ./x/ccv/types/...
ok  	github.com/cosmos/interchain-security/v7/x/ccv/types

AI-assisted; directed, reviewed and tested by the author (amalsaidov).


Author Checklist

I have...

  • Included the correct type prefix in the PR title
  • Added ! to the type prefix if the change is state-machine breaking
  • Confirmed this PR does not introduce changes requiring state migrations, OR migration code has been added to consumer and/or provider modules
  • Targeted the correct branch (main)
  • Provided a link to the relevant issue or specification
  • Followed the guidelines for building SDK modules
  • Included the necessary unit and integration tests
  • Added a changelog entry to CHANGELOG.md
  • Included comments for documenting Go code
  • Updated the relevant documentation or specification
  • Reviewed "Files changed" and left comments if necessary
  • Confirmed all CI checks have passed
  • If this PR is library API breaking, bump the go.mod version string of the repo

GetRewardMemoFromTransferMemo returned a nil error when the parsed
transfer memo did not contain a "provider" field, so callers could
not tell a missing reward memo apart from a valid one. The provider
IBC middleware branches on this error to fall back to identifying the
consumer from the IBC packet, and that fallback was skipped whenever
the memo was valid JSON without a provider field.

Return a descriptive error in that case and add unit tests covering
the present, absent, malformed, and empty memo cases.
@greptile-apps

greptile-apps Bot commented Nov 13, 2026

Copy link
Copy Markdown

This PR does not match any of the 1 configured review trigger rule.

@github-actions github-actions Bot added the C:x/types Assigned automatically by the PR labeler label Nov 13, 2026
@mergify

mergify Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C:x/types Assigned automatically by the PR labeler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant