func RebuildTreeHashStack(stackBytes []byte) *TreeHashStack{
	th := &TreeHashStack{}
	th.leaf = binary.LittleEndian.Uint32(stackBytes[8:])
	th.leafUpper = binary.LittleEndian.Uint32(stackBytes[12:])
	th.height = binary.LittleEndian.Uint32(stackBytes[16:])
	stackSize := binary.LittleEndian.Uint32(stackBytes[0:])
	elementSize := binary.LittleEndian.Uint32(stackBytes[4:])
	hashSize := int(elementSize) - 4
	offset := 20
	th.nodeStack = stack.New()
	for i := 0 ; i < int(stackSize); i++{
		height := binary.LittleEndian.Uint32(stackBytes[offset : offset + 4])
		offset += 4
		nu := stackBytes[offset : offset+hashSize]
		offset += hashSize
		node := &Node{
			height: height,
			nu: nu,
		}
		th.nodeStack.Push(node)
	}
	return th
}
RebuildTreeHashStack restores the TreeHashStack from serialized bytes
package mss
import (
	"fmt"
	"math"
	"github.com/LoCCS/mss/config"
	"github.com/LoCCS/mss/container/stack"
	"encoding/binary"
)
type Node struct {
	height uint32
	nu []byte
}
func (node *Node) String() string {
	return fmt.Sprintf("{height: %v}", node.height)
}
type TreeHashStack struct {
	leaf      uint32        
	leafUpper uint32        
	height    uint32        
	nodeStack *stack.Stack  
}
func (th *TreeHashStack) SetLeaf(leaf uint32) {
	th.leaf = leaf
}
func NewTreeHashStack(startingLeaf, h uint32) *TreeHashStack {
	treeHashStack := new(TreeHashStack)
	treeHashStack.Init(startingLeaf, h)
	return treeHashStack
}
func (th *TreeHashStack) Init(startingLeaf, h uint32) error {
	th.leaf, th.leafUpper, th.height = startingLeaf, startingLeaf+(1<<h), h
	th.nodeStack = stack.New()  
	return nil
}
func (th *TreeHashStack) IsCompleted() bool {
	return (th.leaf >= th.leafUpper) && (th.nodeStack.Peek().(*Node).height == th.height)
}
func (th *TreeHashStack) LowestTailHeight() uint32 {
	if th.nodeStack.Empty() {
		return th.height
	}
	if th.IsCompleted() {
		return math.MaxUint32
	}
	return th.Top().height
}
func (th *TreeHashStack) Top() *Node {
	if th.nodeStack.Empty() {
		return nil
	}
	return th.nodeStack.Peek().(*Node)
}
func (th *TreeHashStack) Update(numOp uint32, nodeHouse [][]byte) {
	for (numOp > 0) && !th.IsCompleted() {
		if th.nodeStack.Len() >= 2 {
			e1, e2 := th.nodeStack.Peek2()
			node1 := e1.(*Node)
			node2 := e2.(*Node)
			if node1.height == node2.height {
				th.nodeStack.Pop()
				th.nodeStack.Pop()
				th.nodeStack.Push(&Node{node1.height + 1, merge(node2.nu, node1.nu)})
				numOp--
				continue
			}
		}
		if th.leaf >= uint32(len(nodeHouse)) {
			th.nodeStack.Push(&Node{0, nodeHouse[0]})
		} else {
			th.nodeStack.Push(&Node{0, nodeHouse[th.leaf]})
		}
		th.leaf++
		numOp--
	}
}
func (th *TreeHashStack) Serialize() []byte{
	stackSize := uint32(th.nodeStack.Len())
	elementSize := uint32(4 + config.Size)
	ret := make([]byte, 20 + stackSize * elementSize)
	binary.LittleEndian.PutUint32(ret[0:], stackSize)
	binary.LittleEndian.PutUint32(ret[4:], elementSize)
	binary.LittleEndian.PutUint32(ret[8:], th.leaf)
	binary.LittleEndian.PutUint32(ret[12:], th.leafUpper)
	binary.LittleEndian.PutUint32(ret[16:], th.height)
	vs := th.nodeStack.ValueSlice()
	offset := 20
	for i := 0; i < th.nodeStack.Len(); i++{
		binary.LittleEndian.PutUint32(ret[offset:], vs[i].(*Node).height)
		offset += 4
		copy(ret[offset:], vs[i].(*Node).nu)
		offset += config.Size
	}
	return ret
}