Skip to content

Commit 216825c

Browse files
feat(utxo-lib): add ZEC NU6.2 consensus branch id
Zcash NU6.2 activated on mainnet at block 3364600, introducing a new consensus branch id 0x5437f330 (re-enabling Orchard with a corrected circuit after the GHSA-ghc3-g8w4-whf9 emergency soft fork). The builder previously defaulted to NU6.1 (0x4dec4df0), so transactions built for heights >= 3364600 carried a stale branch id and were rejected by upgraded nodes. Add VERSION4/5_BRANCH_NU6_2 markers (457/552) and the 0x5437f330 branch id, wire it through getDefaultConsensusBranchIdForVersion, getDefaultVersionGroupIdForVersion, setPsbtDefaults, and both setDefaultsForVersion switches. Bump the mainnet default build version to NU6.2; testnet stays on NU6.1 because its NU6.2 activation (block 4052000) has not been reached. Regenerate the zcash PSBT signing fixtures: the consensus branch id feeds the transaction sighash, so the serialized PSBTs and signatures change with the new default. Refs: T1-3519
1 parent 3ca5247 commit 216825c

11 files changed

Lines changed: 104 additions & 43 deletions

modules/utxo-lib/src/bitgo/transaction.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ export function createPsbtFromTransaction(tx: UtxoTransaction<bigint>, prevOuts:
154154
}
155155

