iden3 / go-iden3-crypto

Go implementation of some cryptographic primitives (that fit inside the SNARK field) and compatible with circomlib
Apache License 2.0
117 stars 38 forks source link

Update to goff v0.2.0 #19

Closed arnaucube closed 4 years ago

arnaucube commented 4 years ago

Update to goff v0.2.0 https://github.com/ConsenSys/goff/pull/13

benchmark                                  old ns/op     new ns/op     delta
BenchmarkBabyjub/AddConst-4                1363          1366          +0.22%
BenchmarkBabyjub/AddRnd-4                  16023         15888         -0.84%
BenchmarkBabyjub/MulRnd-4                  6025374       6054802       +0.49%
BenchmarkBabyjub/Compress-4                212           214           +0.94%
BenchmarkBabyjub/InCurve-4                 2485          2465          -0.80%
BenchmarkBabyjub/InSubGroup-4              2499          2477          -0.88%
BenchmarkBabyjubEddsa/SignMimc7-4          12048929      12115278      +0.55%
BenchmarkBabyjubEddsa/VerifyMimc7-4        12120261      12116330      -0.03%
BenchmarkBabyjubEddsa/SignPoseidon-4       12111692      12167928      +0.46%
BenchmarkBabyjubEddsa/VerifyPoseidon-4     12159735      12211645      +0.43%
BenchmarkMul-4                             30.9          29.7          -3.88%
BenchmarkInverseELEMENT-4                  2727          2980          +9.28%
BenchmarkExpELEMENT-4                      2855          2877          +0.77%
BenchmarkDoubleELEMENT-4                   10.1          9.29          -8.02%
BenchmarkAddELEMENT-4                      5.04          5.82          +15.48%
BenchmarkSubELEMENT-4                      5.59          5.62          +0.54%
BenchmarkNegELEMENT-4                      3.70          3.68          -0.54%
BenchmarkDivELEMENT-4                      2674          3050          +14.06%
BenchmarkFromMontELEMENT-4                 21.7          21.8          +0.46%
BenchmarkToMontELEMENT-4                   30.2          25.3          -16.23%
BenchmarkSquareELEMENT-4                   25.8          27.7          +7.36%
BenchmarkMulAssignELEMENT-4                29.1          23.8          -18.21%
BenchmarkMIMC7-4                           61667         63289         +2.63%
BenchmarkPoseidon-4                        122522        115091        -6.07%
BenchmarkPoseidonLarge-4                   121598        115560        -4.97%
ed255 commented 4 years ago

Tests in 32 bits are not being run in Travis due to a bug (#20) so I tested it locally:

 $ GOARCH=386 go test ./...
go build github.com/ethereum/go-ethereum/crypto/secp256k1: build constraints exclude all Go files in /home/dev/go/pkg/mod/github.com/ethereum/go-et
hereum@v1.8.27/crypto/secp256k1
# github.com/iden3/go-iden3-crypto/ff [github.com/iden3/go-iden3-crypto/ff.test]
ff/element_test.go:306:3: undefined: MulAssignElement
FAIL    github.com/iden3/go-iden3-crypto/babyjub [build failed]
?       github.com/iden3/go-iden3-crypto/constants      [no test files]
FAIL    github.com/iden3/go-iden3-crypto/ff [build failed]
FAIL    github.com/iden3/go-iden3-crypto/mimc7 [build failed]
panic: runtime error: index out of range [4] with length 4

goroutine 1 [running]:
github.com/iden3/go-iden3-crypto/ff.(*Element).SetBigInt(0x901a4c0, 0x908ce68, 0x20)
        /home/dev/git/iden3/go-iden3-crypto/ff/element.go:614 +0x4a9
github.com/iden3/go-iden3-crypto/poseidon.getPseudoRandom(0x83032d6, 0x12, 0x41, 0xe15, 0x30, 0x54)
        /home/dev/git/iden3/go-iden3-crypto/poseidon/poseidon.go:40 +0x178
github.com/iden3/go-iden3-crypto/poseidon.init.0()
        /home/dev/git/iden3/go-iden3-crypto/poseidon/poseidon.go:31 +0x41
FAIL    github.com/iden3/go-iden3-crypto/poseidon       0.004s
?       github.com/iden3/go-iden3-crypto/utils  [no test files]
FAIL