Skip to content

fix: hardening sweep across wallet, bridge, trading and deploy surfaces - #39

Merged
erubboli merged 52 commits into
mainfrom
feat/ocr-sweep-2
Nov 3, 2026
Merged

erubboli merged 52 commits into
mainfrom
feat/ocr-sweep-2

Conversation

@erubboli

@erubboli erubboli commented Nov 3, 2026

Copy link
Copy Markdown
Member

What this is

A full hardening pass across the GUI, the Bitcoin sidecar, and the deploy tooling: 52 fix commits delivered in 8 incremental rounds over 8 components (shared libraries, auth/session/bootstrap, wallet RPC surface, Bitcoin wallet, bridge, tokens/trading, management pages, infra/deploy). Every round re-reviewed the whole component after fixes, until components converged or the round cap was reached.

Highlights

Bitcoin wallet (bdk-wallet + BitcoinWallet.tsx)

  • /send no longer parks on the wallet mutex during scans (double-spend hazard: a timed-out send still broadcast, retry queued a second spend behind the same lock)
  • Prune-window guard now evaluates the same origin BDK actually rescans from (last sync time, persisted across restarts) instead of the creation horizon, so healthy wallets stop being frozen on pruned nodes
  • Concurrent wallet creation can no longer delete another tab's seed.json; seed-file cleanup skips AlreadyExists
  • Network mismatch between seed file and config refused loudly at boot; dust sends classified as 400 instead of 500; send/balance/address endpoints return busy-responses instead of blocking during scans
  • Fee estimate refetched on demand with an explicit notice when the 1 sat/vB default is used

Auth / bootstrap

  • Passkeys work behind HTTPS proxies (origin/RP ID derived from forwarded headers; PASSKEY_RP_ID/PASSKEY_ORIGIN plumbed through compose + deploy scripts)
  • Session-expired API calls return 401 JSON instead of a login-page redirect; login/setup rate limits added; setup upload written via temp file + atomic rename
  • next= redirect parameter rejects non-printable-ASCII bytes that crash undici at the Location header

Wallet RPC surface

  • Transaction decoding shows token amounts in human decimals (batch-resolved via getTokensInfo) instead of raw atoms
  • Recovery swap is a single atomic rename (no crash window leaving no wallet); tx watchers support concurrent registrations for the same tx; transport errors redacted consistently

Bridge

  • Quick-chip amounts computed in integer base units (no float overflow at 18 decimals), trimmed only where a decimal point exists (0-decimal tokens keep their real trailing zeros)
  • Stale request cards reset on new submissions; orphaned/unknown-outcome deposits shown honestly in history with explorer guidance

Tokens / trading

  • Order book ranking uses exact BigInt cross-multiplication (no double-precision ties), market orders capped at the target order's remaining amount, per-token decimal gates before code burns
  • NFT listings respect frozen state; mint/unmint validated against real token decimals client-side

Management pages / settings

  • Update/rollback watchers re-arm on failure; feature toggles mirror server invariants; explorer links degrade gracefully on non-public networks; large-send threshold validated

Infra / deploy

  • All daemon images default to multi-arch ghcr.io tags (arm64 installs no longer crash-loop on amd64-only images)
  • Whitespace install paths rejected instead of silently redirected; RPC credentials with = parsed correctly; random postgres password even when the indexer is declined; windows compose gets the scanner/web-server commands; indexer bitcoind URI split into discrete user/password vars

Verification

  • tsc --noEmit clean; 966/966 vitest tests green (79 files); astro build OK
  • cargo check + cargo test (12 tests) green for bdk-wallet
  • feature-enabler test suite: all pass; bash -n on all shell scripts
  • All 52 commits GPG-signed, conventional subjects ≤72 chars

Order confirm totals are now computed with exact decimal math
(new lib/decimal.ts) so the confirmed number is the number the
chain receives, price inputs no longer carry thousands separators,
and issuance metadata is matched by token id instead of list
position. Also hardens the explorer token route body read, the
search/import races in TokenSearch and the NFT listing error paths.
stake-trade and the rpc proxy now complete daemon param shapes
(options/output_address) before the TOTP gate so conclude and
decommission stop failing after burning a code, zero-amount order
legs are rejected up front, transport errors are redacted from
send and the proxy, an empty timeout env no longer disables rpc
timeouts, the block stream releases its upstream socket on
non-abort cancels, a broken scan reports failure instead of an
empty wallet, lookahead size is clamped and unknown networks stop
borrowing the mainnet chain tip.
- auto-sync the wallet after creation, boot and link so balances are
  never stale at zero until a manual sync
