mirror of
				https://source.quilibrium.com/quilibrium/ceremonyclient.git
				synced 2025-04-04 19:36:54 +00:00 
			
		
		
		
	v1.0.1
This commit is contained in:
		
							parent
							
								
									8276e0d1c3
								
							
						
					
					
						commit
						ec7ea35a2d
					
				
							
								
								
									
										89
									
								
								bootstrap.go
									
									
									
									
									
								
							
							
						
						
									
										89
									
								
								bootstrap.go
									
									
									
									
									
								
							| @ -11,6 +11,7 @@ import ( | ||||
| 	"net/http" | ||||
| 	"os" | ||||
| 	"strings" | ||||
| 	"sync" | ||||
| 
 | ||||
| 	"github.com/cloudflare/circl/sign/ed448" | ||||
| 	bls48581 "source.quilibrium.com/quilibrium/ceremonyclient/ec/bls48581" | ||||
| @ -112,15 +113,11 @@ func GetSequencerState() string { | ||||
| 	return string(sequencerState) | ||||
| } | ||||
| 
 | ||||
| func Bootstrap(batch uint, batchSize uint) { | ||||
| 	if batch == 65536/batchSize { | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	if batch == 0 { | ||||
| func Bootstrap() { | ||||
| 	secretBytes := make([]byte, (8 * int(bls48581.MODBYTES))) | ||||
| 	rand.Read(secretBytes) | ||||
| 	secret = bls48581.FromBytes(secretBytes) | ||||
| 	secret.Mod(bls48581.NewBIGints(bls48581.CURVE_Order)) | ||||
| 
 | ||||
| 	bcjRes, err := http.DefaultClient.Post(HOST+"current_state", "application/json", bytes.NewBufferString("{}")) | ||||
| 	if err != nil { | ||||
| @ -138,33 +135,32 @@ func Bootstrap(batch uint, batchSize uint) { | ||||
| 		// message is not conformant, we are in validating phase
 | ||||
| 		panic(err) | ||||
| 	} | ||||
| 	} | ||||
| 
 | ||||
| 	contributeWithSecrets(batch, batchSize, secret) | ||||
| 
 | ||||
| 	fmt.Printf("Participating... %f%% Complete\n", float32(batch*batchSize)/655.36) | ||||
| 	contributeWithSecrets(secret) | ||||
| } | ||||
| 
 | ||||
| func contributeWithSecrets(batch uint, batchSize uint, secret *bls48581.BIG) error { | ||||
| 	updatePowersOfTau(batch, batchSize, secret) | ||||
| 
 | ||||
| 	if batch == 0 { | ||||
| func contributeWithSecrets(secret *bls48581.BIG) error { | ||||
| 	updatePowersOfTau(secret) | ||||
| 	updateWitness(secret) | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| var xi *bls48581.BIG | ||||
| var xi2 *bls48581.BIG | ||||
| var xi []*bls48581.BIG | ||||
| 
 | ||||
| func updatePowersOfTau(batch uint, batchSize uint, secret *bls48581.BIG) { | ||||
| 	if batch == 0 { | ||||
| 		xi = bls48581.NewBIGint(1) | ||||
| 		xi2 = bls48581.NewBIGint(1) | ||||
| func updatePowersOfTau(secret *bls48581.BIG) { | ||||
| 	xi = append(xi, bls48581.NewBIGint(1)) | ||||
| 
 | ||||
| 	for i := 0; i < 65536; i++ { | ||||
| 		xi = append(xi, bls48581.Modmul(xi[i], secret, bls48581.NewBIGints(bls48581.CURVE_Order))) | ||||
| 	} | ||||
| 
 | ||||
| 	for i := batchSize * batch; i < batchSize*(batch+1); i++ { | ||||
| 	wg := sync.WaitGroup{} | ||||
| 	wg.Add(65536) | ||||
| 
 | ||||
| 	for i := 0; i < 65536; i++ { | ||||
| 		i := i | ||||
| 		go func() { | ||||
| 			g1PowersString := strings.TrimPrefix(bcj.PowersOfTau.G1Affines[i], "0x") | ||||
| 			g1PowersHex, _ := hex.DecodeString(g1PowersString) | ||||
| 			g1Power := bls48581.ECP_fromBytes(g1PowersHex) | ||||
| @ -173,30 +169,12 @@ func updatePowersOfTau(batch uint, batchSize uint, secret *bls48581.BIG) { | ||||
| 				panic("invalid g1Power") | ||||
| 			} | ||||
| 
 | ||||
| 		g1Power = g1Power.Mul(xi) | ||||
| 			g1Power = g1Power.Mul(xi[i]) | ||||
| 			g1Power.ToBytes(g1PowersHex, true) | ||||
| 			bcj.PowersOfTau.G1Affines[i] = "0x" + hex.EncodeToString(g1PowersHex) | ||||
| 
 | ||||
| 		if (i%batchSize == 0) && i < uint(257*batchSize) { | ||||
| 			g2PowersString := strings.TrimPrefix(bcj.PowersOfTau.G2Affines[i/batchSize], "0x") | ||||
| 			g2PowersHex, _ := hex.DecodeString(g2PowersString) | ||||
| 			g2Power := bls48581.ECP8_fromBytes(g2PowersHex) | ||||
| 
 | ||||
| 			if g2Power.Equals(bls48581.NewECP8()) { | ||||
| 				panic("invalid g1Power") | ||||
| 			} | ||||
| 
 | ||||
| 			g2Power = g2Power.Mul(xi2) | ||||
| 			g2Power.ToBytes(g2PowersHex, true) | ||||
| 			bcj.PowersOfTau.G2Affines[i/batchSize] = "0x" + hex.EncodeToString(g2PowersHex) | ||||
| 			xi2 = bls48581.Modmul(xi2, secret, bls48581.NewBIGints(bls48581.Modulus)) | ||||
| 		} | ||||
| 		xi = bls48581.Modmul(xi, secret, bls48581.NewBIGints(bls48581.Modulus)) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func updateWitness(secret *bls48581.BIG) { | ||||
| 	g2PowersString := strings.TrimPrefix(bcj.PotPubKey, "0x") | ||||
| 			if i < 257 { | ||||
| 				g2PowersString := strings.TrimPrefix(bcj.PowersOfTau.G2Affines[i], "0x") | ||||
| 				g2PowersHex, _ := hex.DecodeString(g2PowersString) | ||||
| 				g2Power := bls48581.ECP8_fromBytes(g2PowersHex) | ||||
| 
 | ||||
| @ -204,8 +182,29 @@ func updateWitness(secret *bls48581.BIG) { | ||||
| 					panic("invalid g2Power") | ||||
| 				} | ||||
| 
 | ||||
| 	newPotPubKey := g2Power.Mul(secret) | ||||
| 	newPotPubKey.ToBytes(g2PowersHex, true) | ||||
| 				g2Power = g2Power.Mul(xi[i]) | ||||
| 				g2Power.ToBytes(g2PowersHex, true) | ||||
| 				bcj.PowersOfTau.G2Affines[i] = "0x" + hex.EncodeToString(g2PowersHex) | ||||
| 			} | ||||
| 			wg.Done() | ||||
| 		}() | ||||
| 	} | ||||
| 
 | ||||
| 	wg.Wait() | ||||
| } | ||||
| 
 | ||||
| func updateWitness(secret *bls48581.BIG) { | ||||
| 	g2PowersString := strings.TrimPrefix(bcj.PotPubKey, "0x") | ||||
| 	g2PowersHex, _ := hex.DecodeString(g2PowersString) | ||||
| 	g2Power := bls48581.ECP8_fromBytes(g2PowersHex) | ||||
| 	x := bls48581.Modmul(bls48581.NewBIGint(1), secret, bls48581.NewBIGints(bls48581.CURVE_Order)) | ||||
| 
 | ||||
| 	if g2Power.Equals(bls48581.NewECP8()) { | ||||
| 		panic("invalid g2Power") | ||||
| 	} | ||||
| 
 | ||||
| 	g2Power = g2Power.Mul(x) | ||||
| 	g2Power.ToBytes(g2PowersHex, true) | ||||
| 	bcj.PotPubKey = "0x" + hex.EncodeToString(g2PowersHex) | ||||
| 	bcj.VoucherPubKey = "0x" + hex.EncodeToString(voucherPubKey) | ||||
| } | ||||
|  | ||||
							
								
								
									
										10
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								main.go
									
									
									
									
									
								
							| @ -15,16 +15,12 @@ func main() { | ||||
| 	state := GetSequencerState() | ||||
| 	for state != SEQUENCER_ACCEPTING { | ||||
| 		fmt.Println("Sequencer currently not accepting new contributions, waiting...") | ||||
| 		time.Sleep(30 * time.Second) | ||||
| 		time.Sleep(1 * time.Second) | ||||
| 		state = GetSequencerState() | ||||
| 	} | ||||
| 
 | ||||
| 	JoinLobby() | ||||
| 	batchSize := uint(32) | ||||
| 	for batch := uint(0); batch < 65536/batchSize; batch++ { | ||||
| 		Bootstrap(batch, batchSize) | ||||
| 		fmt.Printf("batch: %d\n", batch) | ||||
| 	} | ||||
| 	Bootstrap() | ||||
| 	fmt.Println("New Pubkey: ") | ||||
| 	fmt.Println(bcj.PotPubKey) | ||||
| 	ContributeAndGetVoucher() | ||||
| @ -67,5 +63,5 @@ func PrintLogo() { | ||||
| 
 | ||||
| func PrintVersion() { | ||||
| 	fmt.Println(" ") | ||||
| 	fmt.Println("                    Quilibrium Ceremony Client - CLI - v1.0.0") | ||||
| 	fmt.Println("                    Quilibrium Ceremony Client - CLI - v1.0.1") | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Cassandra Heart
						Cassandra Heart