예제 #1
0
func NewClient(t time.Duration, dist, beta int, index int64, graph string) *Client {
	sk, err := sign.GenerateKey(elliptic.P256(), rand.Reader)
	if err != nil {
		panic(err)
	}
	pk := sk.Public()
	pkBytes, err := json.Marshal(pk)
	if err != nil {
		panic(err)
	}

	prover := pos.NewProver(pkBytes, index, "Xi", graph)
	commit := prover.Init()
	verifier := pos.NewVerifier(pkBytes, index, beta, commit.Commit)

	c := Client{
		sk:   sk,
		pk:   pk,
		t:    t,
		dist: dist,

		sols: make(chan *block.Block, 100), // nomially say 100 answers per round..

		index:    index,
		prover:   prover,
		verifier: verifier,
		commit:   *commit,
	}
	return &c
}
예제 #2
0
func main() {
	idx := flag.Int("index", 1, "graph index")
	name := flag.String("name", "Xi", "graph name")
	dir := flag.String("file", "/media/storage/Xi", "graph location")
	mode := flag.String("mode", "gen", "mode:[gen|commit]")
	flag.Parse()

	pk := []byte{1}
	beta := 30
	now := time.Now()
	prover := pos.NewProver(pk, int64(*idx), *name, *dir)
	if *mode == "gen" {
		fmt.Printf("%d. Graph gen: %fs\n", *idx, time.Since(now).Seconds())
	} else if *mode == "commit" {
		now = time.Now()
		prover.Init()
		fmt.Printf("%d. Graph commit: %fs\n", *idx, time.Since(now).Seconds())
	} else if *mode == "check" {
		commit := prover.PreInit()
		root := commit.Commit
		verifier := pos.NewVerifier(pk, int64(*idx), beta, root)

		seed := make([]byte, 64)
		rand.Read(seed)
		cs := verifier.SelectChallenges(seed)

		now = time.Now()
		hashes, parents, proofs, pProofs := prover.ProveSpace(cs)
		fmt.Printf("Prove: %f\n", time.Since(now).Seconds())

		now = time.Now()
		if !verifier.VerifySpace(cs, hashes, parents, proofs, pProofs) {
			log.Fatal("Verify space failed:", cs)
		}
		fmt.Printf("Verify: %f\n", time.Since(now).Seconds())
	}
}