Skip to content

Commit 718e2d1

Browse files
zmanianclaude
andcommitted
Fix darkside v5 txid computation and tree state nil dereference
darksideSetTxID applied SHA256d to all transactions including v5, producing incorrect txids. Now that ParseFromSlice computes v5 txids via ZIP 244, skip the SHA256d override for v5 transactions. (fixes #456) DarksideRemoveTreeState crashed with a nil pointer dereference when removing a tree state at a non-existent height or hash. Add nil checks to return an error instead of panicking. (fixes #466) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b71b2c0 commit 718e2d1

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎common/darkside.go‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ type darksideProtocolSubtreeRoots struct {
112112
var DarksideEnabled bool
113113

114114
func darksideSetTxID(tx *parser.Transaction) {
115-
// SHA256d
116-
// This is correct for V4 transactions, but not for V5, but in this test
117-
// environment, it's harmless (the incorrect txid calculation can't be
118-
// detected). This will be fixed when lightwalletd calculates txids correctly .
115+
if tx.IsV5() {
116+
// V5 txids are computed via ZIP 244 during ParseFromSlice.
117+
return
118+
}
119+
// SHA256d (correct for pre-v5 transactions).
119120
digest := sha256.Sum256(tx.Bytes())
120121
digest = sha256.Sum256(digest[:])
121122
tx.SetTxID(digest)
@@ -935,11 +936,17 @@ func DarksideRemoveTreeState(arg *walletrpc.BlockID) error {
935936
}
936937
if arg.Height > 0 {
937938
treestate := state.stagedTreeStates[arg.Height]
939+
if treestate == nil {
940+
return fmt.Errorf("no tree state at height %d", arg.Height)
941+
}
938942
delete(state.stagedTreeStatesByHash, treestate.Hash)
939943
delete(state.stagedTreeStates, treestate.Height)
940944
} else {
941945
h := hex.EncodeToString(arg.Hash)
942946
treestate := state.stagedTreeStatesByHash[h]
947+
if treestate == nil {
948+
return fmt.Errorf("no tree state for hash %s", h)
949+
}
943950
delete(state.stagedTreeStatesByHash, treestate.Hash)
944951
delete(state.stagedTreeStates, treestate.Height)
945952
}

‎parser/transaction.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,11 @@ func (tx *Transaction) isZip225V5() bool {
646646
tx.version == ZIP225_TX_VERSION
647647
}
648648

649+
// IsV5 reports whether the transaction uses the ZIP 225 v5 format.
650+
func (tx *Transaction) IsV5() bool {
651+
return tx.isZip225V5()
652+
}
653+
649654
func (tx *Transaction) isGroth16Proof() bool {
650655
// Sapling changed the joinSplit proof from PHGR (BCTV14) to Groth16;
651656
// this applies also to versions beyond Sapling.

0 commit comments

Comments
 (0)