Skip to content

Commit 8269937

Browse files
config: disable state proofs by default (#4573)
## Summary Disables deprecated ABCI `/store` state proofs by default while keeping a per-node escape hatch for the v6.8 rollout. The proof code stays in place, but `Store.Query` now rejects proof requests unless the operator sets `state-commit.sc-enable-state-proof = true`. - `sei-db/config/sc_config.go`: adds `EnableStateProof` to `StateCommitConfig`. The default is `false`, so a node with no new config key rejects state proof requests. - `sei-db/config/toml.go`: renders `sc-enable-state-proof = false` in app.toml. The comment says the option is temporary and will be removed with the proof code. - `app/seidb.go`: adds `FlagSCEnableStateProof` and reads it with the same presence guard as the other SC keys. An absent key keeps the in-code default. - `app/config_register.go`: declares the new state-commit key in the config registry, so generated config, parsed config, and registered keys stay in sync. - `sei-cosmos/storev2/rootmulti/store.go`: stores the resolved flag on `Store` and checks it in `admitProofQuery`, at the proof choke point after `needProof := req.Prove && rootmulti.RequireProof(subPath)`. A rejection returns `ErrNotSupported` (code 37), so clients can tell it apart from the pruned-height error (code 18). Unproven queries keep their existing path. `/subspace` queries keep their existing limits. The gate runs before the historical-proof permit, so rejected requests do not use it. - `sei-cosmos/storev2/rootmulti/metrics.go`: adds `state_proof_rejected`, a counter for proof requests rejected by the default-off gate. It has a `store` attribute and a `latest` attribute, so the rollout shows which module state callers still prove, and at which heights. The store set is bounded, because `Query` rejects unknown store names before the gate. - `CHANGELOG.md`: documents the v6.8 default-off behavior, the temporary operator override, and the affected clients: `sei-tendermint/light/rpc` (always sets `prove=true`), the light proxy built on it, and `sei-cosmos/client` queries with `Prove` set. ## Test plan - `sei-cosmos/storev2/rootmulti/store_test.go`: - default config rejects `Prove: true` for latest and historical `/key` queries with `ErrNotSupported`; - default config still serves the same latest and historical queries without proof; - on a node with SS enabled, default config still serves `Prove: true` on `/subspace` unproven, because only `/key` produces a proof (a node without SS refuses `/subspace` since #4572); - `EnableStateProof = true` returns `ProofOps` at latest and historical heights; - existing proof-path tests opt in to `EnableStateProof`. - `sei-cosmos/storev2/rootmulti/flatkv_helpers_test.go`: flatkv query tests opt in through the shared SC test config, so they still cover the proof path. - `app/seidb_test.go`: absent `sc-enable-state-proof` keeps `false`; explicit `true` enables proofs; explicit `false` disables proofs. - `app/config_register_test.go`, `app/config_register_agreement_test.go`, and `sei-db/config/toml_test.go`: the new key is registered, read, and rendered by the app.toml template. - `app/upgrade_offline_harness_test.go`: both harness constructors open apps with `offlineUpgradeAppOpts`, which turns proofs on, so `requireOfflineUpgradeStoreProof` still checks committed store membership. The key is a string literal, because CI also compiles this file into the source release worktree, which does not have `FlagSCEnableStateProof`. - Verification run: - `make fmtcheck` - `scripts/ramtest.sh ./sei-cosmos/storev2/... ./sei-db/config/...` - `scripts/ramtest.sh ./app/ -run 'TestParseSCConfigs|ConfigRegister|Offline'` - `make upgrade-test-vet` - `make upgrade-test-offline FROM_REF=release/v6.7 TO_REF=HEAD` (v6.7 -> v6.8 boundary) - `make lint` - Harbor (4 validators + 2 RPC nodes, image `7e83763`, before the `ErrNotSupported` change and before #4572): - default validator: `prove=false` returns the value at latest and historical heights; `prove=true` is rejected at both heights; `/subspace` with `prove=true` succeeds; `sei_chain_state_proof_rejected_total{store="bank"}` counts the rejections with `latest="true"` and `latest="false"`; - RPC node with `sc-enable-state-proof = true`: `prove=true` returns `ics23:iavl` + `ics23:simple` proof ops at latest and historical heights, and the rejection counter stays empty. --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 1736cc3 commit 8269937

14 files changed

Lines changed: 185 additions & 5 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
3030

3131
## Unreleased
3232
sei-chain
33+
* [#4573](https://github.com/sei-protocol/sei-chain/pull/4573) Disable ABCI `/store` state proofs by default in v6.8. Nodes now reject proof queries with `ErrNotSupported` (code 37) unless operators set `state-commit.sc-enable-state-proof = true`; rejected proof requests increment `state_proof_rejected`. This affects light clients (`sei-tendermint/light/rpc`, which always sets `prove=true`, and the light proxy built on it) and any ABCI client that sends `prove=true`, such as `sei-cosmos/client` queries with `Prove` set. This is a deprecation step before the proof code is removed in a later release.
3334
* [#4576](https://github.com/sei-protocol/sei-chain/pull/4576) Upgrade to Go 1.27.3 and golangci-lint v2.14.0
3435
* [#4564](https://github.com/sei-protocol/sei-chain/pull/4564) Add two wasm params governance can set to stop CosmWasm contracts in stages. While `msgExecuteContractDisabled` is true, every `MsgExecuteContract` fails, whether sent directly, wrapped in an authz `MsgExec` or dispatched by a contract; the EVM wasmd precompile, solo claims and wasm gov proposals still execute. While `contractExecutionDisabled` is true, no contract runs: every instantiation, execution, migration and sudo call fails, whatever its origin, including the EVM wasmd and solo precompiles and wasm gov proposals; queries still work. The wasm module moves to consensus version 2 and stores both params as false at the upgrade. App-hash breaking at the upgrade height.
3536
* [#4563](https://github.com/sei-protocol/sei-chain/pull/4563) Delete the retired feegrant store at the v6.8 upgrade: v6.7 kept it mounted for historical state access, and from the upgrade height v6.8 nodes no longer serve feegrant state at any height, so that history needs a v6.7 or older node. App-hash breaking at the upgrade height.

‎app/config_register.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ type stateCommitSchema struct {
162162
HistoricalProofMaxInFlight int `mapstructure:"sc-historical-proof-max-inflight"`
163163
HistoricalProofRateLimit float64 `mapstructure:"sc-historical-proof-rate-limit"`
164164
HistoricalProofBurst int `mapstructure:"sc-historical-proof-burst"`
165+
EnableStateProof bool `mapstructure:"sc-enable-state-proof"`
165166
SubspaceQueryMaxInFlight int `mapstructure:"sc-subspace-query-max-inflight"`
166167
SubspaceMaxPairs int `mapstructure:"sc-subspace-max-pairs"`
167168
SubspaceMaxBytes int `mapstructure:"sc-subspace-max-bytes"`
@@ -198,6 +199,7 @@ func stateCommitDefaults(registry.Mode) any {
198199
HistoricalProofMaxInFlight: live.HistoricalProofMaxInFlight,
199200
HistoricalProofRateLimit: live.HistoricalProofRateLimit,
200201
HistoricalProofBurst: live.HistoricalProofBurst,
202+
EnableStateProof: live.EnableStateProof,
201203
SubspaceQueryMaxInFlight: live.SubspaceQueryMaxInFlight,
202204
SubspaceMaxPairs: live.SubspaceMaxPairs,
203205
SubspaceMaxBytes: live.SubspaceMaxBytes,

‎app/config_register_agreement_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func readerValues(t *testing.T) map[string]string {
4242
FlagSCHistoricalProofMaxInFlight: fmt.Sprint(sc.HistoricalProofMaxInFlight),
4343
FlagSCHistoricalProofRateLimit: fmt.Sprint(sc.HistoricalProofRateLimit),
4444
FlagSCHistoricalProofBurst: fmt.Sprint(sc.HistoricalProofBurst),
45+
FlagSCEnableStateProof: fmt.Sprint(sc.EnableStateProof),
4546
FlagSCSubspaceQueryMaxInFlight: fmt.Sprint(sc.SubspaceQueryMaxInFlight),
4647
FlagSCSubspaceMaxPairs: fmt.Sprint(sc.SubspaceMaxPairs),
4748
FlagSCSubspaceMaxBytes: fmt.Sprint(sc.SubspaceMaxBytes),

‎app/config_register_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func TestStateCommitResolvesTheModuleDeclaredValues(t *testing.T) {
125125
FlagSCHistoricalProofMaxInFlight: live.HistoricalProofMaxInFlight,
126126
FlagSCHistoricalProofRateLimit: live.HistoricalProofRateLimit,
127127
FlagSCHistoricalProofBurst: live.HistoricalProofBurst,
128+
FlagSCEnableStateProof: live.EnableStateProof,
128129
FlagSCSubspaceQueryMaxInFlight: live.SubspaceQueryMaxInFlight,
129130
FlagSCSubspaceMaxPairs: live.SubspaceMaxPairs,
130131
FlagSCSubspaceMaxBytes: live.SubspaceMaxBytes,

‎app/seidb.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
FlagSCHistoricalProofMaxInFlight = "state-commit.sc-historical-proof-max-inflight"
2929
FlagSCHistoricalProofRateLimit = "state-commit.sc-historical-proof-rate-limit"
3030
FlagSCHistoricalProofBurst = "state-commit.sc-historical-proof-burst"
31+
FlagSCEnableStateProof = "state-commit.sc-enable-state-proof"
3132
FlagSCSubspaceQueryMaxInFlight = "state-commit.sc-subspace-query-max-inflight"
3233
FlagSCSubspaceMaxPairs = "state-commit.sc-subspace-max-pairs"
3334
FlagSCSubspaceMaxBytes = "state-commit.sc-subspace-max-bytes"
@@ -168,6 +169,9 @@ func parseSCConfigs(appOpts servertypes.AppOptions) config.StateCommitConfig {
168169
if v := appOpts.Get(FlagSCHistoricalProofBurst); v != nil {
169170
scConfig.HistoricalProofBurst = cast.ToInt(v)
170171
}
172+
if v := appOpts.Get(FlagSCEnableStateProof); v != nil {
173+
scConfig.EnableStateProof = cast.ToBool(v)
174+
}
171175
if v := appOpts.Get(FlagSCSubspaceQueryMaxInFlight); v != nil {
172176
scConfig.SubspaceQueryMaxInFlight = cast.ToInt(v)
173177
}

‎app/seidb_test.go‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func (t TestSeiDBAppOpts) Get(s string) interface{} {
3737
return defaultSCConfig.MemIAVLConfig.SnapshotPrefetchThreshold
3838
case FlagSCSnapshotWriteRateMBps:
3939
return defaultSCConfig.MemIAVLConfig.SnapshotWriteRateMBps
40+
case FlagSCEnableStateProof:
41+
return defaultSCConfig.EnableStateProof
4042
case FlagSCFlatKVReadWriteMetrics:
4143
return defaultSCConfig.FlatKVConfig.EnableReadWriteMetrics
4244
case FlagSSEnable:
@@ -109,6 +111,25 @@ func TestParseSCConfigs_HistoricalProofFlags(t *testing.T) {
109111
assert.Equal(t, 3, scConfig.HistoricalProofBurst)
110112
}
111113

114+
func TestParseSCConfigs_EnableStateProof(t *testing.T) {
115+
scConfig := parseSCConfigs(mapAppOpts{
116+
FlagSCEnable: true,
117+
})
118+
assert.False(t, scConfig.EnableStateProof)
119+
120+
scConfig = parseSCConfigs(mapAppOpts{
121+
FlagSCEnable: true,
122+
FlagSCEnableStateProof: true,
123+
})
124+
assert.True(t, scConfig.EnableStateProof)
125+
126+
scConfig = parseSCConfigs(mapAppOpts{
127+
FlagSCEnable: true,
128+
FlagSCEnableStateProof: false,
129+
})
130+
assert.False(t, scConfig.EnableStateProof)
131+
}
132+
112133
func TestParseSCConfigs_FlatKVReadWriteMetrics(t *testing.T) {
113134
scConfig := parseSCConfigs(mapAppOpts{
114135
FlagSCEnable: true,

‎app/upgrade_offline_harness_test.go‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,23 @@ func requireOfflineUpgradePhase(t *testing.T, want string) string {
112112
return absolute
113113
}
114114

115-
type offlineUpgradeChainIDOpts struct {
115+
// offlineUpgradeAppOpts are the app options every offline upgrade app opens with. State proofs are on
116+
// because requireOfflineUpgradeStoreProof proves a store is in the commitment set. An empty chainID
117+
// keeps the TestAppOpts chain ID.
118+
type offlineUpgradeAppOpts struct {
116119
TestAppOpts
117120
chainID string
118121
}
119122

120-
func (o offlineUpgradeChainIDOpts) Get(s string) interface{} {
121-
if s == "chain-id" {
123+
func (o offlineUpgradeAppOpts) Get(s string) interface{} {
124+
if s == "chain-id" && o.chainID != "" {
122125
return o.chainID
123126
}
127+
// A literal, not FlagSCEnableStateProof: this file is also compiled into the source release's
128+
// worktree, which predates that constant.
129+
if s == "state-commit.sc-enable-state-proof" {
130+
return true
131+
}
124132
return o.TestAppOpts.Get(s)
125133
}
126134

@@ -188,7 +196,7 @@ func openOfflineUpgradeSnapshotApp(t *testing.T, home, chainID string) *App {
188196
config.TestConfig(),
189197
encodingConfig,
190198
wasm.EnableAllProposals,
191-
offlineUpgradeChainIDOpts{chainID: chainID},
199+
offlineUpgradeAppOpts{chainID: chainID},
192200
EmptyWasmOpts,
193201
options,
194202
)
@@ -230,7 +238,7 @@ func openOfflineUpgradeApp(t *testing.T, root string, initialize bool) *App {
230238
config.TestConfig(),
231239
encodingConfig,
232240
wasm.EnableAllProposals,
233-
TestAppOpts{},
241+
offlineUpgradeAppOpts{},
234242
EmptyWasmOpts,
235243
options,
236244
)

‎sei-cosmos/storev2/rootmulti/flatkv_helpers_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func withTestMemIAVL(cfg seidbconfig.StateCommitConfig) seidbconfig.StateCommitC
8888
cfg.FlatKVConfig.SnapshotKeepRecent = 1000
8989
cfg.HistoricalProofRateLimit = 0
9090
cfg.HistoricalProofMaxInFlight = 100
91+
cfg.EnableStateProof = true
9192
return cfg
9293
}
9394

‎sei-cosmos/storev2/rootmulti/metrics.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var (
2222
iavlTotalNumKeys metric.Int64Gauge
2323
stateSyncKeysExported metric.Int64Counter
2424
subspaceQueryRejected metric.Int64Counter
25+
stateProofRejected metric.Int64Counter
2526
}{
2627
scCommitLatency: must(meter.Float64Histogram(
2728
"sc_commit_latency",
@@ -64,6 +65,11 @@ var (
6465
metric.WithDescription("Number of rejected /subspace ABCI queries by reason"),
6566
metric.WithUnit("{count}"),
6667
)),
68+
stateProofRejected: must(meter.Int64Counter(
69+
"state_proof_rejected",
70+
metric.WithDescription("Number of ABCI /store state proof queries rejected because proofs are disabled, by store and by whether the height is the latest"),
71+
metric.WithUnit("{count}"),
72+
)),
6773
}
6874
)
6975

‎sei-cosmos/storev2/rootmulti/store.go‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type Store struct {
5757
ckvStores map[types.StoreKey]types.CommitKVStore
5858
gigaKeys []string
5959

60+
enableStateProof bool
6061
histProofSem chan struct{}
6162
histProofLimiter *rate.Limiter
6263

@@ -165,6 +166,7 @@ func NewStore(
165166
MaxPairs: scConfig.SubspaceMaxPairs,
166167
MaxBytes: scConfig.SubspaceMaxBytes,
167168
},
169+
enableStateProof: scConfig.EnableStateProof,
168170
hashLoggerConfig: scConfig.HashLogger,
169171
hashLogger: hashLogger,
170172
hashLoggerDisabled: !hashLoggingOn,
@@ -1030,6 +1032,11 @@ func (rs *Store) Query(ctx context.Context, req abci.RequestQuery) abci.Response
10301032

10311033
needProof := req.Prove && rootmulti.RequireProof(subPath)
10321034
latest := version == rs.scStore.Version()
1035+
if needProof {
1036+
if err := rs.admitProofQuery(ctx, storeName, latest); err != nil {
1037+
return sdkerrors.QueryResult(err)
1038+
}
1039+
}
10331040

10341041
// Fast path: no proof + SS enabled
10351042
if !needProof && rs.ssStore != nil {
@@ -1099,6 +1106,19 @@ func (rs *Store) Query(ctx context.Context, req abci.RequestQuery) abci.Response
10991106
return res
11001107
}
11011108

1109+
// admitProofQuery rejects deprecated state proofs unless this node explicitly enables them, and records
1110+
// each rejection by store and by whether the query was at the latest height.
1111+
func (rs *Store) admitProofQuery(ctx context.Context, storeName string, latest bool) error {
1112+
if rs.enableStateProof {
1113+
return nil
1114+
}
1115+
storev2Metrics.stateProofRejected.Add(ctx, 1, otelmetric.WithAttributes(
1116+
attribute.String("store", storeName),
1117+
attribute.Bool("latest", latest),
1118+
))
1119+
return errors.Wrap(sdkerrors.ErrNotSupported, "state proofs are disabled on this node; set state-commit.sc-enable-state-proof = true to enable")
1120+
}
1121+
11021122
// admitSubspaceQuery takes a /subspace permit, or records the rejection and returns why it failed.
11031123
// The caller must release a taken permit. The permits bound concurrent /subspace scans.
11041124
func (rs *Store) admitSubspaceQuery(ctx context.Context) error {

0 commit comments

Comments
 (0)