Skip to content

Commit b05a402

Browse files
committed
perf(stark-curve/perdersen-hash): use Strauss-Shamir scalarMul
1 parent 6bf593d commit b05a402

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

ecc/stark-curve/pedersen-hash/pedersen_hash.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,14 @@ func Pedersen(a *fp.Element, b *fp.Element) *fp.Element {
7272
}
7373

7474
func processElement(a *fp.Element, p1 *starkcurve.G1Jac, p2 *starkcurve.G1Jac) *starkcurve.G1Jac {
75-
var bigInt big.Int
76-
var aBytes [32]byte
77-
a.BigInt(&bigInt).FillBytes(aBytes[:])
75+
var lowPart, highPart big.Int
76+
aBytes := a.Bytes()
7877

79-
highPart := bigInt.SetUint64(uint64(aBytes[0])) // The top nibble (bits 249-252)
80-
lowPart := aBytes[1:] // Zero-out the top nibble (bits 249-252)
78+
highPart.SetUint64(uint64(aBytes[0])) // The top nibble (bits 249-252)
79+
lowPart.SetBytes(aBytes[1:32])
8180

82-
m := new(starkcurve.G1Jac).ScalarMultiplication(p2, highPart)
81+
var sum starkcurve.G1Jac
82+
sum.JointScalarMultiplication(p1, p2, &lowPart, &highPart)
8383

84-
var n starkcurve.G1Jac
85-
n.ScalarMultiplication(p1, bigInt.SetBytes(lowPart))
86-
return m.AddAssign(&n)
84+
return &sum
8785
}

0 commit comments

Comments
 (0)