示例#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 TestMain(m *testing.M) {
	os.Remove("block.chain")
	chain = NewBlockChain("block.chain")

	pk := []byte{1}
	pos.Setup(pk, 4, "../pos/graph")
	prover := pos.NewProver(pk, 4, "../pos/graph")
	commit := prover.Init()
	pos := PoS{
		Commit:    *commit,
		Challenge: []byte{2},
		Answer: Answer{
			Size:   4,
			Hashes: [][]byte{[]byte{3}, []byte{4}},
			Proofs: nil,
		},
		Quality: 1.3,
	}

	ts := make([]Transaction, 2)

	sk, _ := sign.GenerateKey(elliptic.P256(), rand.Reader)
	oldB = &Block{
		Id:    0,
		Hash:  Hash{},
		Trans: make([]Transaction, 3),
		Sig:   Signature{},
	}
	b = NewBlock(oldB, pos, ts, sk)
	os.Exit(m.Run())
}
示例#3
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())
	}
}