- expose syncing state and the last sync error on /status, with
  visible chips in the UI (pruned-refused scans surface loudly)
- actually send the displayed fee estimate with each transaction
  instead of falling back to the 1 sat/vB default
- mark spent outputs right after broadcast so a second send cannot
  reuse them; kick a follow-up sync from the UI
- remove the wallet files when a fresh wallet fails to open so a
  generated mnemonic is not lost behind a permanent 409
- ignore estimatesmartfee -1 answers (fresh node has no data)
- validate the configured network name and fix the restore-dialog
  wording
- read token decimals from the chain for balances (USDC/USDT were
  shown 10^12x too small and Max built a reverting amount)
- a stale tracked-bridge poll can no longer flip the phase while a
  new submission is talking to the wallet
- validate the e2m receiver payload before the on-chain deposit
- give up on a dead tracked request after repeated poll failures
- label the Mintlayer explorer link by direction (deposit vs payout)
- reset the picker icon fallback when the token changes
- release unread ipfs gateway bodies and time out pinning uploads
- failed upgrades and rollbacks now render their error instead of
  reloading over it, and the last failure is shown server-side
- validate the large-send threshold before storing it
- require a fresh 2FA code to remove a passkey, same as enrolling
- stop rendering ipfs provider secrets into the page; keys are
  write-only with a last-four hint, and the page is no-store
- probe the key-lock state without revealing seed material and only
  for an open wallet
- validate the lookahead size and refuse locking while staking
- report a failed request write as a 503 instead of a bare 500
- Signet addresses now use the tb human-readable part (BIP-0326).
- P2WSH payloads pass validation instead of falling into the typo
  corrector, which could rewrite a valid address.
- depositToBridge verifies the wallet is still on the expected chain
  right before signing; USDT-style approvals reset to zero first;
  missing-chain errors are retried via wallet_addEthereumChain.
- Plugin installs use unique temp dirs, clear stale targets and import
  entries through properly encoded file URLs.
- Browser RPC proxy drops transaction_abandon (now behind 2FA at
  /api/transaction-abandon) and no longer hides transport failures.
- Mempool capability probe negotiates JSON, keeping detection honest.
- CSP stays report-only until inline scripts carry nonces.
- Upgrade aborts before touching .env when any image pull fails, so a
  transient registry error can no longer wedge the stack on retry.
- The failed-pull test now diffs the whole env file; the old grep passed
  vacuously off its own anchor line.
- Installer-seeded prefs values are escaped for SQL in all three
  installers; windows.ps1 also aborts when seeding, pulling or starting
  fails instead of reporting success.
- Makefile derives the compose network name from the checkout directory;
  helper targets fall back to .env.dev; nuke is project-scoped again.
- The enabler keeps COMPOSE_PROFILES in sync with toggles, claims a
  request before reading it and refuses empty env rewrites.
- Setup hardening: REST API port validated, session secret survives a
  missing openssl, domain prompts reject whitespace, prefs seeding
  window documented.
- btc-explorer image drops to the node user; .env.example documents
  PROJECT_DIR_HOST and the v1.4.1 daemon source.
- Bridge deposits read token decimals as numbers again (ethers v6
  returns bigint, so every honest answer failed the range check and
  USDC/USDT amounts were built 10^12x too large).
- Explorer links route by hash shape: the payout link lands on
  Etherscan for ML->ETH bridges, the deposit link shows for Mintlayer-
  side deposits, and labels no longer follow the live form toggle.
- A failed e2m broadcast after the Ethereum deposit now records a
  provisional history entry instead of orphaning the funds, and the
  status card says so when live tracking gives up.
- Pool creation converts the margin percent to per-mille (the old
  division produced commissions 1000x too small) and order forms use
  exact-decimal validation so scientific notation fails before the
  2FA code is burned.
- Rapid favourite toggles build on a ref mirror instead of a stale
  render snapshot; NFT listings with unresolvable metadata stay
  visible; stored token lists drop junk entries at load.
- Installer-seeded prefs are stored as JSON strings again: the previous
  seed wrote raw values while the app JSON-parses every pref, which
  broke first login. Values are escaped for JSON (backslash, quotes)
  and SQL (single quotes) and the seeding was verified against sqlite.
- pending-transactions and list-utxos use the derived compose network
  name instead of a hardcoded one.
- bitcoind falls back to a valid -chain value (main) when
  BITCOIN_CORE_CHAIN is unset; the example env documents the variable
  and corrects the pruning note.
