Пример #1
0
func NewVerifier(pk []byte, index int64, beta int, root []byte) *Verifier {
	size := numXi(index)
	log2 := util.Log2(size) + 1
	pow2 := int64(1 << uint64(log2))
	if (1 << uint64(log2-1)) == size {
		log2--
		pow2 = 1 << uint64(log2)
	}

	graph := &Graph{
		pk:    pk,
		index: index,
		log2:  log2,
		pow2:  pow2,
		size:  size,
	}

	v := Verifier{
		pk:   pk,
		beta: beta,
		root: root,

		graph: graph,
		index: index,
		size:  size,
		pow2:  pow2,
		log2:  log2,
	}
	return &v
}
Пример #2
0
func NewProver(pk []byte, index int64, name, graph string) *Prover {
	size := numXi(index)
	log2 := util.Log2(size) + 1
	pow2 := int64(1 << uint64(log2))
	if (1 << uint64(log2-1)) == size {
		log2--
		pow2 = 1 << uint64(log2)
	}

	g := NewGraph(index, size, pow2, log2, graph, pk)

	empty := make(map[int64]bool)

	// if not power of 2, then uneven merkle
	if util.Count(uint64(size)) != 1 {
		for i := pow2 + size; util.Count(uint64(i+1)) != 1; i /= 2 {
			empty[i+1] = true
		}
	}

	p := Prover{
		pk:    pk,
		graph: g,
		name:  name,

		index: index,
		size:  size,
		pow2:  pow2,
		log2:  log2,
		empty: empty,
	}
	return &p
}
Пример #3
0
func (g *Graph) subtree(node int64) int64 {
	level := (g.log2 + 1) - util.Log2(node)
	return int64((1 << uint64(level)) - 1)
}