Skip to content

feat(precompiles): expose module Query rpcs as precompile methods#3767

Draft
codchen wants to merge 2 commits into
mainfrom
claude/audit-missing-precompile-impls-07737c
Draft

feat(precompiles): expose module Query rpcs as precompile methods#3767
codchen wants to merge 2 commits into
mainfrom
claude/audit-missing-precompile-impls-07737c

Conversation

@codchen

@codchen codchen commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Motivation

An audit of all rpc defs in service Query (query.proto) and service Msg (tx.proto) under /proto and /sei-cosmos/proto found that many module Query rpcs have no EVM precompile counterpart: bank/distribution were partial, gov was write-only, and auth, authz, evidence, feegrant, mint, params, slashing, and upgrade had no precompile at all.

Changes

Extended existing precompiles (new view methods, head version only)

  • bank (+5): spendableBalances, totalSupply (paginated all-denoms; existing supply(denom) unchanged), params, denomMetadata, denomsMetadata
  • distribution (+8): params, validatorOutstandingRewards, validatorCommission, validatorSlashes, delegationRewards, delegatorValidators, delegatorWithdrawAddress, communityPool
  • gov (+8): proposal, proposals (status/voter/depositor filters), getVote, votes, params (voting+deposit+tallying merged), getDeposit, deposits, tallyResultgetVote(uint64,address) / getDeposit(uint64,address) (named to avoid overloading the tx methods, which breaks ethers.js name resolution)

New query-only precompiles

Precompile Address Methods
auth 0x…100D account, accounts, params, nextAccountNumber
authz 0x…100E grants, granterGrants, granteeGrants
evidence 0x…100F evidence, allEvidence
feegrant 0x…1010 allowance, allowances, allowancesByGranter
mint 0x…1012 params, minter
params 0x…1013 params(subspace, key)
slashing 0x…1014 params, signingInfo, signingInfos
upgrade 0x…1015 currentPlan, appliedPlan, upgradedConsensusState, moduleVersions

(0x…1011 is already p256.) Each new precompile follows the oracle-style DynamicGasPrecompile shape with abi.json, a Solidity interface, a versions file (single v6.6 entry), and a generated-style setup.go, so scripts/bump_version manages them going forward.

Plumbing

  • 11 narrow querier interfaces (mirroring the existing StakingQuerier pattern) plus Codec() added to precompiles/utils/expected_keepers.go, wired to concrete keepers in app/precompiles.go (mint via mintkeeper.NewQuerier; others implement their gRPC QueryServers directly)
  • Conventions follow the staking precompile: Dec/Int → string, times → Unix seconds, durations → seconds, pagination via bytes pageKey + nextKey
  • Any-typed response fields (gov proposal content, authz authorizations, evidence, feegrant allowances) are returned as registry-resolved JSON bytes ({"@type": …}), consumable on-chain with the json precompile

Notes for reviewers

  • These are consensus-visible additions at the current head version (v6.6). If v6.6 is already live, they should ride the next upgrade tag — the bump_version flow handles archival when the tag is added.
  • Account-typed query inputs take EVM address and require address association (consistent with existing bank/staking/distribution precompiles); validator/consensus addresses are bech32 strings.
  • precompiles/setup.go registers the new precompiles in GetCustomPrecompiles only (same as solo), not in the legacy InitializePrecompiles global-VM path.

Testing

  • go build ./... clean
  • go test ./precompiles/... -count=1 — all 22 precompile packages pass, including new tests covering happy paths, pagination, error paths (unassociated address, not-found), and exact packed-output assertions
  • go test ./x/evm/keeper/ -run TestGetCustomPrecompiles passes
  • go vet clean; all touched files gofmt -s / goimports compliant

🤖 Generated with Claude Code

Add query counterparts for Cosmos module Query rpcs that had no EVM
precompile surface:

- bank: spendableBalances, totalSupply, params, denomMetadata,
  denomsMetadata
- distribution: params, validatorOutstandingRewards, validatorCommission,
  validatorSlashes, delegationRewards, delegatorValidators,
  delegatorWithdrawAddress, communityPool
- gov: proposal, proposals, vote, votes, params, deposit, deposits,
  tallyResult

New query-only precompiles: auth (0x100D), authz (0x100E), evidence
(0x100F), feegrant (0x1010), mint (0x1012), params (0x1013), slashing
(0x1014), upgrade (0x1015).

Querier interfaces and codec plumbing are added to precompiles/utils and
wired in app/precompiles.go. Any-typed response fields (gov content,
authz authorizations, evidence, feegrant allowances) are returned as
registry-resolved JSON bytes for use with the json precompile.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedJul 16, 2026, 1:35 PM

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.17305% with 497 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.02%. Comparing base (ad863c7) to head (f45c933).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
precompiles/distribution/distribution.go 54.58% 75 Missing and 29 partials ⚠️
precompiles/gov/gov.go 67.65% 41 Missing and 35 partials ⚠️
precompiles/bank/bank.go 65.80% 30 Missing and 23 partials ⚠️
precompiles/authz/authz.go 66.91% 25 Missing and 20 partials ⚠️
precompiles/feegrant/feegrant.go 64.00% 25 Missing and 20 partials ⚠️
precompiles/auth/auth.go 64.70% 25 Missing and 17 partials ⚠️
precompiles/upgrade/upgrade.go 70.47% 18 Missing and 13 partials ⚠️
precompiles/evidence/evidence.go 67.60% 14 Missing and 9 partials ⚠️
precompiles/slashing/slashing.go 76.04% 14 Missing and 9 partials ⚠️
precompiles/mint/mint.go 73.97% 12 Missing and 7 partials ⚠️
... and 10 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3767      +/-   ##
==========================================
- Coverage   59.88%   59.02%   -0.86%     
==========================================
  Files        2288     2217      -71     
  Lines      190023   181666    -8357     
==========================================
- Hits       113786   107226    -6560     
+ Misses      66091    64903    -1188     
+ Partials    10146     9537     -609     
Flag Coverage Δ
sei-chain-pr 57.31% <67.17%> (?)
sei-db 70.41% <ø> (ø)
sei-db-state-db ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
app/precompiles.go 100.00% <100.00%> (ø)
precompiles/setup.go 50.90% <100.00%> (+3.85%) ⬆️
precompiles/auth/setup.go 71.42% <71.42%> (ø)
precompiles/authz/setup.go 71.42% <71.42%> (ø)
precompiles/evidence/setup.go 71.42% <71.42%> (ø)
precompiles/feegrant/setup.go 71.42% <71.42%> (ø)
precompiles/mint/setup.go 71.42% <71.42%> (ø)
precompiles/params/setup.go 71.42% <71.42%> (ø)
precompiles/slashing/setup.go 71.42% <71.42%> (ø)
precompiles/upgrade/setup.go 71.42% <71.42%> (ø)
... and 12 more

... and 88 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Overloading the vote/deposit transaction methods breaks tooling that
resolves functions by name (ethers.js rejects ambiguous names with
INVALID_ARGUMENT). Rename the query variants instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant