Skip to content

Commit

Permalink
faster Mul01By01
Browse files Browse the repository at this point in the history
  • Loading branch information
shramee committed Mar 8, 2024
1 parent 1ed22f7 commit 2845b9b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
11 changes: 2 additions & 9 deletions std/algebra/emulated/fields_bn254/e6.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,22 +230,15 @@ func (e Ext6) MulBy01(z *E6, c0, c1 *E2) *E6 {
func (e Ext6) Mul01By01(c0, c1, d0, d1 *E2) *E6 {
a := e.Ext2.Mul(d0, c0)
b := e.Ext2.Mul(d1, c1)
t0 := e.Ext2.Mul(c1, d1)
t0 = e.Ext2.Sub(t0, b)
t0 = e.Ext2.MulByNonResidue(t0)
t0 = e.Ext2.Add(t0, a)
t2 := e.Ext2.Mul(c0, d0)
t2 = e.Ext2.Sub(t2, a)
t2 = e.Ext2.Add(t2, b)
t1 := e.Ext2.Add(c0, c1)
tmp := e.Ext2.Add(d0, d1)
t1 = e.Ext2.Mul(t1, tmp)
t1 = e.Ext2.Sub(t1, a)
t1 = e.Ext2.Sub(t1, b)
return &E6{
B0: *t0,
B0: *a,
B1: *t1,
B2: *t2,
B2: *b,
}
}

Expand Down
11 changes: 2 additions & 9 deletions std/algebra/emulated/fields_bw6761/e3.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,22 +235,15 @@ func (e Ext3) MulBy12(x *E3, b1, b2 *baseEl) *E3 {
func (e Ext3) Mul01By01(c0, c1, d0, d1 *baseEl) *E3 {
a := e.fp.Mul(d0, c0)
b := e.fp.Mul(d1, c1)
t0 := e.fp.Mul(c1, d1)
t0 = e.fp.Sub(b, t0)
t0 = e.fp.MulConst(t0, big.NewInt(4))
t0 = e.fp.Add(t0, a)
t2 := e.fp.Mul(c0, d0)
t2 = e.fp.Sub(t2, a)
t2 = e.fp.Add(t2, b)
t1 := e.fp.Add(c0, c1)
tmp := e.fp.Add(d0, d1)
t1 = e.fp.Mul(t1, tmp)
t1 = e.fp.Sub(t1, a)
t1 = e.fp.Sub(t1, b)
return &E3{
A0: *t0,
A0: *a,
A1: *t1,
A2: *t2,
A2: *b,
}
}

Expand Down
13 changes: 3 additions & 10 deletions std/algebra/native/fields_bls12377/e6.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,27 +280,20 @@ func (e *E6) MulBy01(api frontend.API, c0, c1 E2) *E6 {
}

func Mul01By01(api frontend.API, c0, c1, d0, d1 E2) *E6 {
var a, b, t0, t1, t2, tmp E2
var a, b, t1, tmp E2

a.Mul(api, d0, c0)
b.Mul(api, d1, c1)
t0.Mul(api, c1, d1)
t0.Sub(api, t0, b)
t0.MulByNonResidue(api, t0)
t0.Add(api, t0, a)
t2.Mul(api, c0, d0)
t2.Sub(api, t2, a)
t2.Add(api, t2, b)
t1.Add(api, c0, c1)
tmp.Add(api, d0, d1)
t1.Mul(api, t1, tmp)
t1.Sub(api, t1, a)
t1.Sub(api, t1, b)

return &E6{
B0: t0,
B0: a,
B1: t1,
B2: t2,
B2: b,
}
}

Expand Down

0 comments on commit 2845b9b

Please sign in to comment.