Skip to content

fix: avoid panic in IsReverseCharge when reverse-charge flag is absent - #667

Merged
fragwuerdig merged 5 commits into
classic-terra:mainfrom
GeoffreySHD:fix/reverse-charge-panic
Oct 3, 2026
Merged

fragwuerdig merged 5 commits into
classic-terra:mainfrom
GeoffreySHD:fix/reverse-charge-panic

Conversation

@GeoffreySHD

Copy link
Copy Markdown
Contributor

Description

Keeper.IsReverseCharge in x/tax/keeper/keeper.go performed an unchecked type assertion:

if !ctx.Value(types.ContextKeyTaxReverseCharge).(bool) {

The flag is only stored in the context by the ante handler (custom/auth/ante/fee.go). On any sdk.Context that did not flow through the ante handler — queries, genesis import/export, or calls from other keepers/tools — ctx.Value(...) returns nil, and this assertion panics, taking down the calling process.

Fix

Use the standard comma-ok idiom and default to "no reverse charge" when the flag is absent — which is also the correct fund-flow default (no flag ⇒ tax behaves normally):

reverseCharge, ok := ctx.Value(types.ContextKeyTaxReverseCharge).(bool)
if !ok || !reverseCharge {

Testing

New regression test x/tax/keeper/keeper_test.go (TestIsReverseCharge, 6 subtests):

  • absent flag → no panic, returns false (previously panicked — verified the test fails with the panic on pre-fix code)
  • wrong-typed flag → no panic, returns false
  • explicit true/false → correct result
  • event emission behavior unchanged (only on request, only for the no-reverse-charge path)

Verified in a Linux container (golang:1.24, CI parity): go build ./..., go vet ./x/tax/..., full x/tax + x/market test suites, and golangci-lint run (v2.1.6, the pinned version) all pass.

Notes

The same unchecked assertion exists in the Market Module 2.0 branch (#664) — after this lands, that branch can rebase cleanly onto it.

GeoffreySHD and others added 2 commits September 9, 2026 16:33
The tax keeper's IsReverseCharge performed an unchecked type assertion
on ctx.Value(types.ContextKeyTaxReverseCharge). Contexts that did not
flow through the ante handler (queries, genesis import/export, external
keepers) do not carry the flag, so the assertion panicked on nil.

Use the comma-ok idiom and default to "no reverse charge" when the flag
is absent, which is also the correct fund-flow default. Add a regression
test covering absent, false, true and wrong-typed flags, plus event
emission behavior.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
The strangelove-ventures GitHub org was renamed/moved to amygdala-labs,
which killed the ghcr.io/strangelove-ventures/heighliner/osmosis image
path baked into interchaintest's built-in chain config. Both PFM tests
(TestTerraGaiaOsmoPFM, TestTerraPFM) now fail during chain setup with
"denied" when pulling the image, independent of the code under test.

Override the osmosis image repository per ChainSpec (the spec-level
Images list replaces the built-in one; ChainSpec.Version still applies
to Images[0]) to the same tags under the new amygdala-labs org. Verified
the replacement manifests are pullable.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@GeoffreySHD

Copy link
Copy Markdown
Contributor Author

Root cause of the red test-ibc-pfm check — not this PR's code:

The failing job died pulling a third-party image during chain setup, before any code from this branch compiled or ran:

ERROR Failed to pull image {"error": "... ghcr.io/strangelove-ventures/heighliner/osmosis/manifests/v25.0.0\": denied"}
failed to create faucet accounts: ... image ghcr.io/strangelove-ventures/heighliner/osmosis:v25.0.0: denied

The strangelove-ventures GitHub org was renamed to amygdala-labs; the old ghcr namespace died with it (repo now resolves to amygdala-labs/heighliner). interchaintest v10.0.1 hardcodes the old path for osmosis in its built-in chain config — every PR would hit this today; the last green run of that workflow was 2026-07-27.

Fix: e718e86 overrides the osmosis image repository per ChainSpec (spec-level Images replaces the built-in entry; Version still applies) to the same v25.0.0 tag under ghcr.io/amygdala-labs/heighliner/osmosis, which is verified pullable. Both PFM tests (TestTerraGaiaOsmoPFM, TestTerraPFM) get the fix.

@GeoffreySHD

Copy link
Copy Markdown
Contributor Author

Friendly bump — this is now fully green (31/31 checks, including the real test-ibc-pfm e2e passing with the osmosis image fix aboard). Summary for review: IsReverseCharge did ctx.Value(key).(bool) without the comma-ok check, so any context that skipped the fee/tax ante handler (queries, genesis, external tools) panicked; the fix defaults to false and the PR also repairs the dead strangelove-ventures/heighliner osmosis image pin (org transferred to amygdala-labs) that was failing interchain tests on every PR. Would appreciate a look from @StrathCole @fragwuerdig @hoank101 whenever convenient.

GeoffreySHD added a commit to GeoffreySHD/core that referenced this pull request Sep 9, 2026
Complete writeup of the audit shipped across classic-terra#667/classic-terra#668/classic-terra#669/classic-terra#670 plus the
part-2 pass over oracle price-staleness windows and treasury distribution
params, and the posted MM2 (classic-terra#664) review.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>

@fragwuerdig fragwuerdig left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you. Apart from overly verbosity LGTM,

Comment thread tests/interchaintest/ibc_pfm_test.go
Comment thread tests/interchaintest/ibc_pfm_test.go
Comment thread x/tax/keeper/keeper.go Outdated
Comment thread x/tax/keeper/keeper_test.go Outdated
Removes the comments flagged in review as unnecessary verbosity;
no code changes.
@GeoffreySHD

Copy link
Copy Markdown
Contributor Author

All four comments removed in 54ba2f0 — no code changes.

@fragwuerdig

fragwuerdig commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

DO NOT MERGE YET

Thank you @GeoffreySHD - this will be merged after the Cosmos Labs security disclosure on 28th of September. There will be a rebuild of v4.0.1-patch.3 with official sources published by upstream. This change can be based on that afterwards.

Possibly consensus breaking touching the return behavior of a query into the context values that were setup by the first Ante Handler decorators.

Gonna ship this with a v4.1.0 I think

@fragwuerdig
fragwuerdig self-requested a review September 23, 2026 10:48
@fragwuerdig fragwuerdig added the state machine breaking Something that will impact the state machine and consensus label Sep 28, 2026
Resolve the conflict in tests/interchaintest/ibc_pfm_test.go by taking
main's version: the osmosis heighliner image fix has landed on main, so
this branch no longer needs to carry it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@fragwuerdig
fragwuerdig merged commit f3c6dcc into classic-terra:main Oct 3, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked state machine breaking Something that will impact the state machine and consensus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants