@@ -845,15 +845,46 @@ impl Pairing {
845
845
script_lines. push ( Fq2 :: copy ( 2 ) ) ;
846
846
script_lines. push ( Fq2 :: copy ( 2 ) ) ;
847
847
// [beta_12(2), beta_13(2), beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), c(12), c_inv(12), wi(12), T4(4), T4(4) | f(12)]
848
+
849
+ // -- push c3,c4 to stack
850
+ script_lines. push ( fq2_push_not_montgomery ( line_coeffs[ num_lines - ( i + 2 ) ] [ j] [ 0 ] . 1 ) ) ;
851
+ script_lines. push ( fq2_push_not_montgomery ( line_coeffs[ num_lines - ( i + 2 ) ] [ j] [ 0 ] . 2 ) ) ;
852
+ // [...T4(4),T4(4),C3(2),C4(2)]
853
+ // -- move t4 to stack top
854
+ script_lines. push ( Fq2 :: roll ( 6 ) ) ;
855
+ script_lines. push ( Fq2 :: roll ( 6 ) ) ;
856
+ // -- [...T4(4),C3(2),C4(2),T4(4)]
848
857
script_lines. push ( scripts_iter. next ( ) . unwrap ( ) ) ; // check_tangent_line(line_coeffs[num_lines - (i + 2)][j][0].1, line_coeffs[num_lines - (i + 2)][j][0].2)
849
858
// [beta_12(2), beta_13(2), beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), c(12), c_inv(12), wi(12), T4(4) | f(12)]
850
859
860
+ // -- [...T4(4),c3(2),c4(2)]
861
+ // -- move c3,c4 to alt stack
862
+ script_lines. push ( Fq2 :: toaltstack ( ) ) ;
863
+ script_lines. push ( Fq2 :: toaltstack ( ) ) ;
864
+ // -- [...T4(4), | c3(2),c4(2),f(12)]
865
+ //
851
866
// update T4
852
867
// drop T4.y, leave T4.x
853
868
script_lines. push ( Fq2 :: drop ( ) ) ;
869
+
870
+ // -- [...T4.x(2),| c3(2),c4(2),fq(12)]
871
+ // -- move c3 c4 to stack
872
+ script_lines. push ( Fq2 :: fromaltstack ( ) ) ;
873
+ script_lines. push ( Fq2 :: fromaltstack ( ) ) ;
874
+ // -- [...T4.x(2),c3(2),c4(2)|f(12)]
875
+ // -- move T4.x(2) to stack top
876
+ script_lines. push ( Fq2 :: roll ( 4 ) ) ;
877
+ // -- [...,c3(2),c4(2),T4.x(2)|f(12)]
854
878
// [beta_12(2), beta_13(2), beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), c(12), c_inv(12), wi(12), T4.x(2) | f(12)]
855
879
script_lines. push ( scripts_iter. next ( ) . unwrap ( ) ) ; // affine_double_line(line_coeffs[num_lines - (i + 2)][j][0].1, line_coeffs[num_lines - (i + 2)][j][0].2)
856
880
// [beta_12(2), beta_13(2), beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), c(12), c_inv(12), wi(12), T4(4) | f(12)]
881
+ // -- [...c3(2),c4(2),T4(4)|f(12)]
882
+ // -- drop c3,c4 [...T4(4)|f(12)]
883
+ script_lines. push ( Fq2 :: roll ( 6 ) ) ;
884
+ script_lines. push ( Fq2 :: roll ( 6 ) ) ;
885
+ script_lines. push ( Fq2 :: drop ( ) ) ;
886
+ script_lines. push ( Fq2 :: drop ( ) ) ;
887
+
857
888
script_lines. push ( Fq12 :: fromaltstack ( ) ) ;
858
889
// [beta_12(2), beta_13(2), beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), c(12), c_inv(12), wi(12), T4(4), f(12)]
859
890
}
@@ -887,18 +918,49 @@ impl Pairing {
887
918
if ark_bn254:: Config :: ATE_LOOP_COUNT [ i - 1 ] == -1 {
888
919
script_lines. push ( Fq2 :: neg ( 0 ) ) ;
889
920
}
921
+ // -- push c3,c4 to stack
922
+ script_lines. push ( fq2_push_not_montgomery ( line_coeffs[ num_lines - ( i + 2 ) ] [ j] [ 1 ] . 1 ) ) ;
923
+ script_lines. push ( fq2_push_not_montgomery ( line_coeffs[ num_lines - ( i + 2 ) ] [ j] [ 1 ] . 2 ) ) ;
924
+ // -- [...T4(4),Q4(4),c3(2),c4(2)|f(12)]
925
+ // -- move t4,q4 to stack top
926
+ script_lines. push ( Fq2 :: roll ( 10 ) ) ;
927
+ script_lines. push ( Fq2 :: roll ( 10 ) ) ;
928
+ script_lines. push ( Fq2 :: roll ( 10 ) ) ;
929
+ script_lines. push ( Fq2 :: roll ( 10 ) ) ;
930
+ // -- [...c3(2),c4(2),T4(4),Q4(4),|f(12)]
890
931
script_lines. push ( scripts_iter. next ( ) . unwrap ( ) ) ; // check_chord_line(line_coeffs[num_lines - (i + 2)][j][1].1, line_coeffs[num_lines - (i + 2)][j][1].2)
891
932
// [beta_12(2), beta_13(2), beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), c(12), c_inv(12), wi(12), T4(4) | f(12)]
892
933
934
+ // -- [...T4(4),c3(2),c4(2)|f(12)]
935
+ // -- move c3 c4 to altstack
936
+ script_lines. push ( Fq2 :: toaltstack ( ) ) ;
937
+ script_lines. push ( Fq2 :: toaltstack ( ) ) ;
938
+ // -- [...T4(4)|c3(2),c4(2),f(12)]
893
939
// update T4
894
940
// drop T4.y, leave T4.x
895
941
script_lines. push ( Fq2 :: drop ( ) ) ;
896
942
// [beta_12(2), beta_13(2), beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), c(12), c_inv(12), wi(12), T4.x(2) | f(12)]
897
943
// copy Q4.x
898
944
script_lines. push ( Fq2 :: copy ( 4 + 36 ) ) ;
899
945
// [beta_12(2), beta_13(2), beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), c(12), c_inv(12), wi(12), T4.x(2), Q4.x(2) | f(12)]
946
+
947
+ // -- move c3,c4 to stack
948
+ script_lines. push ( Fq2 :: fromaltstack ( ) ) ;
949
+ script_lines. push ( Fq2 :: fromaltstack ( ) ) ;
950
+ // -- [...T4.x(2), Q4.x(2),c3(2),c4(2) | f(12)]
951
+ // -- move t4.x,q4.x to stack top
952
+ script_lines. push ( Fq2 :: roll ( 6 ) ) ;
953
+ script_lines. push ( Fq2 :: roll ( 6 ) ) ;
954
+ // -- [...,c3(2),c4(2),T4.x(2), Q4.x(2) | f(12)]
900
955
script_lines. push ( scripts_iter. next ( ) . unwrap ( ) ) ; // affine_add_line(line_coeffs[num_lines - (i + 2)][j][1].1, line_coeffs[num_lines - (i + 2)][j][1].2)
901
956
// [beta_12(2), beta_13(2), beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), c(12), c_inv(12), wi(12), T4(4) | f(12)]
957
+ // -- [... c3(2),c4(2),T4(4)|f(12)]
958
+ // -- drop c3,c4 [... T4(4)|f(12)]
959
+ script_lines. push ( Fq2 :: roll ( 6 ) ) ;
960
+ script_lines. push ( Fq2 :: roll ( 6 ) ) ;
961
+ script_lines. push ( Fq2 :: drop ( ) ) ;
962
+ script_lines. push ( Fq2 :: drop ( ) ) ;
963
+
902
964
script_lines. push ( Fq12 :: fromaltstack ( ) ) ;
903
965
// [beta_12(2), beta_13(2), beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), c(12), c_inv(12), wi(12), T4(4), f(12)]
904
966
}
@@ -977,9 +1039,25 @@ impl Pairing {
977
1039
script_lines. push ( Fq2 :: copy ( 6 ) ) ;
978
1040
script_lines. push ( Fq2 :: copy ( 6 ) ) ;
979
1041
// [beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), T4(4), phi(Q4)(4), T4(4), phi(Q4)(4) | f(12)]
1042
+
1043
+ // -- [...T4(4),Q4(4), T4(4),Q4(4)|f(12)]
1044
+ // -- push c3,c4 to stack
1045
+ script_lines. push ( fq2_push_not_montgomery ( line_coeffs[ num_lines - 2 ] [ j] [ 0 ] . 1 ) ) ;
1046
+ script_lines. push ( fq2_push_not_montgomery ( line_coeffs[ num_lines - 2 ] [ j] [ 0 ] . 2 ) ) ;
1047
+ // -- [... T4(4),Q4(4),T4(4),Q4(4),c3(2),c4(2)|f(12)]
1048
+ // -- move T4,Q4 to stack top
1049
+ script_lines. push ( Fq2 :: roll ( 10 ) ) ;
1050
+ script_lines. push ( Fq2 :: roll ( 10 ) ) ;
1051
+ script_lines. push ( Fq2 :: roll ( 10 ) ) ;
1052
+ script_lines. push ( Fq2 :: roll ( 10 ) ) ;
1053
+ // -- [... T4(4),Q4(4),c3(2),c4(2),T4(4),Q4(4),|f(12)]
980
1054
script_lines. push ( scripts_iter. next ( ) . unwrap ( ) ) ; // check_chord_line(line_coeffs[num_lines - 2][j][0].1, line_coeffs[num_lines - 2][j][0].2)
981
1055
// [beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), T4(4), phi(Q4)(4) | f(12)]
982
-
1056
+ // -- [... T4(4),Q4(4),c3(2),c4(2)|f(12)]
1057
+ // -- move c3,c4 to altstack
1058
+ script_lines. push ( Fq2 :: toaltstack ( ) ) ;
1059
+ script_lines. push ( Fq2 :: toaltstack ( ) ) ;
1060
+ // -- [... T4(4),Q4(4)|,c3(2),c4(2),f(12)]
983
1061
// update T4
984
1062
script_lines. push ( Fq2 :: drop ( ) ) ;
985
1063
// [beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), T4(4), phi(Q4).x(2) | f(12)]
@@ -989,8 +1067,23 @@ impl Pairing {
989
1067
// [beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), T4.x(2) | phi(Q4).x(2), f(12)]
990
1068
script_lines. push ( Fq2 :: fromaltstack ( ) ) ;
991
1069
// [beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), T4.x(2), phi(Q4).x(2) | f(12)]
1070
+ // -- move c3,c4 to stack
1071
+ script_lines. push ( Fq2 :: fromaltstack ( ) ) ;
1072
+ script_lines. push ( Fq2 :: fromaltstack ( ) ) ;
1073
+ // -- [... T4.x(2), phi(Q4).x(2) ,c3(2),c4(2)|f(12)]
1074
+ // -- move T4.x Q4.x to stack top
1075
+ script_lines. push ( Fq2 :: roll ( 6 ) ) ; // [... phi(Q4).x(2) ,c3(2),c4(2),T4.x(2), |f(12)]
1076
+ script_lines. push ( Fq2 :: roll ( 6 ) ) ;
1077
+ // -- [... ,c3(2),c4(2), T4.x(2), phi(Q4).x(2) |f(12)]
992
1078
script_lines. push ( scripts_iter. next ( ) . unwrap ( ) ) ; // affine_add_line(line_coeffs[num_lines - 2][j][0].1, line_coeffs[num_lines - 2][j][0].2)
993
1079
// [beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), T4(4) | f(12)]
1080
+ // -- [...c3(2),c4(2),T4(4)|f(12)]
1081
+ // -- drop c3,c4
1082
+ script_lines. push ( Fq2 :: roll ( 6 ) ) ;
1083
+ script_lines. push ( Fq2 :: roll ( 6 ) ) ;
1084
+ script_lines. push ( Fq2 :: drop ( ) ) ;
1085
+ script_lines. push ( Fq2 :: drop ( ) ) ;
1086
+ // -- [...,T4(4)|f(12)]
994
1087
script_lines. push ( Fq12 :: fromaltstack ( ) ) ;
995
1088
// [beta_22(2), P1(2), P2(2), P3(2), P4(2), Q4(4), T4(4), f(12)]
996
1089
}
@@ -1020,9 +1113,24 @@ impl Pairing {
1020
1113
// phi(Q4)^2 = (Q4.x', Qy)
1021
1114
// [T4(4), phi(Q4)^2(4) | f(12)]
1022
1115
1116
+ // -- push c3,c4 to stack
1117
+ script_lines. push ( fq2_push_not_montgomery ( line_coeffs[ num_lines - 1 ] [ j] [ 0 ] . 1 ) ) ;
1118
+ script_lines. push ( fq2_push_not_montgomery ( line_coeffs[ num_lines - 1 ] [ j] [ 0 ] . 2 ) ) ;
1119
+ // [T4.x(2),T4.y(2),Q4.x(2),Q4.y(2),c3(2),c4(2)|f(12)]
1120
+ // -- move T4,Q4 to stack top
1121
+ script_lines. push ( Fq2 :: roll ( 10 ) ) ; // [T4.y(2),Q4.x(2),Q4.y(2),c3(2),c4(2),T4.x(2),|f(12)]
1122
+ script_lines. push ( Fq2 :: roll ( 10 ) ) ; // [Q4.x(2),Q4.y(2),c3(2),c4(2),T4.x(2),T4.y(2),|f(12)]
1123
+ script_lines. push ( Fq2 :: roll ( 10 ) ) ; // [Q4.y(2),c3(2),c4(2),T4.x(2),T4.y(2),Q4.x(2),|f(12)]
1124
+ script_lines. push ( Fq2 :: roll ( 10 ) ) ; // [c3(2),c4(2),T4.x(2),T4.y(2),Q4.x(2),Q4.y(2),|f(12)]
1125
+ // -- [c3(2),c4(2),T4(4),Q4.x(2),Q4.y(2)|f(12)]
1023
1126
// check whether the chord line through T4 and phi(Q4)^2
1024
1127
script_lines. push ( scripts_iter. next ( ) . unwrap ( ) ) ; // check_chord_line(line_coeffs[num_lines - 1][j][0].1, line_coeffs[num_lines - 1][j][0].2)
1025
1128
// [ | f(12)]
1129
+ // -- [c3(2),c4(2)|f(12)]
1130
+ // -- drop c3,c4
1131
+ script_lines. push ( Fq2 :: drop ( ) ) ; //[c3(2)|f(12)]
1132
+ script_lines. push ( Fq2 :: drop ( ) ) ; //[|f(12)]
1133
+ // -- [|f(12)]
1026
1134
script_lines. push ( Fq12 :: fromaltstack ( ) ) ;
1027
1135
// [f(12)]
1028
1136
}
@@ -1380,7 +1488,7 @@ mod test {
1380
1488
1381
1489
{ quad_miller_loop_affine_script }
1382
1490
1383
- { fq12_push_not_montgomery( hint ) }
1491
+ { fq12_push_not_montgomery( ark_bn254 :: Fq12 :: ONE ) }
1384
1492
1385
1493
{ Fq12 :: equalverify( ) }
1386
1494
0 commit comments