Skip to content

fix: close High/Medium findings from both deep-review reports (batch 2) - #10

Merged
colneech-dev merged 1 commit into
mainfrom
fix/review-findings-batch-2
Nov 24, 2026
Merged

colneech-dev merged 1 commit into
mainfrom
fix/review-findings-batch-2

Conversation

@colneech-dev

Copy link
Copy Markdown
Owner

Summary

Follow-up to #8 (perf) and #9 (Critical share-dedup bypass). Closes the remaining High/Medium findings from both independent deep-review reports run against this repo (review-miningcore-positive.md, review-miningcore-negative.md):

  • NUL-byte share poisoning (High) — sanitize Worker/UserAgent once in ShareRecorder.cs before any persistence. Previously a single NUL byte could fail an entire shares+blocks batch across every pool and trip the circuit breaker.
  • Admin API whitelist case bypass (High) — case-insensitive path match.
  • P2SH pool address (High) — startup now fails loudly instead of silently producing unspendable coinbase outputs.
  • BIP22 inconclusive/duplicate misclassified as rejection (High) — no longer treated as a hard submission failure.
  • Duplicate blocks rows double-crediting a reward (Medium) — unique partial index + ON CONFLICT DO NOTHING (with a migration script).
  • Reward-recipient percentages >100% (Low-medium) — config validation.
  • Miner-settings endpoint trusts a client-supplied IP (Medium) — now uses the real connection IP; also clamps the threshold's upper bound.
  • Two processes paying out concurrently (Medium) — per-pool Postgres advisory lock in PayoutManager.
  • Legacy-wallet -4 "commit failed" treated as nothing-sent (Medium) — now outcome-unknown, matching how these wallets actually behave.
  • networkdifficulty = 0 aborts a pool's whole payout pass (Medium) — guarded in PPLNS/PPLNSBF.
  • Equihash z_sendmany/sendcurrency wait loop can spin forever, halting every pool (Medium) — bounded to 10 minutes.
  • AuxPoW FindNonce infinite loop on a chain-id collision (Medium, latent) — bounded, throws instead of hanging job updates.
  • Wallet passphrase written to Trace logs (Medium) — redacted.
  • Several Low-severity fixes: NoticeThrottle reset every payout cycle, unsynchronized auxDiff1 dictionary, banManager NRE when pool-level banning is off, publish-before-respond reorder (block candidate could be lost on a backed-up send queue).

Not included (larger, separately scoped): non-Bitcoin payout-handler idempotency (Kaspa et al.), the shutdown-buffer-flush gap in ShareRecorder, permanent orphan reclassification.

Test plan

  • Builds clean (dotnet build, 0 errors, pre-existing warnings only)
  • Run the add_block_dedup_index.sql migration against the production DB before/at deploy
  • Watch logs after deploy for any unexpected admin-whitelist or pool-startup (P2SH guard) rejections on existing configs
  • Confirm existing miner-settings API callers still succeed now that IP comes from the connection, not the body

🤖 Generated with Claude Code

