From b8b01f536f36ddd64d7ca35352cc761c5b5a4810 Mon Sep 17 00:00:00 2001 From: Jared Tobin Date: Fri, 1 May 2026 12:00:19 -0230 Subject: [PATCH] mssmt: guard nil children in BranchNode.Copy NewComputedBranch creates BranchNode with nil Left/Right children, which the DB-backed tree stores return during proof construction. Copy() previously dereferenced these unconditionally, causing a panic when running mssmt tests against sqlite3/postgres backends. --- mssmt/node.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mssmt/node.go b/mssmt/node.go index e29b67f1e4..dab5a8a731 100644 --- a/mssmt/node.go +++ b/mssmt/node.go @@ -275,10 +275,22 @@ func (n *BranchNode) Copy() Node { *sumCopy = *n.sum } + var leftCopy, rightCopy Node + if n.Left != nil { + leftCopy = NewComputedNode( + n.Left.NodeHash(), n.Left.NodeSum(), + ) + } + if n.Right != nil { + rightCopy = NewComputedNode( + n.Right.NodeHash(), n.Right.NodeSum(), + ) + } + return &BranchNode{ nodeHash: nodeHashCopy, - Left: NewComputedNode(n.Left.NodeHash(), n.Left.NodeSum()), - Right: NewComputedNode(n.Right.NodeHash(), n.Right.NodeSum()), + Left: leftCopy, + Right: rightCopy, sum: sumCopy, } }