Skip to content

feat(staking): read and write the staking precompile's storage - #4728

Open
codchen wants to merge 8 commits into
claude/giga-staking-params-subspacefrom
claude/giga-staking-storage-layer
Open

codchen wants to merge 8 commits into
claude/giga-staking-params-subspacefrom
claude/giga-staking-storage-layer

Conversation

@codchen

@codchen codchen commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds the staking precompile's storage layer over StakingStorage.sol. It has no methods and no EndBlock yet; those come in the next PR.

  • layout.go: the top-level slots and struct members of StakingStorage.sol, and the bonded and not-bonded escrow addresses.
  • storage.go: typed reads and writes of validators, the validator set and key lookup, the last bonded set, delegations, unbonding entries, redelegation counts, and the three FIFO queues. Every delegation write keeps both sets, each delegator's validators and each validator's delegators.
  • validator.go: the power index (validatorsByPower), a sorted array kept in x/staking's iteration order, with insert, remove and move.
  • precompiles/dec: 1e18-scaled decimal math that rounds as sdk.Dec does, in a package of its own so every precompile can use it. Staking's token units and consensus power stay in units.go.
  • solstorage: AddressAt/SetAddressAt for addresses packed with other members.
  • StakingStorage.sol: ValidatorQueueEntry.completionHeight is renamed unbondingHeight, which is what it holds.
  • Validator takes 15 slots, without the __gap the PR below drops, and deleteValidator zeroes those.

Test plan

  • go test -race ./giga/evmonly/precompiles/...
  • layout.go is pinned against solc's storage layout of StakingStorage.sol.
  • A compiled Solidity harness writes every structure, and the Go accessors read it back.
  • Share math is compared with sdk.Dec and stakingtypes.Validator on random inputs.

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 ← this PR
  4. feat(staking): delegate, redelegate and undelegate in a giga evmonly precompile #4729 feat(staking): delegate, redelegate and undelegate in a giga evmonly precompile
  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 56.08696% with 101 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.41%. Comparing base (3bf68ef) to head (c77cd41).

Files with missing lines Patch % Lines
giga/evmonly/precompiles/staking/validator.go 7.54% 49 Missing ⚠️
giga/evmonly/precompiles/staking/storage.go 70.62% 47 Missing ⚠️
giga/evmonly/precompiles/dec/dec.go 66.66% 4 Missing ⚠️
giga/evmonly/precompiles/staking/units.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                           Coverage Diff                           @@
##           claude/giga-staking-params-subspace    #4728      +/-   ##
=======================================================================
- Coverage                                61.43%   61.41%   -0.02%     
=======================================================================
  Files                                     2067     2072       +5     
  Lines                                   160999   161229     +230     
=======================================================================
+ Hits                                     98903    99025     +122     
- Misses                                   62091    62199     +108     
  Partials                                     5        5              
Flag Coverage Δ
sei-chain 59.62% <56.08%> (-0.01%) ⬇️
sei-db 75.17% <ø> (ø)
sei-db-state-db 81.58% <ø> (-0.04%) ⬇️

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

Files with missing lines Coverage Δ
giga/evmonly/precompiles/solstorage/store.go 87.65% <100.00%> (+0.47%) ⬆️
giga/evmonly/precompiles/staking/layout.go 100.00% <100.00%> (ø)
giga/evmonly/precompiles/staking/units.go 0.00% <0.00%> (ø)
giga/evmonly/precompiles/dec/dec.go 66.66% <66.66%> (ø)
giga/evmonly/precompiles/staking/storage.go 70.62% <70.62%> (ø)
giga/evmonly/precompiles/staking/validator.go 7.54% <7.54%> (ø)

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

Medium Risk
Foundational, layout-sensitive staking state I/O; mistakes could corrupt validator/delegation storage once the precompile is wired, though this PR adds no live execution paths yet.

Overview
Adds a Go storage layer for the evmonly staking precompile (0x1005) so StakingStorage.sol can be read and updated from Go with typed helpers, ahead of delegate/EndBlock logic in follow-up PRs.