Addresses the remaining High/Medium findings from review-miningcore-positive.md
and review-miningcore-negative.md, after the Critical share-dedup bypass (#9)
and the PoolEffort perf fix (#8):

- ShareRecorder.cs: sanitize Worker/UserAgent (strip control chars incl. NUL,
  cap length) once at the single choke point before any persistence. A NUL
  byte previously made Postgres reject an entire shares+blocks batch -
  spanning every pool, not just the attacker's - tripping the circuit
  breaker and losing block candidates to the recovery file. [F2/H1]

- IPAccessWhitelistMiddleware.cs: whitelist prefix match is now
  case-insensitive. ASP.NET Core routing is case-insensitive, so
  "/API/admin/..." reached AdminApiController without matching the
  case-sensitive "/api/admin" prefix check. [H2]

- BitcoinJobManagerBase.cs: pool startup now fails if the daemon reports the
  pool address as a script (P2SH) address, instead of silently falling back
  to a P2PKH decode of the script hash - an unspendable coinbase output.
  Also stops treating BIP22 "duplicate"/"duplicate-inconclusive"/
  "inconclusive" submitblock responses as hard rejections; they mean the
  block is already known or valid-but-not-yet-connected, not rejected, so a
  block that later confirms no longer risks never getting a DB row. [F3b/F4]

- BlockRepository.cs + createdb.sql + add_block_dedup_index.sql: unique
  partial index on (poolid, blockheight, hash) with ON CONFLICT DO NOTHING,
  so a retried commit or a replayed recovery file can no longer insert - and
  credit - the same block twice. [F5]

- ClusterConfigValidation.cs: reject pool configs whose RewardRecipients
  percentages sum above 100, which otherwise overpays recipients straight
  out of the wallet's float. [F11]

- PoolApiController.cs: the miner-settings "proof of ownership" check now
  uses the caller's real connection IP instead of one supplied in the
  request body, and clamps the payment threshold's upper bound. [M5/F9]

- PayoutManager.cs: per-pool Postgres advisory lock (held on one connection
  for the whole payout pass) so a second process against the same database
  skips a pool instead of paying it out alongside the first. [F10]

- BitcoinPayoutHandler.cs: the insufficient-funds notice throttle is now
  keyed per-pool in a static dictionary instead of an instance field, which
  reset every cycle because handlers are resolved fresh per payout run. [L1]

- BitcoinJobManager.cs: auxDiff1 is now a ConcurrentDictionary; it was
  written from up to 8 concurrent aux-submit tasks. [L2]

- BitcoinPool.cs: guard banManager.Ban() against pool-level banning being
  disabled (banManager null) while the cluster-level BanOnLoginFailure
  default still says to ban - previously an NRE. Also moved the share
  publish before the stratum response, since RespondAsync can throw on a
  backed-up send queue; previously that could happen after the daemon
  accepted a block but before it was ever published.  [L4/F3a]

- PayoutErrorClassifier.cs: treat RPC -4 "Transaction commit failed" as
  outcome-unknown. 0.10-0.13-derived wallets (several supported legacy
  daemons) record the transaction in the wallet before broadcasting, so this
  error does not mean nothing was sent. [F6]

- PPLNSPaymentScheme.cs / PPLNSBFPaymentScheme.cs: skip shares with
  NetworkDifficulty <= 0 instead of dividing by it, which throws
  OverflowException and aborts every other block queued in the same
  UpdatePoolBalancesAsync pass. [M1]

- EquihashPayoutHandler.cs: bound the z_sendmany/sendcurrency operation-wait
  loops to 10 minutes. z_getoperationresult can return an empty array
  forever once the daemon has already handed out and forgotten a result,
  and PayoutManager processes pools sequentially, so this previously halted
  every other pool too. [M2]

- AuxPowSerializer.cs: bound FindNonce's treeSize doubling and throw instead
  of spinning forever when chains collide at every tree size (equal
  daemon-reported chainids, or two SlotByNonce chains) - this runs inside
  BuildCoinbase, in UpdateJob's pipeline, so an infinite loop here freezes
  job updates for the whole parent pool. [F7]

- RpcClient.cs: redact walletpassphrase RPC calls from Trace-level logging.
  The log level can be raised to Trace at runtime via the admin API, which
  would otherwise write the wallet passphrase to disk. [M4]

Not included in this batch (larger, separately scoped): non-Bitcoin payout
handler idempotency (Kaspa et al., H3), the shutdown-buffer-flush gap in
ShareRecorder (F3c), and permanent orphan reclassification (F3d/M3).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@colneech-dev
colneech-dev merged commit 3906a89 into main Nov 24, 2026
1 check passed
@colneech-dev
colneech-dev deleted the fix/review-findings-batch-2 branch November 24, 2026 08:59
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