Skip to content

[codex] add evm-only staking precompile#3616

Open
codchen wants to merge 4 commits into
codex/sei-v3-evm-only-scaffoldfrom
codex/evmonly-staking-precompile
Open

[codex] add evm-only staking precompile#3616
codchen wants to merge 4 commits into
codex/sei-v3-evm-only-scaffoldfrom
codex/evmonly-staking-precompile

Conversation

@codchen

@codchen codchen commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds the first SDK-free custom precompile for the evm-only executor: staking at 0x0000000000000000000000000000000000001005.

This PR wires custom precompile execution into the evm-only executor, stores precompile module-like state as storage owned by the precompile address, and adds an end-block hook for staking validator-set updates and delayed redelegation/undelegation completion. It also keeps staking token handling explicitly usei-only for the evm-only path.

Details

  • Adds SDK-free precompile context interfaces for byte-keyed store access, native balance transfers, logs, and end-block execution.
  • Implements staking create/delegate/redelegate/undelegate/query flows without Cosmos keepers or SDK objects.
  • Uses a deterministic escrow address for bonded stake instead of the precompile account balance.
  • Replicates staking end-block behavior with explicit JSON indexes instead of store iterators.
  • Moves reusable JSON/event/helper utilities under giga/evmonly/precompiles/util.
  • Adds executor and staking tests, including a delegate -> redelegate -> undelegate lifecycle e2e that checks balances and delegation accounting through maturity.

Validation

  • go test ./giga/evmonly/...

@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedJun 24, 2026, 6:12 AM

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.79290% with 933 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.09%. Comparing base (9c28df7) to head (27e3acc).

Files with missing lines Patch % Lines
giga/evmonly/precompiles/staking/staking.go 24.31% 353 Missing and 86 partials ⚠️
giga/evmonly/precompiles/staking/state.go 57.14% 142 Missing and 68 partials ⚠️
giga/evmonly/precompiles/staking/endblock.go 37.39% 107 Missing and 47 partials ⚠️
giga/evmonly/precompile_adapter.go 75.00% 25 Missing and 21 partials ⚠️
giga/evmonly/precompiles/staking/commission.go 59.37% 17 Missing and 9 partials ⚠️
giga/evmonly/precompiles/staking/helpers.go 40.00% 18 Missing and 6 partials ⚠️
giga/evmonly/precompiles/util/helpers.go 51.72% 7 Missing and 7 partials ⚠️
giga/evmonly/precompiles/staking/balances.go 60.00% 4 Missing and 4 partials ⚠️
giga/evmonly/precompiles/util/events.go 71.42% 2 Missing and 2 partials ⚠️
giga/evmonly/precompiles/util/json.go 71.42% 2 Missing and 2 partials ⚠️
... and 2 more
Additional details and impacted files

Impacted file tree graph

@@                        Coverage Diff                         @@
##           codex/sei-v3-evm-only-scaffold    #3616      +/-   ##
==================================================================
- Coverage                           58.21%   58.09%   -0.13%     
==================================================================
  Files                                2175     2186      +11     
  Lines                              176633   178307    +1674     
==================================================================
+ Hits                               102830   103588     +758     
- Misses                              64773    65443     +670     
- Partials                             9030     9276     +246     
Flag Coverage Δ
sei-chain-pr 54.21% <44.79%> (-22.56%) ⬇️
sei-db 70.41% <ø> (ø)

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

Files with missing lines Coverage Δ
giga/evmonly/executor.go 88.32% <50.00%> (+3.08%) ⬆️
giga/evmonly/precompiles/staking/events.go 60.00% <60.00%> (ø)
giga/evmonly/precompiles/util/events.go 71.42% <71.42%> (ø)
giga/evmonly/precompiles/util/json.go 71.42% <71.42%> (ø)
giga/evmonly/precompiles/staking/balances.go 60.00% <60.00%> (ø)
giga/evmonly/precompiles/util/helpers.go 51.72% <51.72%> (ø)
giga/evmonly/precompiles/staking/helpers.go 40.00% <40.00%> (ø)
giga/evmonly/precompiles/staking/commission.go 59.37% <59.37%> (ø)
giga/evmonly/precompile_adapter.go 75.00% <75.00%> (ø)
giga/evmonly/precompiles/staking/endblock.go 37.39% <37.39%> (ø)
... and 2 more

... and 2 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.

@codchen codchen requested review from arajasek and philipsu522 June 22, 2026 08:43
@codchen codchen marked this pull request as ready for review June 22, 2026 08:44
@cursor

cursor Bot commented Jun 22, 2026

Copy link
Copy Markdown

PR Summary

High Risk
Large new consensus-adjacent surface (validator set updates, escrow balances, end-block state) with intentional Cosmos parity gaps; incorrect staking or adapter logic could affect bonding accounting or validator power.

Overview
Introduces the first real custom precompile on the evm-only path: staking at 0x…1005, plus the plumbing needed to run it without Cosmos SDK types.

The executor now invokes registered precompile contracts (not only fail-closed placeholders), maps module-like state through a storage-backed byte store on the precompile address, and runs EndBlock hooks after txs to populate BlockResult.ValidatorUpdates. Precompile context is split into Store, BalanceTransfer, and logs instead of a monolithic state interface.

Staking implements create/delegate/redelegate/undelegate, queries, commission checks, and end-block validator-set / unbonding / redelegation completion; payable stake goes to a deterministic escrow address in usei-aligned units. Shared helpers live under precompiles/util. Docs and broad executor/staking tests (including a multi-block lifecycle e2e) cover the new behavior.

Not modeled: rewards, slashing, jailing; shares are 1:1 with tokens.

Reviewed by Cursor Bugbot for commit 27e3acc. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread giga/evmonly/precompiles/staking/state.go
Comment thread giga/evmonly/precompiles/staking/staking.go
Comment thread giga/evmonly/precompiles/staking/staking.go
@codchen codchen force-pushed the codex/sei-v3-evm-only-scaffold branch 2 times, most recently from ab82ec3 to 23fc6d3 Compare June 24, 2026 03:53

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b90eb37. Configure here.

record, ok, err := getUnbondingDelegation(ctx.Store, pair.DelegatorAddress, pair.ValidatorAddress)
if err != nil || !ok {
return err
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing unbonding record skips payout

Medium Severity

In completeUnbonding and completeRedelegation, when the store lookup returns ok == false with a nil error, the functions return success instead of failing. The mature-queue loop still deletes queue entries, so a queued unbonding pair without a matching record can be dropped without releasing escrowed stake or cleaning redelegation indexes.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b90eb37. Configure here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this is consistent with cosmos behavior

codchen and others added 4 commits June 24, 2026 14:08
Address review findings on the SDK-free staking precompile:

- redelegate/undelegate now enforce Cosmos guardrails: reject
  self-redelegation, transitive redelegation, and over-MaxEntries
  unbonding/redelegation entries.
- delegation shares are reported as an sdk.Dec (scaled by 10^precision)
  to match the keeper-backed precompile.
- create/editValidator validate commission bounds, the 24h rate-change
  rule, and min-self-delegation increase/cap; stricter decimal parsing
  rejects fraction/scientific forms.
- historicalInfo query is read-only again; historical info is tracked
  and pruned in the end-block hook.
- powerReduction set to 1_000_000 (Sei DefaultPowerReduction); tests use
  SEI-scale stakes.
- validators query no longer re-reads validators; README documents the
  staking parity limitations.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codchen codchen force-pushed the codex/evmonly-staking-precompile branch from b90eb37 to 27e3acc Compare June 24, 2026 06:11
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