Skip to content

Commit

Permalink
homomorphic: fix package name, add new method AddPair
Browse files Browse the repository at this point in the history
  • Loading branch information
altergui committed Dec 4, 2024
1 parent cc4388f commit 27abd21
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion homomorphic/add.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package hadd
package homomorphic

import (
ecc_tweds "github.com/consensys/gnark-crypto/ecc/twistededwards"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/std/algebra/native/twistededwards"
)

type Pair struct {
P1 twistededwards.Point
P2 twistededwards.Point
}

func Add(api frontend.API, a, b twistededwards.Point) (twistededwards.Point, error) {
curve, err := twistededwards.NewEdCurve(api, ecc_tweds.BN254)
if err != nil {
Expand All @@ -15,3 +20,18 @@ func Add(api frontend.API, a, b twistededwards.Point) (twistededwards.Point, err
curve.AssertIsOnCurve(b)
return curve.Add(a, b), nil
}

// AddPair returns the result (a.P1 + b.P1), (a.P2, b.P2) as a Pair
func AddPair(api frontend.API, a, b Pair) (Pair, error) {
curve, err := twistededwards.NewEdCurve(api, ecc_tweds.BN254)
if err != nil {
return Pair{}, err
}
for _, p := range []twistededwards.Point{a.P1, a.P2, b.P1, b.P2} {
curve.AssertIsOnCurve(p)
}
return Pair{
curve.Add(a.P1, b.P1),
curve.Add(a.P2, b.P2),
}, nil
}
2 changes: 1 addition & 1 deletion homomorphic/add_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hadd
package homomorphic

import (
"crypto/rand"
Expand Down

0 comments on commit 27abd21

Please sign in to comment.