~edwargix/tallyard

deb9e24ac75364758dcbe4ebe0db4238fbdf70d5 — David Florness 1 year, 8 months ago 3dd4bd6
Bump gnark from v0.7.1 to v0.8.0

Release: <https://github.com/ConsenSys/gnark/releases/tag/v0.8.0>
Signed-off-by: David Florness <david@florness.com>
6 files changed, 31 insertions(+), 16 deletions(-)

M election/msg.go
M election/voter.go
M go.mod
M go.sum
M math/poly.go
M math/zk.go
M election/msg.go => election/msg.go +2 -2
@@ 745,7 745,7 @@ func (elections *ElectionsMap) onEvalsMessage(evt *event.Event) (success bool) {
			errorf("our evals verifying key is nil")
			return
		}
		witness, err := frontend.NewWitness(&publicCircuit, ecc.BLS12_381, frontend.PublicOnly())
		witness, err := frontend.NewWitness(&publicCircuit, ecc.BLS12_381.ScalarField(), frontend.PublicOnly())
		if err != nil {
			errorf("couldn't create witness: %w", err)
			return


@@ 946,7 946,7 @@ func (elections *ElectionsMap) onSumMessage(evt *event.Event) (success bool) {
			errorf("our sum verifying key is nil")
			return
		}
		witness, err := frontend.NewWitness(&publicCircuit, ecc.BLS12_381, frontend.PublicOnly())
		witness, err := frontend.NewWitness(&publicCircuit, ecc.BLS12_381.ScalarField(), frontend.PublicOnly())
		if err != nil {
			errorf("couldn't create witness: %w", err)
			return

M election/voter.go => election/voter.go +1 -1
@@ 421,7 421,7 @@ func (el *Election) SendSum(client *mautrix.Client, eventStore *EventStore) erro
			outputs[i] = evaler.Output
		}

		witness, err := frontend.NewWitness(&circuit, ecc.BLS12_381)
		witness, err := frontend.NewWitness(&circuit, ecc.BLS12_381.ScalarField())
		if err != nil {
			return fmt.Errorf("couldn't create witness: %w", err)
		}

M go.mod => go.mod +6 -2
@@ 4,8 4,8 @@ go 1.18

require (
	github.com/adrg/xdg v0.4.0
	github.com/consensys/gnark v0.7.1
	github.com/consensys/gnark-crypto v0.7.0
	github.com/consensys/gnark v0.8.0
	github.com/consensys/gnark-crypto v0.9.1
	github.com/gdamore/tcell/v2 v2.6.0
	github.com/rivo/tview v0.0.0-20230203122838-f0550c7918da
	github.com/sirupsen/logrus v1.9.0


@@ 15,8 15,11 @@ require (
)

require (
	github.com/blang/semver/v4 v4.0.0 // indirect
	github.com/consensys/bavard v0.1.13 // indirect
	github.com/fxamacker/cbor/v2 v2.4.0 // indirect
	github.com/gdamore/encoding v1.0.0 // indirect
	github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
	github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
	github.com/mattn/go-colorable v0.1.13 // indirect
	github.com/mattn/go-isatty v0.0.17 // indirect


@@ 33,4 36,5 @@ require (
	golang.org/x/sys v0.5.0 // indirect
	golang.org/x/term v0.5.0 // indirect
	golang.org/x/text v0.7.0 // indirect
	rsc.io/tmplfunc v0.0.3 // indirect
)

M go.sum => go.sum +13 -4
@@ 1,9 1,13 @@
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/consensys/gnark v0.7.1 h1:0ZWY9uKhhznRn541ptjdt0XxriOp1ikAubAkHahoJyQ=
github.com/consensys/gnark v0.7.1/go.mod h1:oQnMurInsfe+9rG4l8qh8AFVihfuRCS5H3XPJH/6HPM=
github.com/consensys/gnark-crypto v0.7.0 h1:rwdy8+ssmLYRqKp+ryRRgQJl/rCq2uv+n83cOydm5UE=
github.com/consensys/gnark-crypto v0.7.0/go.mod h1:KPSuJzyxkJA8xZ/+CV47tyqkr9MmpZA3PXivK4VPrVg=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ=
github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
github.com/consensys/gnark v0.8.0 h1:0bQ2MyDG4oNjMQpNyL8HjrrUSSL3yYJg0Elzo6LzmcU=
github.com/consensys/gnark v0.8.0/go.mod h1:aKmA7dIiLbTm0OV37xTq0z+Bpe4xER8EhRLi6necrm8=
github.com/consensys/gnark-crypto v0.9.1 h1:mru55qKdWl3E035hAoh1jj9d7hVnYY5pfb6tmovSmII=
github.com/consensys/gnark-crypto v0.9.1/go.mod h1:a2DQL4+5ywF6safEeZFEPGRiiGbjzGFRUN2sg06VuU4=
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=


@@ 15,6 19,9 @@ github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo
github.com/gdamore/tcell/v2 v2.6.0 h1:OKbluoP9VYmJwZwq/iLb4BxwKcwGthaa1YNBJIyCySg=
github.com/gdamore/tcell/v2 v2.6.0/go.mod h1:be9omFATkdr0D9qewWW3d+MEvl5dha+Etb5y65J2H8Y=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 h1:4/hN5RUoecvl+RmJRE2YxKWtnnQls6rQjjW5oV7qg2U=
github.com/google/pprof v0.0.0-20230207041349-798e818bf904/go.mod h1:uglQLonpP8qtYCYyzA+8c/9qtqgA3qsXGYqCPKARAFg=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=


@@ 104,3 111,5 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
maunium.net/go/mautrix v0.13.0 h1:CRdpMFc1kDSNnCZMcqahR9/pkDy/vgRbd+fHnSCl6Yg=
maunium.net/go/mautrix v0.13.0/go.mod h1:gYMQPsZ9lQpyKlVp+DGwOuc9LIcE/c8GZW2CvKHISgM=
rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU=
rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA=

M math/poly.go => math/poly.go +4 -3
@@ 10,6 10,7 @@ import (
	"github.com/consensys/gnark-crypto/ecc/bls12-381/fr/mimc"
	"github.com/consensys/gnark/backend/groth16"
	"github.com/consensys/gnark/backend/witness"
	"github.com/consensys/gnark/constraint"
	"github.com/consensys/gnark/frontend"
)



@@ 25,8 26,8 @@ type polyCache struct {
	ballotBits   []*fr.Element
	constant     *fr.Element
	outputHashes map[*fr.Element]outputCache
	r1cs         frontend.CompiledConstraintSystem
	witness      *witness.Witness
	r1cs         constraint.ConstraintSystem
	witness      witness.Witness
}

type outputCache struct {


@@ 117,7 118,7 @@ func (p *Poly) setupCache() {
	}

	var err error
	p.cache.witness, err = frontend.NewWitness(circuit, ecc.BLS12_381)
	p.cache.witness, err = frontend.NewWitness(circuit, ecc.BLS12_381.ScalarField())
	if err != nil {
		panic(fmt.Errorf("couldn't create witness: %w", err))
	}

M math/zk.go => math/zk.go +5 -4
@@ 6,6 6,7 @@ import (
	"errors"

	"github.com/consensys/gnark-crypto/ecc"
	"github.com/consensys/gnark/constraint"
	"github.com/consensys/gnark/frontend"
	"github.com/consensys/gnark/frontend/cs/r1cs"
	"github.com/consensys/gnark/std/hash/mimc"


@@ 71,13 72,13 @@ func (circuit *EvalsCircuit) Define(api frontend.API) error {
	return nil
}

func EvalsCircuitR1CS(numVoters int, numCandidates int) (frontend.CompiledConstraintSystem, error) {
func EvalsCircuitR1CS(numVoters int, numCandidates int) (constraint.ConstraintSystem, error) {
	var circuit EvalsCircuit
	circuit.Inputs = make([]frontend.Variable, numVoters)
	circuit.OutputHashes = make([]frontend.Variable, numVoters)
	circuit.BallotBits = make([]frontend.Variable, numCandidates*numCandidates)
	circuit.Coeffs = make([]frontend.Variable, numVoters-1)
	r1cs, err := frontend.Compile(ecc.BLS12_381, r1cs.NewBuilder, &circuit)
	r1cs, err := frontend.Compile(ecc.BLS12_381.ScalarField(), r1cs.NewBuilder, &circuit)
	if err != nil {
		return nil, err
	}


@@ 130,12 131,12 @@ func (circuit *SumCircuit) Define(api frontend.API) error {
	return nil
}

func SumCircuitR1CS(numVoters int) (frontend.CompiledConstraintSystem, error) {
func SumCircuitR1CS(numVoters int) (constraint.ConstraintSystem, error) {
	var circuit SumCircuit
	circuit.HashSelects = make([]frontend.Variable, numVoters)
	circuit.OutputHashes = make([]frontend.Variable, numVoters)
	circuit.Outputs = make([]frontend.Variable, numVoters)
	r1cs, err := frontend.Compile(ecc.BLS12_381, r1cs.NewBuilder, &circuit)
	r1cs, err := frontend.Compile(ecc.BLS12_381.ScalarField(), r1cs.NewBuilder, &circuit)
	if err != nil {
		return nil, err
	}