mirror of
https://github.com/arnaucube/eth-kzg-ceremony-alt.git
synced 2026-01-08 15:01:30 +01:00
Update queue waiting logic
This commit is contained in:
@@ -19,6 +19,9 @@ Documents used for this implementation:
|
||||
- [KZG10-Ceremony-audit-report.pdf, section *3.1 Overview of PoT ceremonies*](https://github.com/ethereum/kzg-ceremony/blob/main/KZG10-Ceremony-audit-report.pdf)
|
||||
- [*Why and how zkSNARKs work*, by Maksym Petkus](https://arxiv.org/abs/1906.07221v1)
|
||||
|
||||
|
||||
You can find more info on the logic behind the powers of tau computation & verification in these notes: http://arnaucube.com/blog/powersoftau.html
|
||||
|
||||
### Usage
|
||||
Get the binary from the [releases](https://github.com/arnaucube/eth-kzg-ceremony-alt/releases) (alternative you can compile it from source), and run:
|
||||
```
|
||||
@@ -28,9 +31,9 @@ eth-kzg-ceremony-alt
|
||||
====================
|
||||
|
||||
Usage of ./kzgceremony:
|
||||
-u, --url string sequencer url (default "https://kzg-ceremony-sequencer-dev.fly.dev")
|
||||
-r, --rand string randomness
|
||||
-s, --sleeptime uint time (seconds) sleeping before trying again to be the next contributor (default 10)
|
||||
-u, --url string sequencer url (default "https://seq.ceremony.ethereum.org")
|
||||
-r, --rand string randomness, needs to be bigger than 64 bytes
|
||||
-s, --sleeptime uint time (seconds) sleeping before trying again to be the next contributor (default 30)
|
||||
```
|
||||
|
||||
So for example, run your contribution with:
|
||||
|
||||
@@ -132,38 +132,47 @@ func (c *Client) PostAuthCallback() (*MsgRequestLink, error) {
|
||||
return &msg, err
|
||||
}
|
||||
|
||||
func (c *Client) PostTryContribute(sessionID string) (*kzgceremony.BatchContribution, bool, error) {
|
||||
type Status int
|
||||
|
||||
const (
|
||||
StatusReauth = Status(iota)
|
||||
StatusError
|
||||
StatusWait
|
||||
StatusProceed
|
||||
)
|
||||
|
||||
func (c *Client) PostTryContribute(sessionID string) (*kzgceremony.BatchContribution, Status, error) {
|
||||
bearer := "Bearer " + sessionID
|
||||
resp, err := c.postWithAuth(
|
||||
c.url+"/lobby/try_contribute", "application/json", nil, bearer)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
return nil, StatusError, err
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
return nil, StatusError, err
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
fmt.Println(string(body))
|
||||
switch resp.StatusCode {
|
||||
case http.StatusBadRequest:
|
||||
return nil, true, fmt.Errorf("call came to early. rate limited")
|
||||
return nil, StatusWait, fmt.Errorf("call came to early. rate limited")
|
||||
case http.StatusUnauthorized:
|
||||
return nil, false, fmt.Errorf("unkown session id. unauthorized access")
|
||||
return nil, StatusReauth, fmt.Errorf("unkown session id. unauthorized access")
|
||||
default:
|
||||
return nil, false, fmt.Errorf("unexpected http code: %d", resp.StatusCode)
|
||||
return nil, StatusWait, fmt.Errorf("unexpected http code: %d", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile("prevBatchContribution.json", body, 0600)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
return nil, StatusError, err
|
||||
}
|
||||
bc := &kzgceremony.BatchContribution{}
|
||||
err = json.Unmarshal(body, bc)
|
||||
return bc, false, err
|
||||
return bc, StatusError, err
|
||||
}
|
||||
|
||||
func (c *Client) PostAbortContribution(sessionID string) ([]byte, error) {
|
||||
|
||||
88
cmd/cmd.go
88
cmd/cmd.go
@@ -15,26 +15,28 @@ import (
|
||||
flag "github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
var (
|
||||
redB = color.New(color.FgRed, color.Bold)
|
||||
cyan = color.New(color.FgCyan)
|
||||
cyanB = color.New(color.FgCyan, color.Bold)
|
||||
green = color.New(color.FgHiGreen)
|
||||
greenB = color.New(color.FgHiGreen, color.Bold)
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("eth-kzg-ceremony-alt")
|
||||
fmt.Printf("====================\n")
|
||||
fmt.Printf(" https://github.com/arnaucube/eth-kzg-ceremony-alt\n\n")
|
||||
|
||||
redB := color.New(color.FgRed, color.Bold)
|
||||
cyan := color.New(color.FgCyan)
|
||||
cyanB := color.New(color.FgCyan, color.Bold)
|
||||
green := color.New(color.FgHiGreen)
|
||||
greenB := color.New(color.FgHiGreen, color.Bold)
|
||||
|
||||
var sequencerURL string
|
||||
var randomness string
|
||||
var sleepTime uint64
|
||||
flag.StringVarP(&sequencerURL, "url", "u",
|
||||
"https://sequencer.ceremony.ethereum.org", "sequencer url")
|
||||
"https://seq.ceremony.ethereum.org", "sequencer url")
|
||||
flag.StringVarP(&randomness, "rand", "r",
|
||||
"", fmt.Sprintf("randomness, needs to be bigger than %d", kzgceremony.MinRandomnessLen))
|
||||
"", fmt.Sprintf("randomness, needs to be bigger than %d bytes", kzgceremony.MinRandomnessLen))
|
||||
flag.Uint64VarP(&sleepTime, "sleeptime", "s",
|
||||
10, "time (seconds) sleeping before trying again to be the next contributor")
|
||||
30, "time (seconds) sleeping before trying again to be the next contributor")
|
||||
|
||||
flag.CommandLine.SortFlags = false
|
||||
flag.Parse()
|
||||
@@ -61,25 +63,8 @@ func main() {
|
||||
}
|
||||
|
||||
// Auth
|
||||
msgReqLink, err := c.GetRequestLink()
|
||||
if err != nil {
|
||||
printErrAndExit(err)
|
||||
}
|
||||
|
||||
_, _ = green.Printf("Please go to\n%s\n and authenticate with Github.\n", msgReqLink.GithubAuthURL)
|
||||
fmt.Println("(currently only Github auth is supported)")
|
||||
|
||||
_, _ = greenB.Printf("Paste here the RawData from the auth answer:\n")
|
||||
s, err := readInput()
|
||||
if err != nil {
|
||||
printErrAndExit(err)
|
||||
}
|
||||
var authMsg client.MsgAuthCallback
|
||||
if err = json.Unmarshal([]byte(s), &authMsg); err != nil {
|
||||
printErrAndExit(err)
|
||||
}
|
||||
fmt.Print("Parsed auth msg: ")
|
||||
_, _ = cyan.Printf("%#v\n", authMsg)
|
||||
fmt.Println("Github Authorization:")
|
||||
authMsg := authGH(c)
|
||||
|
||||
// TODO this will be only triggered by a flag
|
||||
// msg, err := c.PostAbortContribution(authMsg.SessionID)
|
||||
@@ -94,16 +79,27 @@ func main() {
|
||||
var prevBatchContribution *kzgceremony.BatchContribution
|
||||
for {
|
||||
fmt.Printf("%s sending try_contribute\n", time.Now().Format("2006-01-02 15:04:05"))
|
||||
var retry bool
|
||||
prevBatchContribution, retry, err = c.PostTryContribute(authMsg.SessionID)
|
||||
var status client.Status
|
||||
prevBatchContribution, status, err = c.PostTryContribute(authMsg.SessionID)
|
||||
if err != nil {
|
||||
_, _ = cyan.Println(err)
|
||||
}
|
||||
if !retry {
|
||||
if status == client.StatusProceed {
|
||||
break
|
||||
}
|
||||
fmt.Printf("%s try_contribute unsuccessful, going to sleep %d seconds\n",
|
||||
time.Now().Format("2006-01-02 15:04:05"), sleepTime)
|
||||
if status == client.StatusReauth {
|
||||
fmt.Println("SessionID has expired, authenticate again with Github:")
|
||||
authMsg = authGH(c)
|
||||
}
|
||||
msgStatus, err := c.GetCurrentStatus()
|
||||
if err != nil {
|
||||
printErrAndExit(err)
|
||||
}
|
||||
fmt.Printf("%s try_contribute unsuccessful, lobby size %d, num contrib %d,"+
|
||||
"\n going to sleep %d seconds\n",
|
||||
time.Now().Format("2006-01-02 15:04:05"),
|
||||
msgStatus.LobbySize, msgStatus.NumContributions,
|
||||
sleepTime)
|
||||
time.Sleep(time.Duration(sleepTime) * time.Second)
|
||||
}
|
||||
|
||||
@@ -115,10 +111,13 @@ func main() {
|
||||
// }
|
||||
|
||||
fmt.Println("starting to compute new contribution")
|
||||
t0 := time.Now()
|
||||
newBatchContribution, err := prevBatchContribution.Contribute([]byte(randomness))
|
||||
if err != nil {
|
||||
printErrAndExit(err)
|
||||
}
|
||||
fmt.Println("Contribution computed in", time.Since(t0))
|
||||
|
||||
// store contribution
|
||||
fmt.Println("storing contribution.json")
|
||||
b, err := json.Marshal(newBatchContribution)
|
||||
@@ -151,6 +150,29 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func authGH(c *client.Client) client.MsgAuthCallback {
|
||||
msgReqLink, err := c.GetRequestLink()
|
||||
if err != nil {
|
||||
printErrAndExit(err)
|
||||
}
|
||||
|
||||
_, _ = green.Printf("Please go to\n%s\n and authenticate with Github.\n", msgReqLink.GithubAuthURL)
|
||||
fmt.Println("(currently only Github auth is supported)")
|
||||
|
||||
_, _ = greenB.Printf("Paste here the RawData from the auth answer:\n")
|
||||
s, err := readInput()
|
||||
if err != nil {
|
||||
printErrAndExit(err)
|
||||
}
|
||||
var authMsg client.MsgAuthCallback
|
||||
if err = json.Unmarshal([]byte(s), &authMsg); err != nil {
|
||||
printErrAndExit(err)
|
||||
}
|
||||
fmt.Print("Parsed auth msg: ")
|
||||
_, _ = cyan.Printf("%#v\n", authMsg)
|
||||
return authMsg
|
||||
}
|
||||
|
||||
func printErrAndExit(err error) {
|
||||
red := color.New(color.FgRed)
|
||||
_, _ = red.Println(err)
|
||||
|
||||
Reference in New Issue
Block a user