- The rpc proxy now forwards the daemon's application errors again:
  the wallet daemon codes them -1, and the previous JSON-RPC-only
  window turned every 'wallet closed'/'not enough funds' toast into
  'service unavailable'. Transport and HTTP-status codes stay
  redacted.
- Freezing an order moves on-chain (fees, broadcast), so it goes
  through the TOTP-gated stake-trade endpoint like every other
  transaction action instead of the session-cookie allowlist.
- A failed wallet token scan now shows an error state with retry
  instead of rendering as a clean empty token list.
- Daemon HTTP 4xx messages no longer leak to the browser on the send,
  staking and token-manage endpoints; block-stream errors drop the
  daemon host:port and scan-issued-tokens rejects unknown networks
  instead of encoding ids with the wrong HRP; token-authority keeps
  per-address results when one lookup fails.
- order_conclude validates that output_address is absent, matching
  its siblings, so crafted junk fails before a 2FA code is burned.
- pf_add now seeds COMPOSE_PROFILES when the key is missing or empty:
  an install with no optionals (or a disable that removed the last
  profile) used to no-op the next enable, leaving the app claiming a
  service that no later host-side 'up' would start.
- The first indexer enable generates a POSTGRES_PASSWORD when the
  installer never made one; an empty password crash-loops postgres.
- The no-openssl rand_pass fallback reads a bounded urandom chunk:
  the old unbounded pipeline SIGPIPEd installers under pipefail.
- Deploy flavors trust their TLS-terminating caddy (TRUST_PROXY) so
  HTTPS installs stop 403-ing every form POST, fall back to a valid
  bitcoind -chain, point btc-explorer/bdk-wallet defaults at the
  registry CI actually publishes, and warn instead of aborting when
  the image pull fails after secrets were seeded.
- windows.ps1 no longer checks a stale exit status before the sqlite
  seeding runs; the packaged compose carries a drift warning; the
  agent prompt expects the real 302 redirect; the example env stops
  advertising signet.
- The staged TOTP secret (QR + manual entry) rendered to every /login
  visitor while first-run setup was pending; it is the future second
  factor, so a network peer reading it during the staging window holds
  it forever. The enrollment form now renders only for the browser
  holding the auth_boot cookie; other visitors get a neutral notice.
- 'Start over' is a POST gated on the same cookie instead of an
  unauthenticated GET (?restart=1) that let anyone wipe in-progress
  setup.
- Malformed multipart bodies no longer 500 the public login POST:
  both branches parse through readFormData.
- Wallet unlock guesses are throttled per client IP (5 per 15 min,
  wrong-password failures only): the unlock password guards sends and
  RPC throughput alone was no rate limit. Same shared map as the
  password-change throttle, under its own key namespace.
- Crafted multipart posts could crash the IPFS/threshold handlers or
  overwrite a stored pinata key with '{}': both reads now go through
  the str() coercion used by their siblings.
- A provider saved with no credential (pasted or stored) is rejected
  with an error naming the missing key instead of reporting success.
- The upgrade/rollback watcher's 12-minute timeout no longer dies
  silently: it says the apply is still running and fires the failure
  path instead of leaving a stale 'Queued' note.
- Unknown lock state renders as 'Key lock state unknown' instead of
  asserting the keys are unlocked.
A 52-symbol v0 program carries 4 padding bits that BIP-173 requires
to be zero. The taproot branch already enforced this; the v0 branch
only compared lengths, so a checksum-valid but spec-invalid address
was presented as verified and bounced by the daemon at send time.
The padding check now runs for both witness versions, with padding
probes in the test suite.
A restore or seed link rescans from the wallet's timestamp, and
bitcoind can scan in the background for a long time. During that
window the sidecar's read endpoints queued on the wallet mutex until
the browser timed out, so the page reported the node as offline, and
a timed-out sync was never retried, leaving the wallet at 0.00 until
a container restart.

- /status answers from the scan state while the wallet is locked;
  /balance and /txs fail fast with 503 so the UI keeps polling
- a sync that fails while bitcoind is still rescanning re-arms
  itself after 30s until the scan converges
- the post-send catch-up runs in the background: an inline sync
  could exceed the client timeout and make a broadcast transaction
  look failed
- the fee estimate is re-fetched right before a send when missing,
  and the form says plainly when the 1 sat/vB fallback will be used
- a failed create now removes sqlite -wal/-shm sidecars so a retry
  cannot replay stale rows, and an unknown BITCOIN_NETWORK aborts
  the start instead of falling back to mainnet
