Commit 3f508c3
fix(utxo-lib): serialize Zcash Sapling valueBalance as signed int64
Zcash's Sapling valueBalance is a signed 64-bit field — it is negative
whenever value flows from the transparent pool into the shielded pool
(t->z shielding). The previous code in fromBufferV4 threw
UnsupportedTransactionError for any non-zero valueBalance, preventing
deposit-detection pipelines from computing txids for shielding
transactions even when the shielded bundle vectors are empty.
In toBufferV4 and hashForSignatureByNetwork the field was always written
as eight zero bytes (VALUE_INT64_ZERO), so even if parsing had succeeded
the re-serialized transaction would have had the wrong bytes and produced
a wrong txid.
Changes:
- ZcashTransaction gains a `saplingValueBalance: Buffer` field,
initialised to VALUE_INT64_ZERO and preserved through clone().
- fromBufferV4 stores the raw 8-byte slice in saplingValueBalance instead
of throwing when the field is non-zero. Non-empty shielded bundles still
throw UnsupportedTransactionError via readEmptySaplingBundle, keeping
the existing restriction against fully-shielded transactions.
- toBufferV4 writes tx.saplingValueBalance back verbatim, enabling exact
round-tripping of fromBuffer→toBuffer/getId for any Sapling tx whose
shielded bundle vectors are empty.
- hashForSignatureByNetwork uses tx.saplingValueBalance so sighash
computation is also correct.
- Add test/bitgo/zcash/ZcashTransaction.ts with round-trip tests for a
minimal Sapling v4 tx with valueBalance = -5.
Security: WCN-1961 / FND-002 (funds-loss, medium severity). A
custody pipeline calling fromBuffer(shieldingTx).getId() would
previously crash or silently produce a wrong txid; with this fix it
correctly round-trips for the case of empty shielded bundles, and
throws UnsupportedTransactionError for populated shielded bundles.
Ticket: WCN-1961
Session-Id: e7382333-471f-41ac-9109-8dbfc6acb8ea
Task-Id: ffe9c655-62ea-463d-a151-7d634b267c811 parent 8e1f0fc commit 3f508c3
3 files changed
Lines changed: 54 additions & 7 deletions
File tree
- modules/utxo-lib
- src/bitgo/zcash
- test/bitgo/zcash
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
99 | 98 | | |
100 | 99 | | |
101 | 100 | | |
| |||
167 | 166 | | |
168 | 167 | | |
169 | 168 | | |
170 | | - | |
| 169 | + | |
171 | 170 | | |
172 | 171 | | |
173 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
117 | 121 | | |
118 | 122 | | |
119 | 123 | | |
| |||
123 | 127 | | |
124 | 128 | | |
125 | 129 | | |
| 130 | + | |
126 | 131 | | |
127 | 132 | | |
128 | 133 | | |
| |||
378 | 383 | | |
379 | 384 | | |
380 | 385 | | |
381 | | - | |
| 386 | + | |
382 | 387 | | |
383 | 388 | | |
384 | 389 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
0 commit comments