Skip to content

lwwallet: reduce browser wallet public KDF cost#1048

Draft
Roasbeef wants to merge 1 commit into
mainfrom
perf/browser-wallet-kdf
Draft

lwwallet: reduce browser wallet public KDF cost#1048
Roasbeef wants to merge 1 commit into
mainfrom
perf/browser-wallet-kdf

Conversation

@Roasbeef

Copy link
Copy Markdown
Member

Summary

In this PR, we reduce browser wallet create and unlock time by configuring
independent scrypt profiles for btcwallet's public and private master keys.
The fixed lwwallet public passphrase protects public wallet metadata, so its
creation profile uses N=16. The user-supplied private passphrase keeps
btcwallet's default N=262144 profile.

The change is limited to the WASM wallet bootstrap. Native builds retain their
existing loader path, existing browser databases retain their persisted KDF
parameters, and only newly created browser wallets receive the faster public
profile.

The latest five-run browser benchmark with
lightninglabs/wavelength-sdk#53 measured:

  • Runtime ready p95: 276 ms.
  • WASM load and instantiate p95: 138 ms.
  • Wallet create total p95: 1,886 ms.
  • Wallet unlock total p95: 669 ms.
  • Performance budget violations: 0.

Technical Notes

This PR temporarily replaces github.com/btcsuite/btcwallet with the exact
fork commit from btcsuite/btcwallet#1298. The replace directive and fork
checksums can be removed once that PR merges and Wavelength advances to the
upstream commit.

The private KDF is selected explicitly rather than relying on an implicit
default. This keeps the security boundary visible in the call site.

Steps to Test

go test ./lwwallet
GOOS=js GOARCH=wasm go test -exec=true ./lwwallet
make lint-changed-local base=origin/main

For the browser benchmark:

WAVELENGTH_DIR=/path/to/wavelength \
  pnpm --dir /path/to/wavelength-sdk \
  --filter web-wallet-demo run wasm:local

pnpm --dir /path/to/wavelength-sdk perf:web

Related Issues and Pull Requests

In this commit, we open browser wallets through a loader configured with independent scrypt profiles. The static public passphrase uses N=16 while the private master key retains btcwallet defaults. This removes nearly all public-only KDF work during create and unlock without changing private-key protection.

Native builds keep the existing loader path, and existing browser databases keep their persisted parameters. The temporary fork pin can be removed once btcsuite/btcwallet#1298 merges.
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

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