- plugin archives are now downloaded outside the extraction dir: the
  raw plugin.tgz sat next to the extracted entries, which made the
  npm-pack single-directory layout impossible to detect and leaked
  the archive into the served plugin dir on flat layouts
- plugin installs are serialized: two concurrent installs could drop
  one from the registry while its files stayed on disk
- mintlayer addresses require the bech32m checksum, so legacy-bech32
  lookalikes are no longer reported as valid
- the bridge deposit re-verifies the wallet chain right before the
  deposit call, not only before the approve minutes earlier
- a trailing slash in INDEXER_URL no longer produces //api/v2 paths
  that 404 every indexer feature
- transaction-abandon redacts transport-class daemon errors like every
  other money endpoint (the message carries the daemon url)
- the transactions page surfaces the real abandon failure (a string
  error field was read as an object, so a wrong 2fa code showed as a
  generic failure and burned retries against the step-up throttle) and
  detects session-expiry redirects instead of a json parser error
- staking pools displayed their commission 10x too high: per-mille
  ratio rendered with a percent sign
- insufficient-funds copy divided ml atoms by 1e11 instead of 1e9,
  understating the balance 100x
- a tx dropped from the mempool now fails immediately instead of
  burning the five minute watch timeout
- a request counts as pending while the sidecar holds its claim file,
  so auto-install no longer re-queues the same upgrade mid-deploy and
  the already-pending answer stays honest during deploys
- the release window is cut after the prerelease filter, so a long rc
  train cannot hide the newest final release from the update check
- the ipfs settings branch explains a missing 2FA setup instead of
  failing every code with 'Invalid authenticator code.'
- a successful seed import recomputes the wallet session state, so the
  page no longer claims the file is closed right after recovery
- starting a new bridge resets the old bridge's tracking state, so the
  poller and websocket actually follow the request that was just made
  instead of showing the previous one's completed steps
- m2e intents fail closed when the configured network flavor has no
  bridge config - falling back to another flavor paid a bridge address
  this deployment does not control
- bridge sdk requests carry a 10s timeout so a hung host cannot pile up
  pending fetches until the browser connection pool starves
- deposits whose bridge submission failed are stored under an orphan id
  and their history rows stop polling a guaranteed 404 or offering a
  dead retry; the row shows the deposit tx hash instead
- switching direction clears a stale address suggestion
- sends no longer park behind a running scan: the request fails fast
  with the same 503 the read endpoints use. Parking meant the client
  timed out, the user was told the send may or may not have happened,
  and the parked task still broadcast it - with a retry queued behind
  the same lock that was the shortest path to paying twice. The send
  form also pauses itself while a scan runs.
- the pruned-node guard compared a unix timestamp against a block
  height, which can never be true: restores aimed inside the pruned
  range were silently allowed and would miss coins. The prune window
  is now converted to time via getblockstats (with a conservative
  fallback), guarded by unit tests with realistic magnitudes.
- the rescan probe asks the sidecar's wallet endpoint, not the bare
  one, so the auto-retry still converges when bitcoind serves more
  than one wallet
- receive-address endpoints fail fast under contention instead of
  stalling every overview fetch for its full timeout
- the overview polls through a scan so balance, history and address
  fill in as progress lands instead of staying empty until a manual
  refresh
- restore accepts every valid BIP39 length (12/15/18/21/24 words)
- the one-time seed card only lets Continue through after the phrase
  was verified - the mnemonic is never shown again
- own nft listings render even when their metadata cannot resolve, so
  the cancel affordance survives rpc glitches instead of hiding the
  order entirely
- the order book ranks asks and bids by exact atom arithmetic instead
  of float division, so a market buy fills the true best ask when two
  prices agree to double precision
- switching pairs clears a row-click prefill, which used to leave the
  old pair's price in the form and place a nonsense order
- a token that resolves live clears its stale tx-failed badge
- mint and unmint validate the amount against the token's own decimals
  before the 2fa code is burned, not after
- nft issuance stores the full sha-256 hex (64 chars); the old slice
  kept half the digest so no verifier could match the file
- the marketplace no longer renders whole units of fungible tokens as
  nft cards; only tokens with no resolvable info keep the
  unknown-collection fallback
- passkeys were silently broken on every https deployment: the
  webauthn origin was read from the raw socket url (http behind the
  shipped tls gateway) and the PASSKEY_* env vars init.sh writes were
  never passed through docker compose. the origin now honors
  X-Forwarded-Proto/Host under TRUST_PROXY (same rules as the csrf
  check) and the compose and linux deploy paths carry the vars.
