From e3ae97ac5ab7740fad8d78794f8f9a134784ad5a Mon Sep 17 00:00:00 2001 From: David Florness Date: Thu, 29 Apr 2021 23:21:26 -0400 Subject: [PATCH] Remove infinite retries for reading proving keys It seems this was fixed in gnark-crypto v0.4.0 [0]: point.SetBytes can now be called concurently with same byte slice input [0]: https://github.com/ConsenSys/gnark-crypto/releases/tag/v0.4.0 --- election/msg.go | 12 ++++-------- election/voter.go | 15 ++------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/election/msg.go b/election/msg.go index 41f3a9a..2a44d43 100644 --- a/election/msg.go +++ b/election/msg.go @@ -444,7 +444,6 @@ func (elections *ElectionsMap) onKeysMessage(evt *event.Event, client *mautrix.C errorf("couldn't download eval proving key: %s", err) return } - tryEvalPk: var buf bytes.Buffer _, err = buf.Write(byts) if err != nil { @@ -454,9 +453,8 @@ func (elections *ElectionsMap) onKeysMessage(evt *event.Event, client *mautrix.C evalProvingKey = groth16.NewProvingKey(ecc.BLS12_381) _, err = evalProvingKey.ReadFrom(&buf) if err != nil { - log.Errorf("couldn't read eval key from downloaded eval proving keys file: %s", err) - log.Debug("trying again...") - goto tryEvalPk + errorf("couldn't read eval key from downloaded eval proving keys file: %s", err) + return } } @@ -467,7 +465,6 @@ func (elections *ElectionsMap) onKeysMessage(evt *event.Event, client *mautrix.C errorf("couldn't download sum proving key: %s", err) return } - trySumPk: var buf bytes.Buffer _, err = buf.Write(byts) if err != nil { @@ -477,9 +474,8 @@ func (elections *ElectionsMap) onKeysMessage(evt *event.Event, client *mautrix.C sumProvingKey = groth16.NewProvingKey(ecc.BLS12_381) _, err = sumProvingKey.ReadFrom(&buf) if err != nil { - log.Errorf("couldn't read sum key from downloaded sum keys file: %s", err) - log.Debug("trying again...") - goto trySumPk + errorf("couldn't read sum key from downloaded sum keys file: %s", err) + return } } diff --git a/election/voter.go b/election/voter.go index b6423d4..f44b5a7 100644 --- a/election/voter.go +++ b/election/voter.go @@ -188,18 +188,7 @@ func (el *Election) SendProvingKeys(client *mautrix.Client, eventStore *EventSto } var evalPkBytes bytes.Buffer - // TODO: change back to WriteTo. There seems to be a bug in - // gnark/gurvy (or a misunderstanding on my part) where - // decompression fails - // ignoring ...'s keys msg ($tsSEYHiouPdJlaTqAOG2q_4t9MZa0OGHtJPD95jOvAg) since couldn't read sum key from bytes buffer: invalid compressed coordinate: square root doesn't exist - // The file was successfully processed on one side (who - // coincidentally was the sender) but not on the other - // NOTE: it's plausible this was fixed in gurvy (now gnark-crypto) 0.4.0: - // - // point.SetBytes can now be called concurently with same byte slice input - // - // https://github.com/ConsenSys/gnark-crypto/releases/tag/v0.4.0 - evalProvingKey.WriteRawTo(&evalPkBytes) + evalProvingKey.WriteTo(&evalPkBytes) uploadResp, err := client.UploadMedia(mautrix.ReqUploadMedia{ Content: &evalPkBytes, ContentLength: int64(evalPkBytes.Len()), @@ -241,7 +230,7 @@ func (el *Election) SendProvingKeys(client *mautrix.Client, eventStore *EventSto var sumPkBytes bytes.Buffer // TODO: see above - sumProvingKey.WriteRawTo(&sumPkBytes) + sumProvingKey.WriteTo(&sumPkBytes) uploadResp, err := client.UploadMedia(mautrix.ReqUploadMedia{ Content: &sumPkBytes, ContentLength: int64(sumPkBytes.Len()), -- 2.38.4