Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync develop to master #69

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
on: [ push, pull_request ]
name: Test
on:
push:
branches:
- main
pull_request:
jobs:
test:
strategy:
matrix:
go-version: [ 1.18.x, 1.19.x, 1.20.x ]
go-version: [ 1.20.x, 1.21.x, 1.22.x , 1.23.x ]
goarch: [ "amd64", "386" ]
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Go implementation of some cryptographic primitives (that fit inside the SNARK fi
* Poseidon hash for BN254
* Poseidon hash for Goldilocks
* MIMC7
* Pedersen

## Contributing

Expand Down
16 changes: 8 additions & 8 deletions babyjub/babyjub.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"math/big"

"github.com/iden3/go-iden3-crypto/constants"
"github.com/iden3/go-iden3-crypto/ff"
"github.com/iden3/go-iden3-crypto/utils"
"github.com/iden3/go-iden3-crypto/v2/constants"
"github.com/iden3/go-iden3-crypto/v2/ff"
"github.com/iden3/go-iden3-crypto/v2/utils"
)

// A is one of the babyjub constants.
Expand Down Expand Up @@ -34,19 +34,19 @@ var B8 *Point

// init initializes global numbers and the subgroup base.
func init() {
A = utils.NewIntFromString("168700")
D = utils.NewIntFromString("168696")
A, _ = utils.NewIntFromString("168700")
D, _ = utils.NewIntFromString("168696")
Aff = ff.NewElement().SetBigInt(A)
Dff = ff.NewElement().SetBigInt(D)

Order = utils.NewIntFromString(
Order, _ = utils.NewIntFromString(
"21888242871839275222246405745257275088614511777268538073601725287587578984328")
SubOrder = new(big.Int).Rsh(Order, 3) //nolint:gomnd

B8 = NewPoint()
B8.X = utils.NewIntFromString(
B8.X, _ = utils.NewIntFromString(
"5299619240641551281634865583518297030282874472190772894086521144482721001553")
B8.Y = utils.NewIntFromString(
B8.Y, _ = utils.NewIntFromString(
"16950150798460657717958625567821834550301663161624707787222815936182638968203")
}

Expand Down
82 changes: 41 additions & 41 deletions babyjub/babyjub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"math/rand"
"testing"

"github.com/iden3/go-iden3-crypto/constants"
"github.com/iden3/go-iden3-crypto/utils"
"github.com/iden3/go-iden3-crypto/v2/constants"
"github.com/iden3/go-iden3-crypto/v2/utils"
"github.com/stretchr/testify/assert"
)

Expand All @@ -22,15 +22,15 @@ func TestAdd1(t *testing.T) {
}

func TestAdd2(t *testing.T) {
aX := utils.NewIntFromString(
aX, _ := utils.NewIntFromString(
"17777552123799933955779906779655732241715742912184938656739573121738514868268")
aY := utils.NewIntFromString(
aY, _ := utils.NewIntFromString(
"2626589144620713026669568689430873010625803728049924121243784502389097019475")
a := &Point{X: aX, Y: aY}

bX := utils.NewIntFromString(
bX, _ := utils.NewIntFromString(
"17777552123799933955779906779655732241715742912184938656739573121738514868268")
bY := utils.NewIntFromString(
bY, _ := utils.NewIntFromString(
"2626589144620713026669568689430873010625803728049924121243784502389097019475")
b := &Point{X: bX, Y: bY}

Expand All @@ -57,15 +57,15 @@ func TestAdd2(t *testing.T) {
}

func TestAdd3(t *testing.T) {
aX := utils.NewIntFromString(
aX, _ := utils.NewIntFromString(
"17777552123799933955779906779655732241715742912184938656739573121738514868268")
aY := utils.NewIntFromString(
aY, _ := utils.NewIntFromString(
"2626589144620713026669568689430873010625803728049924121243784502389097019475")
a := &Point{X: aX, Y: aY}

bX := utils.NewIntFromString(
bX, _ := utils.NewIntFromString(
"16540640123574156134436876038791482806971768689494387082833631921987005038935")
bY := utils.NewIntFromString(
bY, _ := utils.NewIntFromString(
"20819045374670962167435360035096875258406992893633759881276124905556507972311")
b := &Point{X: bX, Y: bY}

Expand All @@ -80,15 +80,15 @@ func TestAdd3(t *testing.T) {
}

func TestAdd4(t *testing.T) {
aX := utils.NewIntFromString(
aX, _ := utils.NewIntFromString(
"0")
aY := utils.NewIntFromString(
aY, _ := utils.NewIntFromString(
"1")
a := &Point{X: aX, Y: aY}

bX := utils.NewIntFromString(
bX, _ := utils.NewIntFromString(
"16540640123574156134436876038791482806971768689494387082833631921987005038935")
bY := utils.NewIntFromString(
bY, _ := utils.NewIntFromString(
"20819045374670962167435360035096875258406992893633759881276124905556507972311")
b := &Point{X: bX, Y: bY}

Expand All @@ -113,12 +113,12 @@ func TestInCurve2(t *testing.T) {
}

func TestMul0(t *testing.T) {
x := utils.NewIntFromString(
x, _ := utils.NewIntFromString(
"17777552123799933955779906779655732241715742912184938656739573121738514868268")
y := utils.NewIntFromString(
y, _ := utils.NewIntFromString(
"2626589144620713026669568689430873010625803728049924121243784502389097019475")
p := &Point{X: x, Y: y}
s := utils.NewIntFromString("3")
s, _ := utils.NewIntFromString("3")

r2 := NewPoint().Projective().Add(p.Projective(), p.Projective()).Affine()
r2 = NewPoint().Projective().Add(r2.Projective(), p.Projective()).Affine()
Expand All @@ -135,12 +135,12 @@ func TestMul0(t *testing.T) {
}

func TestMul1(t *testing.T) {
x := utils.NewIntFromString(
x, _ := utils.NewIntFromString(
"17777552123799933955779906779655732241715742912184938656739573121738514868268")
y := utils.NewIntFromString(
y, _ := utils.NewIntFromString(
"2626589144620713026669568689430873010625803728049924121243784502389097019475")
p := &Point{X: x, Y: y}
s := utils.NewIntFromString(
s, _ := utils.NewIntFromString(
"14035240266687799601661095864649209771790948434046947201833777492504781204499")
r := NewPoint().Mul(s, p)
assert.Equal(t,
Expand All @@ -152,12 +152,12 @@ func TestMul1(t *testing.T) {
}

func TestMul2(t *testing.T) {
x := utils.NewIntFromString(
x, _ := utils.NewIntFromString(
"6890855772600357754907169075114257697580319025794532037257385534741338397365")
y := utils.NewIntFromString(
y, _ := utils.NewIntFromString(
"4338620300185947561074059802482547481416142213883829469920100239455078257889")
p := &Point{X: x, Y: y}
s := utils.NewIntFromString(
s, _ := utils.NewIntFromString(
"20819045374670962167435360035096875258406992893633759881276124905556507972311")
r := NewPoint().Mul(s, p)
assert.Equal(t,
Expand All @@ -169,45 +169,45 @@ func TestMul2(t *testing.T) {
}

func TestInCurve3(t *testing.T) {
x := utils.NewIntFromString(
x, _ := utils.NewIntFromString(
"17777552123799933955779906779655732241715742912184938656739573121738514868268")
y := utils.NewIntFromString(
y, _ := utils.NewIntFromString(
"2626589144620713026669568689430873010625803728049924121243784502389097019475")
p := &Point{X: x, Y: y}
assert.Equal(t, true, p.InCurve())
}

func TestInCurve4(t *testing.T) {
x := utils.NewIntFromString(
x, _ := utils.NewIntFromString(
"6890855772600357754907169075114257697580319025794532037257385534741338397365")
y := utils.NewIntFromString(
y, _ := utils.NewIntFromString(
"4338620300185947561074059802482547481416142213883829469920100239455078257889")
p := &Point{X: x, Y: y}
assert.Equal(t, true, p.InCurve())
}

func TestInSubGroup1(t *testing.T) {
x := utils.NewIntFromString(
x, _ := utils.NewIntFromString(
"17777552123799933955779906779655732241715742912184938656739573121738514868268")
y := utils.NewIntFromString(
y, _ := utils.NewIntFromString(
"2626589144620713026669568689430873010625803728049924121243784502389097019475")
p := &Point{X: x, Y: y}
assert.Equal(t, true, p.InSubGroup())
}

func TestInSubGroup2(t *testing.T) {
x := utils.NewIntFromString(
x, _ := utils.NewIntFromString(
"6890855772600357754907169075114257697580319025794532037257385534741338397365")
y := utils.NewIntFromString(
y, _ := utils.NewIntFromString(
"4338620300185947561074059802482547481416142213883829469920100239455078257889")
p := &Point{X: x, Y: y}
assert.Equal(t, true, p.InSubGroup())
}

func TestPointFromSignAndy(t *testing.T) {
x := utils.NewIntFromString(
x, _ := utils.NewIntFromString(
"17777552123799933955779906779655732241715742912184938656739573121738514868268")
y := utils.NewIntFromString(
y, _ := utils.NewIntFromString(
"2626589144620713026669568689430873010625803728049924121243784502389097019475")
p := &Point{X: x, Y: y}

Expand All @@ -219,9 +219,9 @@ func TestPointFromSignAndy(t *testing.T) {
}

func TestPackAndUnpackSignY(t *testing.T) {
x := utils.NewIntFromString(
x, _ := utils.NewIntFromString(
"17777552123799933955779906779655732241715742912184938656739573121738514868268")
y := utils.NewIntFromString(
y, _ := utils.NewIntFromString(
"2626589144620713026669568689430873010625803728049924121243784502389097019475")
p := &Point{X: x, Y: y}
pComp := p.Compress()
Expand All @@ -239,9 +239,9 @@ func TestPackAndUnpackSignY(t *testing.T) {
}

func TestCompressDecompress1(t *testing.T) {
x := utils.NewIntFromString(
x, _ := utils.NewIntFromString(
"17777552123799933955779906779655732241715742912184938656739573121738514868268")
y := utils.NewIntFromString(
y, _ := utils.NewIntFromString(
"2626589144620713026669568689430873010625803728049924121243784502389097019475")
p := &Point{X: x, Y: y}

Expand All @@ -257,9 +257,9 @@ func TestCompressDecompress1(t *testing.T) {
}

func TestCompressDecompress2(t *testing.T) {
x := utils.NewIntFromString(
x, _ := utils.NewIntFromString(
"6890855772600357754907169075114257697580319025794532037257385534741338397365")
y := utils.NewIntFromString(
y, _ := utils.NewIntFromString(
"4338620300185947561074059802482547481416142213883829469920100239455078257889")
p := &Point{X: x, Y: y}

Expand Down Expand Up @@ -299,9 +299,9 @@ func BenchmarkBabyjub(b *testing.B) {

var points [n]*Point
var pointsProj [n]*PointProjective
baseX := utils.NewIntFromString(
baseX, _ := utils.NewIntFromString(
"17777552123799933955779906779655732241715742912184938656739573121738514868268")
baseY := utils.NewIntFromString(
baseY, _ := utils.NewIntFromString(
"2626589144620713026669568689430873010625803728049924121243784502389097019475")
base := &Point{X: baseX, Y: baseY}
for i := 0; i < n; i++ {
Expand Down
81 changes: 0 additions & 81 deletions babyjub/babyjub_wrapper.go

This file was deleted.

Loading
Loading