-
Notifications
You must be signed in to change notification settings - Fork 0
/
zkacc.go
36 lines (30 loc) · 984 Bytes
/
zkacc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package accumulator
import (
crand "crypto/rand"
"fmt"
"math/big"
"time"
)
// GenRandomizer outputs random number uniformly between 0 to 2^2047
func GenRandomizer() *big.Int {
ranNum, err := crand.Int(crand.Reader, Min2048)
if err != nil {
panic(err)
}
return ranNum
}
// ZKAccumulate generates one accumulator which is zero-knowledge
func ZKAccumulate(set []string, encodeType EncodeType, setup *Setup) (*big.Int, []*big.Int) {
startingTime := time.Now().UTC()
rep := GenRepresentatives(set, encodeType)
endingTime := time.Now().UTC()
var duration = endingTime.Sub(startingTime)
fmt.Printf("Running GenRepresentatives Takes [%.3f] Seconds \n",
duration.Seconds())
r := GenRandomizer()
base := AccumulateNew(setup.G, r, setup.N)
proofs := ProveMembership(base, setup.N, rep)
// we generate the accumulator by anyone of the membership proof raised to its power to save some calculation
acc := AccumulateNew(proofs[0], rep[0], setup.N)
return acc, proofs
}