Skip to content

feat(staking): delegate, redelegate and undelegate in a giga evmonly precompile - #4729

Open
codchen wants to merge 9 commits into
claude/giga-staking-storage-layerfrom
claude/giga-staking-precompile
Open

codchen wants to merge 9 commits into
claude/giga-staking-storage-layerfrom
claude/giga-staking-precompile

Conversation

@codchen

@codchen codchen commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds the staking precompile at 0x1005, over the storage layer in the PR below it.

  • Methods: delegate(address) is payable. redelegate(address,address,uint256) and undelegate(address,uint256) take amounts in wei, which must be a positive whole number of usei. Bad arguments revert before any state is read.

  • Retired V2 methods: V2's string-address forms and authz methods keep their selectors. They revert with a reason naming the replacement.

  • Ported from x/staking's keeper: share math, Sei's max voting power ratio check, the maxEntries limits, the refusal of transitive redelegations, and the escrow moves between bonded and not-bonded.

  • EndBlock runs in V2's order:

    1. Applies the bonded set from the sorted power index, with one net escrow transfer.
    2. Completes due entries of the validator, unbonding and redelegation queues, with a budget for each queue.

    Each step runs under a snapshot. A failure is reverted and reported as ErrDegraded, and a failed queue entry is dropped from its queue.

  • Hooks are called at StakingHooks' points, for distribution to implement later. Genesis gets SetParams and AddGenesisValidator.

Deviations from V2

  • Validators are never jailed. An operator whose self-delegation falls below its minimum keeps its validator in the power index, where x/staking jails it until an unjail.
  • The queues are FIFO, so a new entry's completion time is never earlier than the tail entry's. An unbonding-time decrease takes effect for new entries only once older ones drain.
  • Unbonding and redelegation entries are never slashed.
  • A bonded set with no power is refused; the previous set is kept.
  • Staking takes calls only once an EndBlock has bonded its first validators. x/staking bonds them at InitChain, so its first block's voting-power check sees the bonded power.

Not in this PR

  • The precompile isn't registered in evmonlyapp, and nothing is added to the genesis config. Registering it on a running chain changes the app hash.
  • The bonded set isn't sent to autobahn consensus.
  • There's no createValidator, editValidator, queries, or distribution hook implementation.
  • Testdata bytecode was compiled with solc 0.8.28. The storage layout is the same in 0.8.30, but the bytecode should be regenerated with 0.8.30.

Test plan

  • make fmtcheck
  • go test -race ./giga/evmonly/precompiles/... ./giga/evmonly/
  • Executor-level test with signed transactions; OCC matches sequential execution.

Stack

Replaces #4713. Each PR's base is the one above it; review and merge from the top.

  1. docs(giga-storage): keep only the staking structures an on-chain path reads #4726 docs(giga-storage): keep only the staking structures an on-chain path reads
  2. feat(params): add the staking subspace #4727 feat(params): add the staking subspace
  3. feat(staking): read and write the staking precompile's storage #4728 feat(staking): read and write the staking precompile's storage
  4. feat(staking): delegate, redelegate and undelegate in a giga evmonly precompile #4729 feat(staking): delegate, redelegate and undelegate in a giga evmonly precompile ← this PR
  5. test(staking): check delegations and EndBlock against x/staking #4730 test(staking): check delegations and EndBlock against x/staking

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

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

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedNov 16, 2026, 4:13 AM

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.39309% with 63 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.54%. Comparing base (c77cd41) to head (4358d77).

Files with missing lines Patch % Lines
giga/evmonly/precompiles/staking/delegation.go 83.59% 31 Missing ⚠️
giga/evmonly/precompiles/staking/endblock.go 90.40% 11 Missing and 1 partial ⚠️
giga/evmonly/precompiles/staking/validator.go 80.76% 10 Missing ⚠️
giga/evmonly/precompiles/staking/genesis.go 88.09% 5 Missing ⚠️
giga/evmonly/precompiles/staking/staking.go 90.90% 4 Missing ⚠️
giga/evmonly/precompiles/staking/hooks.go 90.90% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                          Coverage Diff                          @@
##           claude/giga-staking-storage-layer    #4729      +/-   ##
=====================================================================
+ Coverage                              61.41%   61.54%   +0.12%     
=====================================================================
  Files                                   2072     2077       +5     
  Lines                                 161229   161692     +463     
=====================================================================
+ Hits                                   99025    99509     +484     
+ Misses                                 62199    62177      -22     
- Partials                                   5        6       +1     
Flag Coverage Δ
sei-chain 59.75% <86.39%> (+0.13%) ⬆️
sei-db 75.17% <ø> (ø)
sei-db-state-db 81.61% <ø> (+0.03%) ⬆️

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

Files with missing lines Coverage Δ
giga/evmonly/precompiles/staking/hooks.go 90.90% <90.90%> (ø)
giga/evmonly/precompiles/staking/staking.go 90.90% <90.90%> (ø)
giga/evmonly/precompiles/staking/genesis.go 88.09% <88.09%> (ø)
giga/evmonly/precompiles/staking/validator.go 84.76% <80.76%> (+77.21%) ⬆️
giga/evmonly/precompiles/staking/endblock.go 90.40% <90.40%> (ø)
giga/evmonly/precompiles/staking/delegation.go 83.59% <83.59%> (ø)

... and 37 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 marked this pull request as ready for review November 9, 2026 03:49
@cursor

cursor Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

PR Summary