layout.go pins every top-level slot and struct member offset to the Solidity schema (including bonded/not-bonded escrow addresses). storage.go implements accessors for validators, bonded-set snapshots, delegations, unbonding entries, redelegation counters, and the three FIFO queues (push/pop/due/clamp). validator.go maintains validatorsByPower in x/staking iteration order via insert/remove/move.

Supporting pieces: shared dec package (1e18 decimals matching sdk.Dec rounding), solstorage AddressAt/SetAddressAt for packed addresses, and units.go for consensus power. StakingStorage.sol renames ValidatorQueueEntry.completionHeight → unbondingHeight.

Tests lock layout to solc --storage-layout, round-trip compiler-written state through a Solidity harness, and compare share math to the Cosmos SDK.

Reviewed by Cursor Bugbot for commit c77cd41. 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.

This PR adds the Go storage layer for the staking precompile over StakingStorage.sol: layout constants, typed accessors, the sorted power index, 1e18 share math and the packed-address helpers, with tests against solc's layout and a compiled harness. Nothing blocks: the slot, member and packing logic checks out against the schema in the merge tree (953f35a), and the share math matches sdk.Dec. The one real issue, from codex and kept, is that the harness fixture's provenance does not match its source; Go was not available in the sandbox, so the tests were not run.

Non-blocking

1 finding on the changed lines, as inline comments.

Pre-existing

Already true on the base branch, not introduced here.

  • suggestion — giga/evmonly/precompiles/params/testdata/ParamsStorageHarness.bin-runtime on the base branch has the same mismatch: its metadata says solc 0.8.28, but ParamsStorageHarness.sol requires exactly 0.8.30. Rebuild both harness fixtures together.
1 nit, not posted on the code
  • giga/evmonly/precompiles/staking/storage.go:433 — pop doesn't check that head < tail. Called on an empty queue, it moves head past tail and leaves state that check reports as corrupt. Unlike push, it has no error return, so the precondition (call due first) is only implicit.

seidroid review · decision approve · session 374a60f3f8b54d2eacc3935119a1a24c · turn resp_claude_b48c45f8429a81ac0f6243947e76e1ec · item 8558353a42995c7b841dffecb53ae627

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

codchen and others added 2 commits November 12, 2026 11:59
- Add the staking precompile's storage layer over StakingStorage.sol: the
  slot layout, typed accessors for validators, delegations, unbonding and
  redelegation records and the three queues, the power index, and the
  1e18 fixed-point share math.
- Add solstorage AddressAt/SetAddressAt for packed addresses, and rename
  ValidatorQueueEntry.completionHeight to unbondingHeight.
- Tests check the layout against solc's, read state a compiled harness
  wrote, and compare the share math with sdk.Dec.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Validator no longer reserves a __gap, so it takes 15 slots and
deleteValidator zeroes those. The layout testdata is regenerated; the
harness bytecode never writes the gap and is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codchen
codchen force-pushed the claude/giga-staking-params-subspace branch from 5a5dda3 to edf0390 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
codchen and others added 2 commits November 13, 2026 01:53
The harness and StakingStorage declare pragma solidity 0.8.30, and the
committed binary came from 0.8.28. Rebuild it with 0.8.30 and name the
command that reproduces it.

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.

Two items:

  • Stick with solidity 0.8.28 as the fixed version, don't use .30 or anything newwer
  • Move the decimal lib to someplace more generic. Govenance uses deilams and we should make sure we are usign the same decimal subroutines. If gov and staking need to be harminized that can be in a different PR, but the correct home for the decimal functions should be part of this PR.

Comment thread giga/evmonly/precompiles/staking/dec.go Resolved
Staking's share math and gov's tally both divide and round 1e18-scaled
decimals as sdk.Dec does. Put staking's helpers in precompiles/dec so the
precompiles share one implementation; staking keeps its token units and
consensus power in units.go.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
codchen and others added 3 commits November 16, 2026 11:55
setDelegation and removeDelegation keep delegationsByValidator in step with
delegationsByDelegator, so a validator's delegations can be listed without a
migration. The harness and layout testdata are rebuilt with solc 0.8.30.

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