Skip to content

Migrate voting recovery state to SQLite DB#3

Merged
czarcas7ic merged 1 commit into
mainfrom
adam/recovery-state-to-db
Mar 17, 2026
Merged

Migrate voting recovery state to SQLite DB#3
czarcas7ic merged 1 commit into
mainfrom
adam/recovery-state-to-db

Conversation

@czarcas7ic
Copy link
Copy Markdown
Contributor

@czarcas7ic czarcas7ic commented Mar 17, 2026

Summary

Move crash-recovery data (delegation TX hashes, vote TX hashes, vote commitment bundles, Keystone signatures) from Swift-side JSON files into the existing voting SQLite database.

  • Schema v5: add delegation_tx_hash to bundles, tx_hash / vc_tree_position / commitment_bundle_json to votes
  • New keystone_signatures table for Keystone signing recovery
  • New share_delegations table (schema only — populated by upcoming share status feature)
  • KeystoneSignatureRecord type for reading back stored signatures
  • 10 new query functions: store/get delegation TX hash, store/get vote TX hash, store/get commitment bundle, store/get keystone signatures, clear recovery state
  • VotingDb operation wrappers for all new queries

Move crash-recovery data (delegation TX hashes, vote TX hashes,
vote commitment bundles, Keystone signatures) from Swift-side JSON
files into the existing voting SQLite database.

Schema v5: adds delegation_tx_hash to bundles, tx_hash +
vc_tree_position + commitment_bundle_json to votes, new
keystone_signatures and share_delegations tables.
@czarcas7ic czarcas7ic force-pushed the adam/recovery-state-to-db branch from 2eb98b3 to c0e543e Compare March 17, 2026 04:08
@czarcas7ic czarcas7ic marked this pull request as ready for review March 17, 2026 04:13
Copy link
Copy Markdown
Contributor

@greg0x greg0x left a comment

Choose a reason for hiding this comment

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

Nice! I was worried about the migration, but you got it right.

Note: when we go live, we will need to start using the incremental migrations.

@czarcas7ic czarcas7ic merged commit 31605b8 into main Mar 17, 2026
p0mvn added a commit that referenced this pull request Mar 21, 2026
…ipt lifecycle

Add the Rust-side infrastructure for the fire-persist-poll share reveal
confirmation system. After CastVote TX confirms, the wallet delegates
encrypted shares to helpers and polls for on-chain reveal confirmation
using deterministic share nullifiers.

Schema (migration v6):
- votes: add `van_authority_spent` column, separate from `submitted` —
  tracks CastVote TX confirmation for proposal_authority bitmask while
  `submitted` tracks share-reveal completion.
- share_delegations: PK now includes `helper_url` (one receipt per
  helper per share); renamed nullifier→share_nullifier,
  confirmed→reveal_confirmed; added `seq`, `submit_at` columns.

Storage operations:
- ShareDelegationReceipt and PendingShareRevealGroup types with serde.
- CRUD: store/list/clear receipts, mark_share_revealed_for_helper,
  list_pending_share_reveal_groups (joins votes.submitted=0).
- mark_van_authority_spent with rows-affected guard.
- store_vote uses ON CONFLICT to preserve submitted/van_authority_spent
  on crash-retry re-insert.
- Release DB mutex during long-running ZKP #1 proof generation so
  share-polling callers aren't blocked.

Nullifier derivation:
- compute_share_nullifier() chains vote_commitment_hash →
  share_nullifier_hash (Poseidon, same domain tags as ZKP #3 circuit).
- build_share_payloads includes share_nullifier in each SharePayload.
- round_id_bytes_from_hex rejects inputs >32 bytes.

Also fixes pre-existing build error in zkp2.rs (upstream voting-circuits
removed single_share parameter from build_vote_proof_from_delegation).

Made-with: Cursor
p0mvn added a commit that referenced this pull request Mar 21, 2026
…ipt lifecycle

Add the Rust-side infrastructure for the fire-persist-poll share reveal
confirmation system. After CastVote TX confirms, the wallet delegates
encrypted shares to helpers and polls for on-chain reveal confirmation
using deterministic share nullifiers.

Schema (migration v6):
- votes: add `van_authority_spent` column, separate from `submitted` —
  tracks CastVote TX confirmation for proposal_authority bitmask while
  `submitted` tracks share-reveal completion.
- share_delegations: PK now includes `helper_url` (one receipt per
  helper per share); renamed nullifier→share_nullifier,
  confirmed→reveal_confirmed; added `seq`, `submit_at` columns.

Storage operations:
- ShareDelegationReceipt and PendingShareRevealGroup types with serde.
- CRUD: store/list/clear receipts, mark_share_revealed_for_helper,
  list_pending_share_reveal_groups (joins votes.submitted=0).
- mark_van_authority_spent with rows-affected guard.
- store_vote uses ON CONFLICT to preserve submitted/van_authority_spent
  on crash-retry re-insert.
- Release DB mutex during long-running ZKP #1 proof generation so
  share-polling callers aren't blocked.

Nullifier derivation:
- compute_share_nullifier() chains vote_commitment_hash →
  share_nullifier_hash (Poseidon, same domain tags as ZKP #3 circuit).
- build_share_payloads includes share_nullifier in each SharePayload.
- round_id_bytes_from_hex rejects inputs >32 bytes.

Also fixes pre-existing build error in zkp2.rs (upstream voting-circuits
removed single_share parameter from build_vote_proof_from_delegation).

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants