Repository navigation
feat(platform)!: emergency switches the evonodes flip to pause or turn off a feature - #6395
Conversation
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
…n off features Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
…SDKs Co-Authored-By: Claude Fable 5.2 <[email protected]>
…itten clients Co-Authored-By: Claude Fable 5.2 <[email protected]>
… holds back, and document emergency switches Co-Authored-By: Claude Fable 5.2 <[email protected]>
…ch moves at genesis Co-Authored-By: Claude Fable 5.2 <[email protected]>
…otlin SDKs Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Important Review skippedToo many files! This PR contains 217 files, which is 117 over the limit of 100. To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to a paid plan to raise the limit. This organization's CodeRabbit subscription is cancelled. Resubscribe in Billing to continue reviews beyond the free-tier limit.
|
|
🌳 GroveDB structure This pull request changes the described GroveDB structure. Open it in the structure viewer: new nodes glow, removed ones stay as ghosts, and the tour walks through each change. Added (5 nodes)
Changed (1 node)
Compared |
|
📖 Book Preview built successfully. Download the preview from the workflow artifacts. Updated at 2026-11-30T08:29:25.342Z |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
✅ Final review complete — no blockers (commit f2b53c4) · triage: critical |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
This change adds protocol-16 emergency switches across consensus validation, Drive storage and proofs, DAPI, SDKs, and mobile/WASM bindings. No code checks are failing in the available CI snapshot; the Kotlin build, NPM validation, changed-package detection, and PR Hygiene checks are still pending.
🟡 7 suggestion(s) | 💬 2 nitpick(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🟡 Suggestion: The transition-level balance gate still treats free emergency votes as paid
Impact: Any internal caller that invokes the masternode-vote balance validation directly for an emergency-switch vote receives a CorruptedCodeExecution error instead of the free-vote path.
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/balance/mod.rs:48-50
The state-transition implementation correctly returns false for Vote::EmergencySwitchVote, but the MasternodeVoteTransition implementation returns true unconditionally. Its balance validator then calls specialized_balance_id(), which returns None for the free vote and is converted into a CorruptedCodeExecution error. The current production processor reaches the state-transition gate first, so this is not currently observable on the main path, but the two trait implementations disagree and future estimation, tooling, or tests can hit the failing path. Mirror the emergency-vote exemption in the transition-level method as well.
source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality)
Review provenance
Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 8: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 9: gpt-6.2-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — This large, cross-cutting diff changes consensus-critical emergency-switch rules, signature-backed voting and key gating, withdrawal/funds movement behavior, peer-facing serialization and persisted Drive state in files such as packages/rs-dpp/src/voting/emergency_switch/mod.rs, packages/rs-drive-abci/src/execution/platform_events/voting/evaluate_emergency_switches/v0/mod.rs, and packages/rs-drive/ - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— tenderdash-consensus-security (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/balance/mod.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/balance/mod.rs:48-50: The transition-level balance gate still treats free emergency votes as paid
Impact: Any internal caller that invokes the masternode-vote balance validation directly for an emergency-switch vote receives a CorruptedCodeExecution error instead of the free-vote path.
The state-transition implementation correctly returns false for `Vote::EmergencySwitchVote`, but the `MasternodeVoteTransition` implementation returns true unconditionally. Its balance validator then calls `specialized_balance_id()`, which returns `None` for the free vote and is converted into a CorruptedCodeExecution error. The current production processor reaches the state-transition gate first, so this is not currently observable on the main path, but the two trait implementations disagree and future estimation, tooling, or tests can hit the failing path. Mirror the emergency-vote exemption in the transition-level method as well.
In `packages/rs-drive-abci/src/execution/validation/state_transition/check_tx_verification/v0/mod.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/check_tx_verification/v0/mod.rs:542-552: Recheck keeps transactions signed with a paused key type in the mempool
Impact: When a key-type switch is activated, mempools retain already-admitted transactions using that key type, causing proposers and validators to repeatedly process and strip them instead of evicting them during recheck.
First-time check-tx loads the signing identity and applies the key-type emergency gate, but recheck deliberately passes `None` because it verifies no signature and loads no signing key. Consequently, `KeyTypeEcdsaSecp256k1` and the other signing-key switches are not checked during recheck. Block execution remains safe because it refuses the transition unpaid, but a large pre-existing mempool can repeatedly include these transactions during the emergency. Cache the signing key type or key id at admission and use it during recheck so key-type-gated transactions are evicted promptly.
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/check_tx_verification/v0/mod.rs:245-252: Check-tx continues refusing transitions for one block after a pause expires
Impact: Users submitting a gated transition immediately after the pause end can receive a mempool refusal even though the next block would accept the same transition.
The check-tx path evaluates emergency-switch status using `platform.state.last_block_info().time_ms`, while block validation evaluates it using the candidate block's own `block_info.time_ms`. The status is also the last committed status, so after a pause expires between commits, check-tx remains fail-closed until the next block advances the committed state. This does not create a consensus split, but it causes a short liveness dip after every pause. Document the intentional one-block admission lag or use a fresher admission-time reference where available.
In `packages/wasm-sdk/src/emergency_switches.rs`:
- [NITPICK] packages/wasm-sdk/src/emergency_switches.rs:228-234: WASM flip paging does not document the required proTxHash byte orientation
Impact: WASM users paging flips or combining a paging result with voting APIs can supply a differently oriented 32-byte hash and retrieve the wrong page or fail to address the intended evonode.
The voting option documents that `masternodeProTxHash` is in ProTxHash order, but `startAfterProTxHash` is documented only as the last pro tx hash. The FFI, Swift, and Kotlin APIs explicitly describe their wire-order/display-order conversion, while the WASM paging comment does not. State the expected orientation for both WASM hash parameters and clarify how `Identifier` display parsing maps to it.
In `packages/rs-dpp/src/voting/emergency_switch/status/v0/mod.rs`:
- [SUGGESTION] packages/rs-dpp/src/voting/emergency_switch/status/v0/mod.rs:80-100: Pause-tier counters silently wrap if a future tier table exceeds 255 entries
Impact: A future protocol configuration with more than 255 pause tiers would store an incorrect `pause_tiers_fired` value and could cause tiers to be revisited or skipped.
Both `tiers.len() as u8` and `index as u8 + 1` rely on narrowing casts. The current `SystemLimits` table has three tiers, so these casts are inert today, but a future expansion can silently truncate rather than fail deterministically. Use checked `u8` conversions for both assignments and return a protocol error if the configured tier count cannot be represented.
In `packages/rs-sdk/src/platform/emergency_switches.rs`:
- [SUGGESTION] packages/rs-sdk/src/platform/emergency_switches.rs:29-32: The flips query fails against nodes configured with a lower default query limit
Impact: An SDK user querying a node whose `default_query_limit` is below 100 receives an invalid-argument error for every flips fetch that omits an explicit limit.
The SDK always writes `DEFAULT_EMERGENCY_SWITCH_FLIPS_LIMIT` as 100 because proof verification needs the actual limit in the request. The node independently rejects any limit greater than its operator-configured `default_query_limit`, so lowering that setting makes the SDK's ordinary flips query fail rather than return a page. Align the client and node limit contract where possible, or detect this invalid-argument response and expose a clear limit-mismatch error with a way to request a supported page size.
In `packages/rs-sdk-ffi/src/emergency_switch/mod.rs`:
- [NITPICK] packages/rs-sdk-ffi/src/emergency_switch/mod.rs:45-51: Every FFI switch lookup allocates and parses JSON for a fixed name set
Impact: Each emergency-switch read or vote performs an avoidable string allocation and serde dispatch despite accepting only seven fixed camelCase names.
The FFI already has the borrowed C string from `required_str`, but converts it to an owned `String`, wraps it in a JSON value, and deserializes it to select one of seven enum variants. A direct match makes the accepted names visible at the FFI boundary and avoids the extra allocation and serde work while preserving the same invalid-parameter behavior.
In `packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/transform_into_action/v2/mod.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/masternode_vote/transform_into_action/v2/mod.rs:111-123: Flip validation exposes consensus refusals through a nested Result type
Impact: Future callers can mishandle a consensus refusal as an internal failure, or vice versa, because the function requires separate handling of two error layers.
`previous_emergency_switch_flip_changes` returns `Result<Result<u16, ConsensusError>, Error>`, whereas neighboring validation helpers use a single `ConsensusValidationResult` to distinguish consensus-invalid input from internal errors. The current caller handles the nested result correctly, but every future caller must remember to map the inner error explicitly. Return the established validation-result type directly so the distinction is enforced by the API.
In `packages/rs-drive-abci/src/query/voting/emergency_switch_flips/v0/mod.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/query/voting/emergency_switch_flips/v0/mod.rs:33-40: Nodes can accept flip queries for switch IDs inactive at the negotiated protocol version
Impact: A node binary that knows a future switch but is running an older protocol version can accept that switch ID and return an empty result or proof instead of rejecting the request as inactive.
The query validates `switch_id` only with `EmergencySwitch::from_storage_key`, which checks the enum values known to the binary but not whether the decoded switch is present in `EmergencySwitch::existing(platform_version)`. The same version-blind conversion exists in the proof verifier, and the SDK vote builder only checks that the protocol is at least 16. Once a later protocol adds a switch to the enum, a v16 node built with that later binary can expose the future ID through the query and proof surfaces, while a vote for it is rejected only after broadcast. Validate the decoded switch against the active protocol version at the DAPI and proof-verifier boundaries, and reject inactive switches when constructing SDK votes.
|
Bots are done — your move: post |
…o the protocol version Review fixes: a recheck reads the signing key while a switch refuses something, the flips query, its proof verifier and the SDK vote builder refuse a switch the protocol version does not have, tier counts use checked conversions, the flip validation returns a validation result, and the WASM docs state the pro tx hash order. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 2 only (queue backlog)
New on this head: This head adds protocol-version checks for emergency-switch queries and votes, hardens pause-tier counters, documents hash ordering and check-tx timing, and updates mempool recheck handling for newly gated key types. CI has no reported failed code checks; build and test checks are still queued or in progress.
🟡 1 suggestion(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Review provenance
Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — This is a large, intricate diff that changes consensus-critical emergency-switch evaluation and state-transition validation in rs-drive-abci, cryptographic vote/key handling, peer-facing gRPC serialization, withdrawal processing, and persisted Drive state. - Phase 1 reviewers: not run (skipped for throughput: 12 PRs queued, above the 10 limit)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— tenderdash-consensus-security (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-drive-abci/src/execution/validation/state_transition/processor/traits/emergency_switches.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/processor/traits/emergency_switches.rs:140-158: Every active emergency pause makes identity-signed mempool rechecks read GroveDB
Impact: While a non-key switch such as withdrawals or platform-address spends is paused, every retained identity-signed transaction incurs an unnecessary identity-key lookup on each mempool recheck.
The recheck path performs a GroveDB lookup whenever any emergency switch blocks something, even when the active switch cannot depend on the transition's identity key type. `something_is_refused` is computed from all active statuses before checking whether a key-type switch is involved, so a `StopTransfersToCore` or `PlatformAddressSpends` pause causes ordinary identity-signed transactions to call `fetch_identity_keys_as_partial_identity` individually. Tenderdash rechecks retained transactions after blocks, multiplying these reads during an emergency when recheck latency is already important. Restrict the lookup to the presence of a currently blocking identity-key-type switch, while still running normal emergency-switch validation for non-key switches.
|
Bots are done — your move: post |
…e switch refuses A recheck read the signing key from storage whenever any emergency switch refused something. Only the switch of a key type depends on that key, so a pause of withdrawals or of platform address spends made every identity-signed transaction in the mempool cost one more read per recheck for nothing. The read now happens only while the switch of some key type refuses. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
New on this head: The incremental commit narrows mempool recheck identity lookups to active key-type emergency switches, avoiding reads for withdrawal and platform-address pauses while preserving the existing gate validation. No completed code check has failed at this head, but runner generation and contract/build checks remain queued or in progress.
🟡 1 suggestion(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 9: gpt-6.2-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — This is a large, intricate consensus change that modifies emergency-switch voting, state-transition validation, block finalization, withdrawals, identity key handling, cryptographic signatures, peer-facing serialization, and persisted Drive state. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— tenderdash-consensus-security (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-drive-abci/src/execution/validation/state_transition/processor/traits/emergency_switches.rs`:
- [SUGGESTION] packages/rs-drive-abci/src/execution/validation/state_transition/processor/traits/emergency_switches.rs:144-150: Emergency-switch votes still trigger identity reads during a key-type pause
Impact: While any identity key-type switch is blocking, every recheck of an emergency-switch vote performs an unnecessary GroveDB signing-key lookup even though the vote is explicitly exempt and will be accepted.
Emergency-switch votes can still incur a storage read on every mempool recheck during a key-type pause, adding avoidable work to the voting path needed to escalate or resolve an emergency. This predicate causes the lookup for every identity-signed transition whenever a key-type status blocks; only afterward does `validate_emergency_switches` call `StateTransition::gating_emergency_switches`, whose `EmergencySwitchVote` arm returns an empty set. Expose an owner-level indication that a transition can be gated by its signing key type, or otherwise avoid loading the key for exempt vote transitions without duplicating the complete gating rule in `rs-drive-abci`.
|
Bots are done — your move: post |
…gency switch No emergency switch gates a vote on a switch, but while a key type switch refused, a recheck still read the vote's signing key before finding that out. The exemption is now one function in rs-dpp, `StateTransition::is_exempt_from_emergency_switches`, which `gating_emergency_switches` uses and the recheck asks before it reads. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
New on this head: The final incremental commit centralizes the emergency-switch-vote exemption in rs-dpp and uses it before mempool recheck signing-key lookup, with targeted coverage for switch votes and ordinary votes. The CI snapshot shows no failed code checks; several build, generation, policy, and hygiene checks remain queued or in progress.
🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 9: gpt-6.2-astra (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — This is a large, intricate change that directly modifies consensus rules, signature/key handling, peer-facing serialization, state transitions, and persisted Drive state across rs-dpp, rs-drive, and rs-drive-abci. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— tenderdash-consensus-security (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.
No unresolved findings remain from the prior review on this head.
|
Bots are done — your move: post |
…dsa-65-keys v5.2-dev gained the emergency switches (#6395), which give every identity key type its own switch, and EmergencySwitch::for_key_type matches on KeyType without a wildcard so that a new key type must decide its switch. This merge adds that switch for ML_DSA_65: EmergencySwitch::KeyTypeMlDsa65, id 7, appended to the switches of protocol version 16. It gates a state transition signed with an ML_DSA_65 identity key and one adding such a key, through the same code as the other key types. A switch nobody has voted on stores nothing, so no state changes. Conflicts: the feature_initial_protocol_versions import in state_transition/mod.rs (both names kept) and the notes of v16.rs (the emergency switches stay note 2, which the table comments cite; ML_DSA_65 keys become note 3). Co-Authored-By: Claude Fable 5.2 <[email protected]>
Basic explanation
What this does: Adds emergency switches: off switches for single Platform features that the evonodes flip by vote. When a quarter of the evonodes flip a switch, the feature it guards is paused for an hour. A half pauses it for six hours, two thirds for ten days, and three quarters turn it off until a later protocol version turns it back on. Each pause can happen only once per switch, ever. Switches are defined in code; nothing creates one at run time. This first version ships seven of them at protocol version 16: one that stops transfers of credits to Dash Core, one that stops spends from platform addresses, and one per identity key type (five today).
Value: If a signature scheme or the bridge to Core is found broken, the network can stop the damage in one block instead of waiting for a release and an upgrade vote. A minority can buy time (at most 1 hour under a half, 7 hours under two thirds, 10 days and 7 hours under three quarters, over the whole life of a switch) without being able to hold a feature hostage.
Risks: Medium. This is new consensus code at protocol version 16, which is unreleased, and nothing changes at earlier versions.
ECDSA_SECP256K1that is nearly every identity today. This is the intended effect of "this key type is broken", but it is severe.ECDSA_HASH160. If ECDSA is truly broken, votes can be forged. A forged vote can push a switch towards off, or withdraw a flip between pauses. It cannot bring back a feature that was turned off, because off is latched, and it cannot lower the share during a pause.Issue being fixed or feature implemented
Platform has no way to stop a feature quickly. A fix for a broken signature scheme, or for a problem with withdrawals to Core, needs a release and a protocol upgrade vote, which takes days at best.
What was done?
The rule
SystemLimits.The switches
StopTransfersToCorePlatformAddressSpendsKeyTypeEcdsaSecp256k1,KeyTypeBls12381,KeyTypeEcdsaHash160KeyTypeBip13ScriptHash,KeyTypeEddsa25519Hash160EmergencySwitch::for_key_typematches every key type, so a key type added later does not compile until its switch is decided. #6354 adds ML-DSA-65 keys: whichever of the two merges second adds that switch."ECDSA is broken" is three switches: both ECDSA key types and
PlatformAddressSpends. The BLS switch covers identity keys only; quorum signatures, chain locks and instant locks are consensus and are not gated. Block execution keeps writing masternode identity keys of every type: a switch never gates what the system writes.A flip
A flip is a masternode vote,
Vote::EmergencySwitchVote { switch, flipped }, carried by the existingMasternodeVotestate transition and signed with the voting key.KeyTypeEcdsaHash160would stop the votes that escalate it.What a client sees
Before: a withdrawal sent while transfers to Core are in trouble is accepted, queued and sent.
After, with
StopTransfersToCorepaused: the withdrawal is refused in check tx and never enters a block, without a fee:Reading the switches and voting (the values are an example):
By layer
VOTING_VERSION_V4,DRIVE_VOTE_METHOD_VERSIONS_V5,DRIVE_VERIFY_METHOD_VERSIONS_V5,DRIVE_ABCI_METHOD_VERSIONS_V12andDRIVE_ABCI_VALIDATION_VERSIONS_V12, selected byPLATFORM_V16only. NewSystemLimitsfields, backfilled. v16 note 2 describes the feature.EmergencySwitch,EmergencySwitchStatuswith the tier rule (advance),EmergencySwitchFlip, the vote variant,StateTransition::gating_emergency_switches(the one place that says what each switch gates), and seven consensus errors (41400 to 41406).register_identity_vote2,remove_all_votes_given_by_identities2; proofs and verifiers. Described instructure.rs,grovedb-structure.jsonregenerated.evaluate_emergency_switches,validate_emergency_switches(a new check in the processor and in check tx, first time and recheck), masternode votetransform_into_action2, and a new generation of the three withdrawal steps. Statuses are kept in the platform state and read from Drive when it is loaded.getEmergencySwitchesandgetEmergencySwitchFlips, with proofs, through rs-dapi, rs-dapi-client, the proof verifier, rs-sdk, wasm-sdk and js-evo-sdk. Generated gRPC clients regenerated.dash_sdk_emergency_switch*in rs-sdk-ffi, Swift and Kotlin wrappers. No example app screens.One thing found while building: with queued withdrawals held back by the switch, the node would have asked Tenderdash for an immediate next block on every block for the whole pause. The hint is now off while the switch blocks.
In-place changes to shipped generations
Each is unreachable before protocol version 16: no vote on an emergency switch decodes there (
StateTransition::active_version_range), and every new method slot isNonethere.run_block_proposal0 (every version): callsevaluate_emergency_switches, an optional method whose dispatcher returns without reading or writing when its slot isNone, and hands the block's platform state to the three withdrawal steps, whose earlier generations do not read it.process_state_transition0 andstate_transition_to_execution_event_for_check_tx0 (every version): callvalidate_emergency_switches, which returns valid without reading anything when its slot isNone.finalize_block_proposal0 (every version): the next-block hint also reads whetherStopTransfersToCoreblocks. The hint changes no fee, state or app hash, and no switch exists before 16.transform_into_action0 and 1,validate_state0 and 1,register_identity_vote0,VoteResolver: an arm for the new variant that returns an internal error, or passes the action on (validate_state1). The variant cannot be built before 16.MasternodeVoteTransitionAction::into_high_level_drive_operations0,ExecutionEvent::create_from_state_transition_actionanduses_prefunded_specialized_balance_for_payment: a vote on a switch deducts from no fund and is a free event. Only the new variant takes these branches.prove_state_transition0,verify_state_transition_was_executed_with_proof0 andDrive::verify_masternode_vote: an arm that proves and verifies the stored flip, off the block execution path.fetch_platform_statedispatcher: after loading, reads the switch statuses from Drive when the loaded state's protocol version has any switch; nothing is read before 16.Public interface changes
dapi-grpc (wire): two new RPCs,
getEmergencySwitchesandgetEmergencySwitchFlips, with their request and response messages. Nothing existing changes.rs-dpp
dpp::voting::emergency_switch::{EmergencySwitch, EmergencySwitchStatus, EmergencySwitchFlip, EvonodeEmergencySwitchFlip},dpp::voting::votes::emergency_switch_vote::EmergencySwitchVote.dpp::voting::votes::Votegains the variantEmergencySwitchVote, appended. Code that matchesVoteexhaustively no longer compiles until it adds the arm.Vote::vote_poll_unique_idreturns an error for the new variant (it answers no poll);Vote::specialized_balance_idreturnsNonefor it.StateErrorgains seven variants, appended: discriminants 183 to 189, codes 41400 to 41406. Exhaustive matches onStateErrorneed the arms.StateTransition::gating_emergency_switches(signing_key_type: Option<KeyType>) -> BTreeSet<EmergencySwitch>.rs-platform-version
SystemLimitsgainsemergency_switch_pause_tiers,emergency_switch_off_share_numerator,emergency_switch_off_share_denominator,max_emergency_switch_flip_changes_per_evonode, and the typeEmergencySwitchPauseTier. Struct literals ofSystemLimitsneed the fields.Nonebefore 16, inDPPVotingVersions,DriveVoteMethodVersions(emergency_switch),DriveVerifyVoteMethodVersions,DriveAbciVotingMethodVersions,DriveAbciValidationVersionsandDriveAbciQueryVotingVersions.EMERGENCY_SWITCHES_INITIAL_PROTOCOL_VERSION = 16.rs-drive
ResolvedVotegainsEmergencySwitchVote(ResolvedEmergencySwitchVote); exhaustive matches need the arm.Drive::{insert_emergency_switch_trees, register_emergency_switch_flip, register_emergency_switch_flip_operations, fetch_emergency_switch_flip, fetch_emergency_switch_flips, fetch_emergency_switch_statuses, store_emergency_switch_status, remove_emergency_switch_flips_given_by_identities, verify_masternode_emergency_switch_vote},drive::query::emergency_switch_query::{EmergencySwitchStatusesDriveQuery, EmergencySwitchFlipsDriveQuery},drive::drive::votes::emergency_switch::paths.rs-drive-abci
PlatformStategains the public fieldemergency_switch_statuses, andPlatformStateV0Methodsfive methods. The saved record is unchanged.rs-sdk: new module
dash_sdk::platform::emergency_switches(EmergencySwitchStatusesQuery,EmergencySwitchFlipsQuery,EmergencySwitchStatuses,EmergencySwitchFlips,Sdk::emergency_switch_vote).PutVotecasts the new vote unchanged.wasm-dpp2 / wasm-sdk / js-evo-sdk:
Vote.emergencySwitch(name, flipped), the gettersemergencySwitchNameandflipped;getEmergencySwitches,getEmergencySwitchFlips(each alsoWithProofInfo) andemergencySwitchVote;sdk.voting.emergencySwitches(),emergencySwitchFlips(),emergencySwitchVote()and theWithProofforms. TheVoteObjectandVoteJSONtypes gain theemergencySwitchVoteshape.rs-sdk-ffi:
dash_sdk_emergency_switches_get,dash_sdk_emergency_switch_flips_get,dash_sdk_emergency_switch_vote,dash_sdk_emergency_switch_vote_with_signer. Reads return JSON arrays; a pro tx hash is hex of the wire-order bytes, the orientation every pro tx hash argument of this FFI takes.What stays the same: every stored byte, hash and proof at protocol versions 1 to 15; the saved platform state record; every existing RPC and SDK call. At protocol version 16 the genesis state gains the new branch of the votes tree, which moves the state root (ten pinned hashes in
nullifier_batch_guard.rswere re-pinned).How Has This Been Tested?
Targeted runs, all passing:
rs-dpp: 23 tests underemergency_switch(the tier rule at each threshold, tiers firing once, the jump over tiers, the latch, the list shrinking, an empty list, which transitions each switch gates, the decode gate at 15 and 16) and the frozenStateErrordiscriminants.rs-platform-version: the shares rise up to the off share in every version.rs-drive: flips and statuses read, proved and verified; the flips of removed masternodes removed; the structure tests (the description matches a real GroveDB at every protocol version and every described node is reached).rs-drive-abci: 10 behaviour tests that run votes and gated transitions through check tx and a block (an evonode's flip and withdrawal, a regular masternode refused, each pause once, off latched, a withdrawal held until the pause ends, the change limit, banned and removed evonodes not counted, a withdrawal to Core refused while paused and accepted after, the key type gate and the exemption of switch votes, statuses read back when the state is loaded, nothing happening at protocol version 15); the three withdrawal steps leaving withdrawals where they are while paused; the query handlers with proofs; the next-block hint.voting_default_limitsandnonunique_merged_proof.dash-sdk,drive-proof-verifier,rs-dapi-client(request inventory),rs-sdk-ffi(7),rs-unified-sdk-jni(1),@dashevo/dapi-grpcunit tests (77), KotlinEmergencySwitchModelsTest(4, with the SDK compiling).cargo clippy --all-targets --all-features --locked -- --no-deps -D warningsonplatform-version,dpp,drive,drive-abci,rs-dapi,rs-dapi-client,drive-proof-verifier,dash-sdk,wasm-dpp,wasm-dpp2,wasm-sdk,rs-sdk-ffi,rs-unified-sdk-jni;cargo fmt --all --check;cargo check --workspace --all-targets.Not yet verified:
build_ios.shorxcodebuildrun).js-evo-sdkfacade specs and the wasm32 builds were not run.Not done in this pull request
dashmate statusreads Tenderdash and Docker only and has no DAPI query path today.Breaking Changes
Consensus changes at protocol version 16 only, which is unreleased: a new vote kind, a new branch of the votes tree at genesis and on upgrade, a new unpaid refusal of gated state transitions, and withdrawal steps that pause. Protocol versions 1 to 15 are unchanged.
Source-level:
Vote,ResolvedVoteandStateErrorgain variants andSystemLimitsgains fields (see Public interface changes).Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull request (described and regenerated; the viewer link is not checked yet)For repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
f2b53c4/self-reviewedsdk-parity— you own itjs-wasm-sdk(packages/js-evo-sdk/src/voting/facade.ts,packages/js-evo-sdk/tests/unit/facades/voting.spec.ts,packages/wasm-sdk/src/emergency_switches.rsand 1 more) — approved by shumkovkotlin-sdk(packages/kotlin-sdk/PARITY_SUMMARY.md,packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/Sdk.kt,packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/ffi/EmergencySwitchesNative.ktand 5 more) — HashEngineeringrust-dapi(packages/rs-dapi/src/metrics.rs,packages/rs-dapi/src/services/platform_service/mod.rs) — approved by shumkovdpp— you own itrs-drive-abci— you own itrs-drive— you own itrust-sdk-ffi(packages/rs-sdk-ffi/src/emergency_switch/json.rs,packages/rs-sdk-ffi/src/emergency_switch/mod.rs,packages/rs-sdk-ffi/src/emergency_switch/queries.rsand 2 more) — approved by shumkovrust-sdk(packages/rs-sdk/src/mock/requests.rs,packages/rs-sdk/src/mock/sdk.rs,packages/rs-sdk/src/platform.rsand 3 more) — approved by shumkovswift-sdk(packages/swift-sdk/Sources/SwiftDashSDK/Voting/EmergencySwitch.swift,packages/swift-sdk/Sources/SwiftDashSDK/Voting/SDK+EmergencySwitches.swift,packages/swift-sdk/SwiftTests/SwiftDashSDKTests/EmergencySwitchDecodingTests.swift) — llbartekll or romchornyiWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.