- a crafted ?next= with control characters crashed the login post
  after session minting: the redirect target is now filtered like
  every other unsafe value
- the public setup, login and passkey endpoints buffered the whole
  request body before any validation; bodies are now capped before
  parsing (1 MiB forms, 64 KiB passkey json, 55 MiB wallet upload)
- an expired session on an api route answered 302 -> login html,
  which fetch follows silently and reports as 'HTTP 200 wallet
  error'; api routes now get a 401 session_expired signal
- the setup form parse became an unstyled 500 on a malformed
  multipart body; it now renders the inline error like login does
- rollback anchors recorded the raw .env value, so installs without
  image pins (and bitcoin core, which never had a pin) wrote empty
  anchors: upgrading left no way back while the stack already ran the
  new tags. Anchors now carry the resolved reference including the
  compose default, and a stale core anchor is dropped instead of
  clobbering a user's newer pin on rollback
- the tls gateway container stayed Up when caddy died (the entrypoint
  loop was pid 1): it now watches the child and exits so the restart
  policy acts
- the deploy flavors wrote an empty core chain, so a testnet install
  that enabled bitcoin later ran a mainnet bitcoind against a testnet
  wallet; the chain flag is derived from the network like the
  interactive installer does
- enabling bitcoin from settings pre-creates and chowns the bitcoin
  data bind mounts (docker would auto-create them root-owned and both
  sidecars crash-loop on them; the enabler's project mount is
  read-only so the dirs are made through a throwaway container)
- result files can no longer contain raw CR (unparseable json),
  oversized request files are rejected before reading, and a hostile
  pruned value is rejected instead of silently defaulting to the
  chain-deleting pruned mode
- make down/restart/nuke cover the tls and watchtower profiles so
  teardown cannot strand a running caddy from its network
- windows seeding escapes backslash and double quotes before the sql
  literal, matching the linux installer; prefs seeding chowns to the
  clamped container uid, not the invoking shell
- a failed web-gui upgrade or rollback left the update buttons
  disabled with no hint: the watch callbacks only acted on success,
  so the initiating toggle is now re-armed (the error note stays -
  reloading retries)
- importing a seed refreshed the wallet session state but kept the
  pre-import staking snapshot, so a wallet imported while staking
  showed a ghost 'cannot lock while staking' on the fresh wallet;
  staking status is re-probed with the wallet
- the key-lock form asked for a password it never checked (the
  daemon lock rpc takes none) - removed the field and reworded the
  copy so locking does not imply a verification that never happens
- seed import cleanup kept glued list numbers ('3charlie'), failing
  its own documented example - the separator is now optional
- first-time setup was completely broken: the body-cap refactor
  called a helper it never imported, and both gates miss undeclared
  identifiers in .astro frontmatter, so every POST /setup rendered a
  500 on a fresh install
- the pre-bootstrap endpoints ran expensive key derivation with no
  working limit (login step 1 has no password to fail, so the login
  limiter never tripped, and /setup had none at all): staged setup
  attempts now count against a shared per-IP window
- the wallet upload wrote straight onto the path the daemon opens,
  so a racing request could have the open run against half-written
  bytes - the file now lands on a temp name and is renamed into
  place
- the login redirect guard only rejected control characters, but the
  header layer refuses every code point above latin1 - a crafted
  ?next= with U+2028 still crashed a successful login after the
  session was minted; the guard is printable-ASCII now, which covers
  the whole rejected set
- plugin uninstall skipped the serialization installs use, so
  racing an install with an uninstall could silently drop the new
  install from the registry or resurrect the removed one; both
  operations now share the same queue
- the pruned-mode guard evaluated the wallet's creation horizon
  forever, while the actual scan advances to the last sync time -
  a healthy wallet aged out of the prune window (~4 days on the
  documented config) and every sync was refused from then on. The
  guard now evaluates the same origin bdk scans from, so kept-in-sync
  wallets pass forever while one left offline past the window is
  still refused
- a wallet file recorded on one network silently re-derived itself
  on another (84'/1' vs 84'/0') when the env flipped, showing a
  permanent 0.00 over the same cache; boot now refuses the mismatch
  and names the recovery
- dust amounts surfaced as 'internal error (see sidecar logs)';
  they are a user-fixable 400 now
@erubboli
erubboli merged commit 4ad6bea into main Nov 3, 2026
8 checks passed
@erubboli
erubboli deleted the feat/ocr-sweep-2 branch November 3, 2026 11:28
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