mirror of
https://source.quilibrium.com/quilibrium/ceremonyclient.git
synced 2024-12-25 16:15:17 +00:00
v1.0.1
This commit is contained in:
parent
8276e0d1c3
commit
ec7ea35a2d
123
bootstrap.go
123
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,100 +113,98 @@ func GetSequencerState() string {
|
|||||||
return string(sequencerState)
|
return string(sequencerState)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Bootstrap(batch uint, batchSize uint) {
|
func Bootstrap() {
|
||||||
if batch == 65536/batchSize {
|
secretBytes := make([]byte, (8 * int(bls48581.MODBYTES)))
|
||||||
return
|
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 {
|
||||||
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if batch == 0 {
|
defer bcjRes.Body.Close()
|
||||||
secretBytes := make([]byte, (8 * int(bls48581.MODBYTES)))
|
|
||||||
rand.Read(secretBytes)
|
|
||||||
secret = bls48581.FromBytes(secretBytes)
|
|
||||||
|
|
||||||
bcjRes, err := http.DefaultClient.Post(HOST+"current_state", "application/json", bytes.NewBufferString("{}"))
|
bcjBytes, err := io.ReadAll(bcjRes.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
|
||||||
|
|
||||||
defer bcjRes.Body.Close()
|
|
||||||
|
|
||||||
bcjBytes, err := io.ReadAll(bcjRes.Body)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := json.Unmarshal(bcjBytes, bcj); err != nil {
|
|
||||||
// message is not conformant, we are in validating phase
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contributeWithSecrets(batch, batchSize, secret)
|
if err := json.Unmarshal(bcjBytes, bcj); err != nil {
|
||||||
|
// message is not conformant, we are in validating phase
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("Participating... %f%% Complete\n", float32(batch*batchSize)/655.36)
|
contributeWithSecrets(secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
func contributeWithSecrets(batch uint, batchSize uint, secret *bls48581.BIG) error {
|
func contributeWithSecrets(secret *bls48581.BIG) error {
|
||||||
updatePowersOfTau(batch, batchSize, secret)
|
updatePowersOfTau(secret)
|
||||||
|
updateWitness(secret)
|
||||||
if batch == 0 {
|
|
||||||
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{}
|
||||||
g1PowersString := strings.TrimPrefix(bcj.PowersOfTau.G1Affines[i], "0x")
|
wg.Add(65536)
|
||||||
g1PowersHex, _ := hex.DecodeString(g1PowersString)
|
|
||||||
g1Power := bls48581.ECP_fromBytes(g1PowersHex)
|
|
||||||
|
|
||||||
if g1Power.Equals(bls48581.NewECP()) {
|
for i := 0; i < 65536; i++ {
|
||||||
panic("invalid g1Power")
|
i := i
|
||||||
}
|
go func() {
|
||||||
|
g1PowersString := strings.TrimPrefix(bcj.PowersOfTau.G1Affines[i], "0x")
|
||||||
|
g1PowersHex, _ := hex.DecodeString(g1PowersString)
|
||||||
|
g1Power := bls48581.ECP_fromBytes(g1PowersHex)
|
||||||
|
|
||||||
g1Power = g1Power.Mul(xi)
|
if g1Power.Equals(bls48581.NewECP()) {
|
||||||
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")
|
panic("invalid g1Power")
|
||||||
}
|
}
|
||||||
|
|
||||||
g2Power = g2Power.Mul(xi2)
|
g1Power = g1Power.Mul(xi[i])
|
||||||
g2Power.ToBytes(g2PowersHex, true)
|
g1Power.ToBytes(g1PowersHex, true)
|
||||||
bcj.PowersOfTau.G2Affines[i/batchSize] = "0x" + hex.EncodeToString(g2PowersHex)
|
bcj.PowersOfTau.G1Affines[i] = "0x" + hex.EncodeToString(g1PowersHex)
|
||||||
xi2 = bls48581.Modmul(xi2, secret, bls48581.NewBIGints(bls48581.Modulus))
|
|
||||||
}
|
if i < 257 {
|
||||||
xi = bls48581.Modmul(xi, secret, bls48581.NewBIGints(bls48581.Modulus))
|
g2PowersString := strings.TrimPrefix(bcj.PowersOfTau.G2Affines[i], "0x")
|
||||||
|
g2PowersHex, _ := hex.DecodeString(g2PowersString)
|
||||||
|
g2Power := bls48581.ECP8_fromBytes(g2PowersHex)
|
||||||
|
|
||||||
|
if g2Power.Equals(bls48581.NewECP8()) {
|
||||||
|
panic("invalid g2Power")
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
func updateWitness(secret *bls48581.BIG) {
|
||||||
g2PowersString := strings.TrimPrefix(bcj.PotPubKey, "0x")
|
g2PowersString := strings.TrimPrefix(bcj.PotPubKey, "0x")
|
||||||
g2PowersHex, _ := hex.DecodeString(g2PowersString)
|
g2PowersHex, _ := hex.DecodeString(g2PowersString)
|
||||||
g2Power := bls48581.ECP8_fromBytes(g2PowersHex)
|
g2Power := bls48581.ECP8_fromBytes(g2PowersHex)
|
||||||
|
x := bls48581.Modmul(bls48581.NewBIGint(1), secret, bls48581.NewBIGints(bls48581.CURVE_Order))
|
||||||
|
|
||||||
if g2Power.Equals(bls48581.NewECP8()) {
|
if g2Power.Equals(bls48581.NewECP8()) {
|
||||||
panic("invalid g2Power")
|
panic("invalid g2Power")
|
||||||
}
|
}
|
||||||
|
|
||||||
newPotPubKey := g2Power.Mul(secret)
|
g2Power = g2Power.Mul(x)
|
||||||
newPotPubKey.ToBytes(g2PowersHex, true)
|
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