diff --git a/go.mod b/go.mod index b10e619..b442c5b 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,8 @@ module kzgceremony go 1.19 require ( - github.com/ethereum/go-ethereum v1.10.26 github.com/frankban/quicktest v1.14.4 + github.com/kilic/bls12-381 v0.1.0 ) require ( @@ -12,6 +12,5 @@ require ( github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect - golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect ) diff --git a/go.sum b/go.sum index dcdad52..7bfef31 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,10 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/ethereum/go-ethereum v1.10.26 h1:i/7d9RBBwiXCEuyduBQzJw/mKmnvzsN14jqBmytw72s= -github.com/ethereum/go-ethereum v1.10.26/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/kilic/bls12-381 v0.1.0 h1:encrdjqKMEvabVQ7qYOKu1OvhqpK4s47wDYtNiPtlp4= +github.com/kilic/bls12-381 v0.1.0/go.mod h1:vDTTHJONJ6G+P2R74EhnyotQDTliQDnFEwhdmfzw1ig= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -12,7 +12,6 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/sys v0.0.0-20201101102859-da207088b7d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/powersoftau.go b/powersoftau.go index ed61556..75cf3b2 100644 --- a/powersoftau.go +++ b/powersoftau.go @@ -1,10 +1,9 @@ package kzgceremony import ( - "fmt" "math/big" - "github.com/ethereum/go-ethereum/crypto/bls12381" + bls12381 "github.com/kilic/bls12-381" ) // todo: unify addition & multiplicative notation in the comments @@ -58,8 +57,9 @@ func tau(randomness []byte) *toxicWaste { tau := new(big.Int).Mod( new(big.Int).SetBytes(randomness), g2.Q()) + tau_Fr := bls12381.NewFr().FromBytes(tau.Bytes()) TauG2 := g2.New() - g2.MulScalar(TauG2, g2.One(), tau) + g2.MulScalar(TauG2, g2.One(), tau_Fr) return &toxicWaste{tau, TauG2} } @@ -70,15 +70,17 @@ func computeContribution(t *toxicWaste, prevSRS *SRS) *SRS { g2 := bls12381.NewG2() Q := g1.Q() // Q = |G1| == |G2| - fmt.Println("Computing [τ'⁰]₁, [τ'¹]₁, [τ'²]₁, ..., [τ'ⁿ⁻¹]₁, for n =", len(prevSRS.G1s)) + // fmt.Println("Computing [τ'⁰]₁, [τ'¹]₁, [τ'²]₁, ..., [τ'ⁿ⁻¹]₁, for n =", len(prevSRS.G1s)) for i := 0; i < len(prevSRS.G1s); i++ { tau_i := new(big.Int).Exp(t.tau, big.NewInt(int64(i)), Q) - g1.MulScalar(srs.G1s[i], prevSRS.G1s[i], tau_i) + tau_i_Fr := bls12381.NewFr().FromBytes(tau_i.Bytes()) + g1.MulScalar(srs.G1s[i], prevSRS.G1s[i], tau_i_Fr) } - fmt.Println("Computing [τ'⁰]₂, [τ'¹]₂, [τ'²]₂, ..., [τ'ⁿ⁻¹]₂, for n =", len(prevSRS.G2s)) + // fmt.Println("Computing [τ'⁰]₂, [τ'¹]₂, [τ'²]₂, ..., [τ'ⁿ⁻¹]₂, for n =", len(prevSRS.G2s)) for i := 0; i < len(prevSRS.G2s); i++ { tau_i := new(big.Int).Exp(t.tau, big.NewInt(int64(i)), Q) - g2.MulScalar(srs.G2s[i], prevSRS.G2s[i], tau_i) + tau_i_Fr := bls12381.NewFr().FromBytes(tau_i.Bytes()) + g2.MulScalar(srs.G2s[i], prevSRS.G2s[i], tau_i_Fr) } return srs @@ -87,7 +89,8 @@ func computeContribution(t *toxicWaste, prevSRS *SRS) *SRS { func genProof(toxicWaste *toxicWaste, prevSRS, newSRS *SRS) *Proof { g1 := bls12381.NewG1() G1_p := g1.New() - g1.MulScalar(G1_p, prevSRS.G1s[1], toxicWaste.tau) // g_1^{tau'} = g_1^{p * tau}, where p=toxicWaste.tau + tau_Fr := bls12381.NewFr().FromBytes(toxicWaste.tau.Bytes()) + g1.MulScalar(G1_p, prevSRS.G1s[1], tau_Fr) // g_1^{tau'} = g_1^{p * tau}, where p=toxicWaste.tau return &Proof{toxicWaste.TauG2, G1_p} } @@ -110,7 +113,7 @@ func Contribute(prevSRS *SRS, randomness []byte) (Contribution, error) { func Verify(prevSRS, newSRS *SRS, proof *Proof) bool { g1 := bls12381.NewG1() g2 := bls12381.NewG2() - pairing := bls12381.NewPairingEngine() + pairing := bls12381.NewEngine() // 1. check that elements of the newSRS are valid points for i := 0; i < len(newSRS.G1s); i++ {