diff --git a/homomorphic/add.go b/homomorphic/add.go index cfda373..fe1a2e2 100644 --- a/homomorphic/add.go +++ b/homomorphic/add.go @@ -1,4 +1,4 @@ -package hadd +package homomorphic import ( ecc_tweds "github.com/consensys/gnark-crypto/ecc/twistededwards" @@ -6,6 +6,11 @@ import ( "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 { @@ -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 +} diff --git a/homomorphic/add_test.go b/homomorphic/add_test.go index 0b1e252..564e82d 100644 --- a/homomorphic/add_test.go +++ b/homomorphic/add_test.go @@ -1,4 +1,4 @@ -package hadd +package homomorphic import ( "crypto/rand"