Skip to content

Conversation

zsystm
Copy link
Contributor

@zsystm zsystm commented Jun 16, 2025

Description

This PR fixes a bug in the ICS20 precompile where the balance delta reflected in the stateDB did not correctly account for the adjusted amount when the input transfer amount was set to UnboundedSpendLimit.

In such cases, the actual amount transferred is reduced to the sender’s spendable balance by the IBC transfer module internally, but the precompile logic still emitted balance change entries based on the original (unbounded) value. This could lead to inconsistencies between the Cosmos bank state and the EVM stateDB.

Fix Summary

The ics20 precompile now mirrors the same adjustment logic

if sendAmt.GTE(UnboundedSpendLimit) {
    sendAmt = bankKeeper.SpendableCoin(...)
}

so that SetBalanceChangeEntries correctly reflects the actual transferred amount.

Test Covergage Improvements

In addition to the fix, this PR significantly improves the test coverage of the ICS20 precompile

Ensured test environment uses a consistent configuration with the same denom for both staking and EVM (bond_denom == evm_denom) to avoid confusion in test assumptions and better align with default settings.

Test Utility Enhancements

  • Extracted GenerateContractCallArgs as a standalone function to remove unnecessary dependency coupling from TxFactory.
  • Extended SendEvmTx to support contract creation and configurable gas limits, enabling more flexible test case writing (e.g., low gas limit failure cases).

Closes: #199 #221


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • tackled an existing issue or discussed with a team member
  • left instructions on how to review the changes
  • targeted the main branch

Reviewers Checklist

All items are required.
Please add a note if the item is not applicable
and please add your handle next to the items reviewed
if you only reviewed selected items.

I have...

  • added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • confirmed all author checklist items have been addressed
  • confirmed that this PR does not change production code
  • reviewed content
  • tested instructions (if applicable)
  • confirmed all CI checks have passed

- Make gas limit configurable for testing lower gas limit scenario
- Get ibctesting.AppCreator when create coordinator, so other applications can leverage this test suits.
- Make GenerateContractCallArgs as separate function. This doens't have to be a member method of TxFactory implementation. un-necessary dependency.
- SendEvmTx now supports contract creation.
@zsystm zsystm self-assigned this Jun 16, 2025
Previous ibc test suite uses different bond denom ("stake) with EVM denom ("aatom"). Even though it could be different technically, but we need to make sure everything works correctly with default config (bond denom == evm denom).
Wit this commit, we can make sure IBC and ICS20 transfers with default config should work well.

Updated test util for writing test cases more easily.
@zsystm zsystm changed the title tests: add ics20 precompile test cases fix: ics20 precompile wrong balance accounting problem / tests: add ics20 precompile test cases Jun 17, 2025
@zsystm zsystm changed the title fix: ics20 precompile wrong balance accounting problem / tests: add ics20 precompile test cases fix(ics20): correct balance accounting issue with test coverage Jun 17, 2025
Currently, Arguments.Copy in geth panics if there are type mismatch. Returning error instead makes more sense
@zsystm zsystm requested review from vladjdk and cloudgray June 17, 2025 11:58
@zsystm zsystm marked this pull request as ready for review June 17, 2025 11:58

// Run Ginkgo integration tests
RegisterFailHandler(Fail)
RunSpecs(t, "Distribution Precompile Suite")
Copy link
Member

Choose a reason for hiding this comment

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

This name should be changed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied in 496af19

return len(code) > 0
}

_ = Describe("Calling ICS20 precompile", func() {
Copy link
Member

Choose a reason for hiding this comment

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

Rename this to Calling ICS20 Precompile from callerContract.

We'll eventually need to add EOA calls to tests as well

Copy link
Contributor Author

@zsystm zsystm Jun 19, 2025

Choose a reason for hiding this comment

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

Applied in 496af19

@zsystm zsystm removed the request for review from cloudgray June 19, 2025 15:49
@zsystm zsystm merged commit 0e511d3 into cosmos:main Jun 19, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IBC Precompile Testing
2 participants