Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

implement btc/bch/zcash signing in rust#1143

Open
0xh3rman wants to merge 1 commit into
mainfrom
bitcoin-signer
Open

implement btc/bch/zcash signing in rust#1143
0xh3rman wants to merge 1 commit into
mainfrom
bitcoin-signer

Conversation

@0xh3rman
Copy link
Copy Markdown
Collaborator

@0xh3rman 0xh3rman commented May 18, 2026

Bitcoin Signer Test Matrix

Scope: core branch bitcoin-signer — migration of Bitcoin/BCH/Litecoin/Doge/Zcash signing from Trust Wallet Core to crates/gem_bitcoin::signer.

Goal: prove on real networks that signatures verify, fees are sensible, and change/dust handling never loses funds. Unit tests in gem_bitcoin cover preimage shape and byte-exact vectors; this matrix covers what only mainnet/testnet can confirm.

Transfer Matrix

ID Coverage Builder / branch Example Status
T1 Native segwit P2WPKH transfer with change sign_bitcoin_like + UtxoPlanner::Exact BTC bc1q → bc1q Tested: BTC bc1qe7q… → bc1qw0e… (9f71a30b…) 2 in → 2 out (payment + change), 208 vB, fee 418 sat (~2 sat/vB)
T2 Max-send (sweep) leaving no change UtxoPlanner::Max BTC/LTC max-send Tested: Doge (b99c4551…) 1-in, LTC (009a0abc…) 1-in, BTC (5072b15a…) 3-in. All 1 output, no change
T3 Sub-dust change absorbed into fee try_build_plan no-change branch (spend.rs:144-152) LTC send chosen so leftover < 546 sat
T4 Transfer with memo (OP_RETURN at output index 1) op_return_output + spend_outputs Covered indirectly by W1
T5 Legacy P2PKH transfer sign_bitcoin_like legacy path Doge D… → D… Tested: Doge max-send (b99c4551…) D8g1MD… → DL8fYJ…, 191 vB, fee 0.0193 DOGE
T6 Bitcoin Cash P2PKH with FORKID sighash bitcoin_cash::sign_plan (BIP143 + 0x41) BCH bitcoincash:q… → bitcoincash:q… Tested + confirmed at block 952,079: BCH max swap to SOL via NEAR Intents (7360dbab…) 192 B, fee 1,920 sat (~10 sat/B)
T7 Zcash t1 → t1 transparent transfer zcash::sign_transparent ZIP-244 v5 Zcash t1… → t1… Tested: t1RNsP3w… → t1dTLYue… + change (09cc92df…) v5, 240 B, fee 10,000 zat (ZIP-317 min, 2 actions). Mempool-accepted → sighash verifies at consensus level
T8 Zcash max-send Zcash branch in UtxoPlanner::Max + ZIP-317 fee Zcash sweep Tested + block-confirmed: (e5d68d6b…) block 3,351,057, v5, 2 in → 1 out, no change, 355 B, fee 10,000 zat (ZIP-317 floor)

Swap Matrix

ID Coverage Builder / branch Example Status
W1 Swap via Transfer path (memo OP_RETURN), exact amount SpendRequest::swap Transfer BTC → ETH via Thorchain Blocked on Thorchain resumption; unit test test_sign_swap_memo_op_return covers the path
W2 Swap via Transfer path, max amount (memo optional) Transfer + use_max_amount BCH → SOL via NEAR Intents max Tested: BCH → SOL via NEAR Intents (7360dbab… confirmed at block 952,079 + intent 1JSnFERGiXnamsvNCPNQapoFpa1sU61S5N — NEAR indexer pending SOL credit
W3 Swap via Contract path (hex-decoded nulldata), exact amount SpendRequest::swap Contract (request.rs:42-58) BTC → SOL via Chainflip
W4 Swap via Contract path, max-intent (must still emit change as refund) Contract + exact-amount with change BTC → SOL via Chainflip max FAILED then fixed: (5519a6b5…) confirmed on Bitcoin but rejected by Chainflip CFE — only 2 outputs (deposit + OP_RETURN), missing mandatory 3rd output that Chainflip uses as refund address. Fix: force is_max=false for Contract data type in request.rs; tests updated to require 3-output structure. Pending re-test

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements signing support for Bitcoin, Bitcoin Cash, Litecoin, Dogecoin, and Zcash, introducing a new BitcoinChainSigner and a transaction planner with fee estimation. The review feedback identifies critical performance improvements, such as precomputing sighash components to prevent O(N^2) complexity and optimizing the use of cryptographic contexts. Additionally, the reviewer recommends implementing dust threshold checks for transaction amounts and utilizing standard library abstractions for address parsing to enhance code reliability and maintainability.

Comment thread crates/gem_bitcoin/src/signer/transaction.rs Outdated
Comment thread crates/gem_bitcoin/src/signer/bitcoin_cash.rs Outdated
Comment thread crates/gem_bitcoin/src/signer/zcash.rs Outdated
Comment thread crates/gem_bitcoin/src/signer/planner/spend.rs Outdated
Comment thread crates/gem_bitcoin/src/signer/planner/spend.rs
Comment thread crates/gem_bitcoin/src/signer/address/bitcoin.rs
Comment thread crates/gem_bitcoin/src/signer/transaction.rs Outdated
@0xh3rman 0xh3rman force-pushed the bitcoin-signer branch 4 times, most recently from ddf7c26 to a5ebee4 Compare May 22, 2026 00:22
@0xh3rman 0xh3rman marked this pull request as ready for review May 22, 2026 12:48
@0xh3rman 0xh3rman requested a review from gemcoder21 May 23, 2026 08:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant