Skip to content

fix(db): isolate native SQLite on v0.21.4 - #535

Draft
VanshKhanna wants to merge 1 commit into
codex/backport-base-v0.21.4from
codex/sqlite-isolation-v0.21.4
Draft

fix(db): isolate native SQLite on v0.21.4#535
VanshKhanna wants to merge 1 commit into
codex/backport-base-v0.21.4from
codex/sqlite-isolation-v0.21.4

Conversation

@VanshKhanna

@VanshKhanna VanshKhanna commented Sep 10, 2026

Copy link
Copy Markdown

Prevent native WalletKit v0.21.4 from resolving SQLite calls to a host app's unrelated SQLite engine. The original generic sqlite3_* symbols allow link order to select the wrong engine; v0.21.4 also lacks a cipher-availability check, so successful initialization does not establish that encryption is active.

This PR targets codex/backport-base-v0.21.4, pinned to release commit f0e3795d31985b839d372fbd19a6f92b7bda6a0d. It is independent of the activity backport in #533. PR #532 separately addresses current main.

Changes

  • Give the bundled SQLite API internal C linkage and expose 21 WalletKit-prefixed wrappers for Rust. Keep handles and allocations within their creating engine.
  • Select and verify the ChaCha20 cipher before applying a database key or initializing a schema.
  • Add debug/release native hosts that check defined and undefined global SQLite symbols and exercise both library orders with Apple's SQLite and dead stripping enabled.
  • Check independent engines, encrypted persistence/reopening, wrong-key rejection, and preservation of existing file bytes after failed wrong-key and plaintext-store opens, using synthetic data only.

SQLite source/version, compilation settings, encryption parameters, key encoding, vault/envelope formats, dependency lockfile, workspace manifest, and toolchain pins remain those of v0.21.4. This PR contains no credential activity changes or other 0.22.0 functionality.

Validation

  • cargo test -p walletkit-db --locked: all 20 tests pass, including frozen envelope bytes/content IDs and encrypted storage tests.
  • Debug and optimized release native linking regressions pass in both library orders.
  • Rust formatting, ShellCheck, and git diff --check pass.
  • cargo clippy -p walletkit-db --all-targets --locked -- -D warnings: passes.

The local Apple linker emits a nonfatal deployment-target warning (26.5 archive versus 26.0 host). Validation ran in a separate Git worktree using the repository-pinned Rust 1.94.1 toolchain; Nix is unavailable and the Docker daemon is not running.

Review and release

Keep draft for native storage/encryption review. Verify existing encrypted-store upgrade/downgrade behavior and real initialization/proof flows before distribution. The low-level encrypted-open checks preserve and reject plaintext stores; host-level recovery/error handling and any data migration require separate review.

The linking probes remain manual: GitHub rejected workflow edits with the available push credential. Add both commands in SQLITE_ISOLATION_BACKPORT.md to macOS CI with a bounded timeout before release. Cross-platform CI and a full Swift build of this revision remain to be checked.

Assign a distinct reviewed version before publishing, use a narrow internal rollout, and retain the prior SDK artifact with a tested data-preserving rollback path.


Note

High Risk
Changes native encrypted-storage linkage and fail-closed cipher validation; mis-linking or regressions could break encryption or corrupt host SQLite behavior on iOS/macOS.

Overview
Backports a v0.21.4 fix so WalletKit’s bundled sqlite3mc no longer shares unprefixed sqlite3_* symbols with a host app’s SQLite. Native builds compile the amalgamation through native_sqlite.c with internal linkage and route Rust FFI through 21 walletkit_sqlite3_* wrappers; ffi.rs binds those symbols explicitly.

Encrypted open now selects and verifies ChaCha20 via PRAGMA cipher before applying a key, failing closed if the wrong engine is linked (v0.21.4 previously could “open” without proving encryption).

Adds macOS native linking regressions: a staticlib probe (native_link_probe), a C host that links Apple SQLite in both orders, symbol checks with nm, and synthetic tests for encrypted round-trip, wrong-key rejection, and unchanged bytes on failed opens. Documents validation in SQLITE_ISOLATION_BACKPORT.md. Amalgamation version, cipher settings, and on-disk formats are unchanged.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T23:38:48.081328Z 5de9a97 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@VanshKhanna
VanshKhanna marked this pull request as draft September 10, 2026 23:36

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5de9a975ed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let conn = Connection::open(path, read_only)?;
// A host application can link another SQLite implementation. Fail before
// applying a key or writing a schema if the encrypted engine is unavailable.
conn.execute_batch("PRAGMA cipher = 'chacha20';")?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add a frozen pre-backport database compatibility test

For upgrades from the released v0.21.4, this explicit cipher selection is format-sensitive, but the added probes only create and reopen databases using the new code, so they would still pass if this sequence made databases produced by f0e3795 unreadable. Add a frozen encrypted database produced by the pre-backport implementation and verify that this path opens and reads it without changing its bytes.

AGENTS.md reference: AGENTS.md:L9-L9

Useful? React with 👍 / 👎.

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.

1 participant