156156
export function getDefaultTransactionVersion(network: Network): number {
157-
// Use NU6_1 version for both mainnet and testnet
158-
// https://zips.z.cash/zip-0255
157+
// Mainnet activated NU6.2 at block 3364600; testnet has not (activation 4052000),
158+
// so testnet still builds NU6.1 transactions.
159159
if (network === networks.zcashTest) {
160160
return ZcashTransaction.VERSION4_BRANCH_NU6_1;
161161
}
@@ -167,7 +167,7 @@ export function getDefaultTransactionVersion(network: Network): number {
167167
case networks.ecash:
168168
return 2;
169169
case networks.zcash:
170-
return ZcashTransaction.VERSION4_BRANCH_NU6_1;
170+
return ZcashTransaction.VERSION4_BRANCH_NU6_2;
171171
default:
172172
return 1;
173173
}
@@ -219,9 +219,11 @@ export function setPsbtDefaults(
219219
ZcashTransaction.VERSION4_BRANCH_NU5,
220220
ZcashTransaction.VERSION4_BRANCH_NU6,
221221
ZcashTransaction.VERSION4_BRANCH_NU6_1,
222+
ZcashTransaction.VERSION4_BRANCH_NU6_2,
222223
ZcashTransaction.VERSION5_BRANCH_NU5,
223224
ZcashTransaction.VERSION5_BRANCH_NU6,
224225
ZcashTransaction.VERSION5_BRANCH_NU6_1,
226+
ZcashTransaction.VERSION5_BRANCH_NU6_2,
225227
].includes(version)
226228
) {
227229
throw new Error(`invalid version`);

modules/utxo-lib/src/bitgo/zcash/ZcashPsbt.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ export class ZcashPsbt extends UtxoPsbt<ZcashTransaction<bigint>> {
122122
case ZcashTransaction.VERSION4_BRANCH_NU5:
123123
case ZcashTransaction.VERSION4_BRANCH_NU6:
124124
case ZcashTransaction.VERSION4_BRANCH_NU6_1:
125+
case ZcashTransaction.VERSION4_BRANCH_NU6_2:
125126
this.setVersion(4);
126127
break;
127128
case 5:
128129
case ZcashTransaction.VERSION5_BRANCH_NU5:
129130
case ZcashTransaction.VERSION5_BRANCH_NU6:
130131
case ZcashTransaction.VERSION5_BRANCH_NU6_1:
132+
case ZcashTransaction.VERSION5_BRANCH_NU6_2:
131133
this.setVersion(5);
132134
break;
133135
default:

modules/utxo-lib/src/bitgo/zcash/ZcashTransaction.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const CANOPY_BRANCH_ID = 0xe9ff75a6;
2525
const NU5_BRANCH_ID = 0xc2d6d0b4;
2626
const NU6_BRANCH_ID = 0xc8e71055;
2727
const NU6_1_BRANCH_ID = 0x4dec4df0; // https://zips.z.cash/zip-0255
28+
// NU6.2 emergency hard fork re-enabling Orchard with a corrected circuit (mainnet block 3364600).
29+
const NU6_2_BRANCH_ID = 0x5437f330;
2830

2931
export class UnsupportedTransactionError extends Error {
3032
constructor(message: string) {
@@ -38,18 +40,20 @@ export function getDefaultVersionGroupIdForVersion(version: number): number {
3840
case 450:
3941
case 455:
4042
case 456:
43+
case 457:
4144
return SAPLING_VERSION_GROUP_ID;
4245
case 500:
4346
case 550:
4447
case 551:
48+
case 552:
4549
return ZIP225_VERSION_GROUP_ID;
4650
}
4751
throw new Error(`no value for version ${version}`);
4852
}
4953

5054
export function getDefaultConsensusBranchIdForVersion(network: ZcashNetwork, version: number): number {
51-
// Use NU6.1 version for testnet, activated on mainnet in block 2726400
52-
// https://zips.z.cash/zip-0255
55+
// Testnet has not yet activated NU6.2 (testnet activation block 4052000), so keep
56+
// defaulting to NU6.1 there. Mainnet activated NU6.2 at block 3364600.
5357
if (network === networks.zcashTest) {
5458
if (version === 4 || version === 5) {
5559
return NU6_1_BRANCH_ID;
@@ -74,12 +78,16 @@ export function getDefaultConsensusBranchIdForVersion(network: ZcashNetwork, ver
7478
case ZcashTransaction.VERSION5_BRANCH_NU6:
7579
// https://zips.z.cash/zip-0253
7680
return NU6_BRANCH_ID;
77-
case 4:
78-
case 5:
7981
case ZcashTransaction.VERSION4_BRANCH_NU6_1:
8082
case ZcashTransaction.VERSION5_BRANCH_NU6_1:
8183
// https://zips.z.cash/zip-0255
8284
return NU6_1_BRANCH_ID;
85+
case 4:
86+
case 5:
87+
case ZcashTransaction.VERSION4_BRANCH_NU6_2:
88+
case ZcashTransaction.VERSION5_BRANCH_NU6_2:
89+
// NU6.2 — emergency hard fork re-enabling Orchard, mainnet block 3364600
90+
return NU6_2_BRANCH_ID;
8391
}
8492
throw new Error(`no value for version ${version}`);
8593
}
@@ -93,9 +101,11 @@ export class ZcashTransaction<TNumber extends number | bigint = number> extends
93101
static VERSION4_BRANCH_NU5 = 450;
94102
static VERSION4_BRANCH_NU6 = 455;
95103
static VERSION4_BRANCH_NU6_1 = 456;
104+
static VERSION4_BRANCH_NU6_2 = 457;
96105
static VERSION5_BRANCH_NU5 = 500;
97106
static VERSION5_BRANCH_NU6 = 550;
98107
static VERSION5_BRANCH_NU6_1 = 551;
108+
static VERSION5_BRANCH_NU6_2 = 552;
99109

100110
// 1 if the transaction is post overwinter upgrade, 0 otherwise
101111
overwintered = 0;

modules/utxo-lib/src/bitgo/zcash/ZcashTransactionBuilder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ export class ZcashTransactionBuilder<TNumber extends number | bigint = number> e
7474
case ZcashTransaction.VERSION4_BRANCH_NU5:
7575
case ZcashTransaction.VERSION4_BRANCH_NU6:
7676
case ZcashTransaction.VERSION4_BRANCH_NU6_1:
77+
case ZcashTransaction.VERSION4_BRANCH_NU6_2:
7778
this.setVersion(4);
7879
break;
7980
case 5:
8081
case ZcashTransaction.VERSION5_BRANCH_NU5:
8182
case ZcashTransaction.VERSION5_BRANCH_NU6:
8283
case ZcashTransaction.VERSION5_BRANCH_NU6_1:
84+
case ZcashTransaction.VERSION5_BRANCH_NU6_2:
8385
this.setVersion(5);
8486
break;
8587
default:

0 commit comments

Comments
 (0)