Skip to content

fix(evm): clone query cosmos proto buffers#305

Merged
beer-1 merged 1 commit into
mainfrom
fix/evm-query-cosmos-proto-race
Jun 16, 2026
Merged

fix(evm): clone query cosmos proto buffers#305
beer-1 merged 1 commit into
mainfrom
fix/evm-query-cosmos-proto-race

Conversation

@beer-1

@beer-1 beer-1 commented Jun 16, 2026

Copy link
Copy Markdown
Member

Description

Closes: N/A

This fixes a data race in the query_cosmos precompile by treating whitelist protobuf messages as prototypes only. The precompile now clones request and response messages before JSON/protobuf conversion so concurrent calls do not mutate shared decode buffers.

The PR also adds concurrent regression coverage for query_cosmos using a shared whitelist and independent precompile instances. The test asserts zero errors and zero mismatched query results.


Validation

  • go test ./x/evm/precompiles/cosmos -run 'Test_QueryCosmos$|Test_QueryCosmosDataRace' -count=1 -v
  • go test -race ./x/evm/precompiles/cosmos -run 'Test_QueryCosmosDataRace' -count=1 -v
  • go test ./x/evm/precompiles/cosmos -count=1

Author Checklist

I have...

  • included the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Summary by CodeRabbit

  • Bug Fixes

    • Fixed data race conditions in Cosmos query handling that could cause corruption during concurrent operations.
  • Tests

    • Added concurrent execution tests to verify data integrity and reliability of Cosmos query operations under high concurrency.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d4cb2c88-9ea5-48e6-a319-9f5adc03a722

📥 Commits

Reviewing files that changed from the base of the PR and between 772d021 and 0b3e830.

📒 Files selected for processing (2)
  • x/evm/precompiles/cosmos/contract.go
  • x/evm/precompiles/cosmos/contract_test.go

Walkthrough

In ExtendedRun's METHOD_QUERY_COSMOS path, protoSet.Request and protoSet.Response are now cloned via proto.Clone before each JSON↔proto conversion. A new concurrent stress test Test_QueryCosmosDataRace validates the fix by running many parallel precompile calls and asserting zero mismatches or errors.

Changes

Cosmos Query Proto Clone Fix

Layer / File(s) Summary
Clone proto templates in METHOD_QUERY_COSMOS
x/evm/precompiles/cosmos/contract.go
Adds github.com/cosmos/gogoproto/proto import; replaces direct use of protoSet.Request and protoSet.Response with proto.Clone copies at lines 341 and 354 to isolate each concurrent call from the shared template.
Concurrent data-race stress test
x/evm/precompiles/cosmos/contract_test.go
Adds sync/sync/atomic imports and Test_QueryCosmosDataRace, which spawns a large goroutine pool running ExtendedRun concurrently against a mocked gRPC router, collecting panics, errors, and response-field mismatches atomically before asserting all counts are zero.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Two little templates once shared without care,
Goroutines would scramble and mangle the pair.
Now Clone makes a copy for each little call,
No race, no corruption — no chaos at all!
The rabbit hops safely through concurrent land. 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: cloning proto buffers to fix a data race condition in the query_cosmos precompile.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/evm-query-cosmos-proto-race

Comment @coderabbitai help to get the list of available commands and usage tips.

@beer-1 beer-1 marked this pull request as ready for review June 16, 2026 01:39
@beer-1 beer-1 requested a review from a team as a code owner June 16, 2026 01:39
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (19c3bea) to head (0b3e830).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #305   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         10      10           
  Lines       3224    3224           
=====================================
  Misses      3224    3224           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@traviolus traviolus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@beer-1 beer-1 merged commit 2ddcccc into main Jun 16, 2026
11 checks passed
@beer-1 beer-1 deleted the fix/evm-query-cosmos-proto-race branch June 16, 2026 06:31
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.

2 participants