High Risk
Introduces on-chain staking state transitions, escrow balances, and validator set updates that affect consensus economics; failures degrade via EndBlock rather than halting the block, which needs careful operational review.

Overview
Adds the EVM-only staking precompile at 0x1005 with a Solidity interface, embedded ABI, and Go Precompile that exposes delegate(address) (payable), redelegate(address,address,uint256), and undelegate(address,uint256) using validator operator addresses and whole-usei wei amounts. V2 string-address and authz selectors remain in the ABI but revert with messages pointing callers at the address-based APIs.

The implementation ports core x/staking behavior: share math, escrow moves between bonded/not-bonded accounts, max voting power ratio, unbonding/redelegation entry limits, and transitive-redelegation checks, plus Delegate/Redelegate/Undelegate events. EndBlock updates the bonded set from the power index, then drains validator/unbonding/redelegation FIFO queues under a per-block budget, reporting ErrDegraded and dropping bad queue entries on failure. Genesis helpers set default params and AddGenesisValidator; optional Hooks mirror StakingHooks for future modules.

Documented divergences from V2/x-staking include no jailing, FIFO queue completion ordering, no slashing of unbonding/redelegation entries, refusing an empty bonded set, and rejecting calls until the first EndBlock has bonded validators. Unit and executor tests cover delegation flows, end-block edge cases, retired methods, and OCC vs sequential execution (precompile not yet wired into evmonlyapp genesis).

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

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

Adds the giga EVM-only staking precompile, ported from x/staking: delegate, redelegate and undelegate, an EndBlock that updates the bonded set and drains three queues under a budget, plus genesis setup and hooks. Approved because nothing blocks; there are two suggestions on the EndBlock budget and on dropping jailing. Of codex's two findings, the voting-power denominator on redelegation is kept as a pre-existing V2 issue, since it matches sei-cosmos Delegate exactly. The other is dropped: getBeginInfo reading a source validator after Unbond removed it is the same order as BeginRedelegation, and changing it would break the parity #4730 checks.

Non-blocking

2 findings on the changed lines, as inline comments.

Pre-existing

Already true on the base branch, not introduced here.

  • suggestion — From codex: sei-cosmos/x/staking/keeper/delegation.go Delegate checks the max voting power ratio against lastTotalPower + bondAmt even when a bonded-to-bonded redelegation leaves total power unchanged. A destination can therefore pass the check and still end above the cap; for example, at 40 of 100 power with a 50% cap, moving 20 more passes as 60/120 but leaves it at 60/100. checkVotingPowerRatio (giga/evmonly/precompiles/staking/delegation.go:131) inherits this faithfully. Fixing it means diverging from V2 in both places together.

seidroid review · decision approve · session 617c275fec5b4badb7798a704d25562a · turn resp_claude_3aa5a2369fcca6c7c6102167a37721bc · item 7dd2118da1785af59e27044d58b35c2c

Findings: 0 blocking | 2 non-blocking | 2 posted inline | 1 pre-existing

return shares, nil
}

// unbond takes shares from delegator's delegation to op and returns the tokens

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — With jailing removed, minSelfDelegation is checked only at genesis. An operator can withdraw its entire self-stake and stay in the bonded set, on delegators' stake alone, indefinitely. The description lists this as a deviation, but nothing in this stack restores the guarantee. It needs a tracked follow-up, such as dropping such a validator from the power index, before the precompile is registered on a live chain.

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

Stale Bugbot comment from a previous run.

codchen and others added 4 commits November 12, 2026 11:59
- Add the staking precompile at 0x1005 over its storage: delegate
  (payable), redelegate and undelegate, by address and in whole usei.
  V2's string forms and authz methods keep their selectors and revert
  naming the replacement.
- Port x/staking's share math, minSelfDelegation jailing, Sei's max
  voting power ratio, the maxEntries limits, transitive redelegation
  refusal, and the bonded/not-bonded escrow moves.
- EndBlock applies the bonded set from the sorted power index, then
  completes the validator, unbonding and redelegation queues under a
  per-queue budget. Each step runs under a snapshot; a failure is
  reverted and reported as degraded.
- Add Hooks at StakingHooks' points, and genesis SetParams and
  AddGenesisValidator.

Not yet registered in evmonlyapp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An operator whose self-delegation falls below its minimum keeps its validator
in the power index, where x/staking jails it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
x/staking bonds its genesis validators before the first block, but here the
first EndBlock does, so a delegation before it checked the voting power ratio
against no bonded power. Run now refuses calls until the bonded set has power.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codchen
codchen force-pushed the claude/giga-staking-precompile branch from 7c8ab34 to 7982369 Compare November 12, 2026 04:08
@codchen
codchen force-pushed the claude/giga-staking-storage-layer branch from 8458326 to 8bafe18 Compare November 12, 2026 04:08

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

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 67974b9. Configure here.

codchen and others added 2 commits November 13, 2026 02:12
Run takes calls only once an EndBlock has bonded a set with power, and
genesis validators are the only way into the first one. A genesis whose
validators were each below one SEI never bonded, so every call failed for
good. Genesis now requires each self-delegation to be worth at least one
unit of consensus power.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

Is jailing gone forever or coming back in a future PR? Some comments in the code would be useful so seidroid will chill out. Also, if it's coming backleave something related to sedroids complaints in the right place so when we do bring it back we have notes to fix it.

codchen and others added 2 commits November 16, 2026 11:55
…king-precompile

requireInvariants also checks that each validator's delegators are exactly
the accounts delegating to it, so every delegate, undelegate and redelegate
test covers the new index.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

3 participants