mirror of
				https://source.quilibrium.com/quilibrium/ceremonyclient.git
				synced 2025-10-31 21:47:27 +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" | 	"net/http" | ||||||
| 	"os" | 	"os" | ||||||
| 	"strings" | 	"strings" | ||||||
|  | 	"sync" | ||||||
| 
 | 
 | ||||||
| 	"github.com/cloudflare/circl/sign/ed448" | 	"github.com/cloudflare/circl/sign/ed448" | ||||||
| 	bls48581 "source.quilibrium.com/quilibrium/ceremonyclient/ec/bls48581" | 	bls48581 "source.quilibrium.com/quilibrium/ceremonyclient/ec/bls48581" | ||||||
| @ -112,15 +113,11 @@ func GetSequencerState() string { | |||||||
| 	return string(sequencerState) | 	return string(sequencerState) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func Bootstrap(batch uint, batchSize uint) { | func Bootstrap() { | ||||||
| 	if batch == 65536/batchSize { |  | ||||||
| 		return |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if batch == 0 { |  | ||||||
| 	secretBytes := make([]byte, (8 * int(bls48581.MODBYTES))) | 	secretBytes := make([]byte, (8 * int(bls48581.MODBYTES))) | ||||||
| 	rand.Read(secretBytes) | 	rand.Read(secretBytes) | ||||||
| 	secret = bls48581.FromBytes(secretBytes) | 	secret = bls48581.FromBytes(secretBytes) | ||||||
|  | 	secret.Mod(bls48581.NewBIGints(bls48581.CURVE_Order)) | ||||||
| 
 | 
 | ||||||
| 	bcjRes, err := http.DefaultClient.Post(HOST+"current_state", "application/json", bytes.NewBufferString("{}")) | 	bcjRes, err := http.DefaultClient.Post(HOST+"current_state", "application/json", bytes.NewBufferString("{}")) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @ -138,33 +135,32 @@ func Bootstrap(batch uint, batchSize uint) { | |||||||
| 		// message is not conformant, we are in validating phase
 | 		// message is not conformant, we are in validating phase
 | ||||||
| 		panic(err) | 		panic(err) | ||||||
| 	} | 	} | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	contributeWithSecrets(batch, batchSize, secret) | 	contributeWithSecrets(secret) | ||||||
| 
 |  | ||||||
| 	fmt.Printf("Participating... %f%% Complete\n", float32(batch*batchSize)/655.36) |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func contributeWithSecrets(batch uint, batchSize uint, secret *bls48581.BIG) error { | func contributeWithSecrets(secret *bls48581.BIG) error { | ||||||
| 	updatePowersOfTau(batch, batchSize, secret) | 	updatePowersOfTau(secret) | ||||||
| 
 |  | ||||||
| 	if batch == 0 { |  | ||||||
| 	updateWitness(secret) | 	updateWitness(secret) | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var xi *bls48581.BIG | var xi []*bls48581.BIG | ||||||
| var xi2 *bls48581.BIG |  | ||||||
| 
 | 
 | ||||||
| func updatePowersOfTau(batch uint, batchSize uint, secret *bls48581.BIG) { | func updatePowersOfTau(secret *bls48581.BIG) { | ||||||
| 	if batch == 0 { | 	xi = append(xi, bls48581.NewBIGint(1)) | ||||||
| 		xi = bls48581.NewBIGint(1) | 
 | ||||||
| 		xi2 = 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") | 			g1PowersString := strings.TrimPrefix(bcj.PowersOfTau.G1Affines[i], "0x") | ||||||
| 			g1PowersHex, _ := hex.DecodeString(g1PowersString) | 			g1PowersHex, _ := hex.DecodeString(g1PowersString) | ||||||
| 			g1Power := bls48581.ECP_fromBytes(g1PowersHex) | 			g1Power := bls48581.ECP_fromBytes(g1PowersHex) | ||||||
| @ -173,30 +169,12 @@ func updatePowersOfTau(batch uint, batchSize uint, secret *bls48581.BIG) { | |||||||
| 				panic("invalid g1Power") | 				panic("invalid g1Power") | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 		g1Power = g1Power.Mul(xi) | 			g1Power = g1Power.Mul(xi[i]) | ||||||
| 			g1Power.ToBytes(g1PowersHex, true) | 			g1Power.ToBytes(g1PowersHex, true) | ||||||
| 			bcj.PowersOfTau.G1Affines[i] = "0x" + hex.EncodeToString(g1PowersHex) | 			bcj.PowersOfTau.G1Affines[i] = "0x" + hex.EncodeToString(g1PowersHex) | ||||||
| 
 | 
 | ||||||
| 		if (i%batchSize == 0) && i < uint(257*batchSize) { | 			if i < 257 { | ||||||
| 			g2PowersString := strings.TrimPrefix(bcj.PowersOfTau.G2Affines[i/batchSize], "0x") | 				g2PowersString := strings.TrimPrefix(bcj.PowersOfTau.G2Affines[i], "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") |  | ||||||
| 				g2PowersHex, _ := hex.DecodeString(g2PowersString) | 				g2PowersHex, _ := hex.DecodeString(g2PowersString) | ||||||
| 				g2Power := bls48581.ECP8_fromBytes(g2PowersHex) | 				g2Power := bls48581.ECP8_fromBytes(g2PowersHex) | ||||||
| 
 | 
 | ||||||
| @ -204,8 +182,29 @@ func updateWitness(secret *bls48581.BIG) { | |||||||
| 					panic("invalid g2Power") | 					panic("invalid g2Power") | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
| 	newPotPubKey := g2Power.Mul(secret) | 				g2Power = g2Power.Mul(xi[i]) | ||||||
| 	newPotPubKey.ToBytes(g2PowersHex, true) | 				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.PotPubKey = "0x" + hex.EncodeToString(g2PowersHex) | ||||||
| 	bcj.VoucherPubKey = "0x" + hex.EncodeToString(voucherPubKey) | 	bcj.VoucherPubKey = "0x" + hex.EncodeToString(voucherPubKey) | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										10
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								main.go
									
									
									
									
									
								
							| @ -15,16 +15,12 @@ func main() { | |||||||
| 	state := GetSequencerState() | 	state := GetSequencerState() | ||||||
| 	for state != SEQUENCER_ACCEPTING { | 	for state != SEQUENCER_ACCEPTING { | ||||||
| 		fmt.Println("Sequencer currently not accepting new contributions, waiting...") | 		fmt.Println("Sequencer currently not accepting new contributions, waiting...") | ||||||
| 		time.Sleep(30 * time.Second) | 		time.Sleep(1 * time.Second) | ||||||
| 		state = GetSequencerState() | 		state = GetSequencerState() | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	JoinLobby() | 	JoinLobby() | ||||||
| 	batchSize := uint(32) | 	Bootstrap() | ||||||
| 	for batch := uint(0); batch < 65536/batchSize; batch++ { |  | ||||||
| 		Bootstrap(batch, batchSize) |  | ||||||
| 		fmt.Printf("batch: %d\n", batch) |  | ||||||
| 	} |  | ||||||
| 	fmt.Println("New Pubkey: ") | 	fmt.Println("New Pubkey: ") | ||||||
| 	fmt.Println(bcj.PotPubKey) | 	fmt.Println(bcj.PotPubKey) | ||||||
| 	ContributeAndGetVoucher() | 	ContributeAndGetVoucher() | ||||||
| @ -67,5 +63,5 @@ func PrintLogo() { | |||||||
| 
 | 
 | ||||||
| func PrintVersion() { | func PrintVersion() { | ||||||
| 	fmt.Println(" ") | 	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