Skip to content

[codex] add evm-only staking precompile#3616

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

[codex] add evm-only staking precompile#3616
codchen wants to merge 2 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 22, 2026, 8:53 AM

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.66409% with 891 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.98%. Comparing base (966d056) to head (d9d66a8).

Files with missing lines Patch % Lines
giga/evmonly/precompiles/staking/staking.go 22.36% 356 Missing and 78 partials ⚠️
giga/evmonly/precompiles/staking/state.go 55.35% 138 Missing and 58 partials ⚠️
giga/evmonly/precompiles/staking/endblock.go 36.88% 107 Missing and 47 partials ⚠️
giga/evmonly/precompile_adapter.go 75.00% 25 Missing and 21 partials ⚠️
giga/evmonly/precompiles/staking/helpers.go 36.11% 17 Missing and 6 partials ⚠️
giga/evmonly/precompiles/util/helpers.go 48.57% 9 Missing and 9 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 ⚠️
giga/evmonly/executor.go 50.00% 1 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files

Impacted file tree graph

@@                        Coverage Diff                         @@
##           codex/sei-v3-evm-only-scaffold    #3616      +/-   ##
==================================================================
- Coverage                           58.09%   57.98%   -0.11%     
==================================================================
  Files                                2142     2152      +10     
  Lines                              174282   175820    +1538     
==================================================================
+ Hits                               101247   101951     +704     
- Misses                              64070    64684     +614     
- Partials                             8965     9185     +220     
Flag Coverage Δ
sei-chain-pr 50.70% <42.66%> (-11.55%) ⬇️
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 79.56% <50.00%> (+5.73%) ⬆️
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 48.57% <48.57%> (ø)
giga/evmonly/precompiles/staking/helpers.go 36.11% <36.11%> (ø)
giga/evmonly/precompile_adapter.go 75.00% <75.00%> (ø)
giga/evmonly/precompiles/staking/endblock.go 36.88% <36.88%> (ø)
giga/evmonly/precompiles/staking/state.go 55.35% <55.35%> (ø)
... and 1 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
Introduces consensus-adjacent staking, validator-set updates, and native balance moves on a new execution path; behavior must match expected staking semantics despite no Cosmos module.

Overview
Adds the first working custom precompile on the evm-only executor: staking at 0x0000000000000000000000000000000000001005, without Cosmos SDK keepers or sdk.Context.

The executor now runs registered precompiles through a new adapter (precompile_adapter.go) that builds an SDK-free precompiles.Context (byte-key Store mapped to the precompile’s EVM storage slots, BalanceTransfer, logs) and, after all txs, calls EndBlock on contracts that implement it. BlockResult gains ValidatorUpdates. Registry entries with no implementation still fail closed with ErrCustomPrecompilesOpen; empty blocks no longer short-circuit before end-block work.

Staking implements create/delegate/redelegate/undelegate and queries, stores module-like state as JSON in the storage-backed store, moves payable value to a deterministic escrow address (usei-aligned, no wei remainder), and runs end-block logic for validator-set changes and mature unbonding/redelegation (returning stake from escrow). Shared helpers live under precompiles/util. Docs and broad executor/staking tests (including a multi-block delegate → redelegate → undelegate E2E) cover the new behavior.

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

return err
}
return insertRedelegationQueue(store, completionTime, delegator, srcValidator, dstValidator)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

MaxEntries never enforced

Medium Severity

params() and defaults expose MaxEntries (7), but addUnbondingDelegation and addRedelegation always append queue entries without comparing len(record.Entries) to that limit. Undelegate/redelegate can create unbounded entry lists, unlike Cosmos staking where excess entries are rejected.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 917aa28. Configure here.

}
if err := setValidator(ctx.Store, validator); err != nil {
return nil, 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.

Duplicate consensus pubkeys allowed

High Severity

createValidator only rejects duplicate operator addresses. Two validators can register the same ConsensusPubkey under different operator addresses, and end-block logic can emit multiple ValidatorUpdate values sharing one pubkey with different power.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 917aa28. Configure here.

@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.

There are 3 total unresolved issues (including 2 from previous reviews).

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 d9d66a8. Configure here.

return nil, err
}
if !ok {
return nil, errValidatorMissing

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Validator hex case breaks lookups

Medium Severity

Validator operator keys are stored with EIP-55 checksummed Hex() from the creator, but delegate, redelegate, and undelegate look up validators using the raw string argument without normalizing case. The same EVM operator with a lowercase hex string fails with validator not found even when the validator exists.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d9d66a8. Configure here.

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