@@ -101,21 +101,46 @@ impl ProjectivePoint {
101
101
{
102
102
// call when the values are normalized, into powdr ec operations
103
103
if self . z == FieldElement :: ONE && other. z == FieldElement :: ONE {
104
- // z being ONE means value is not identity
105
- let self_x: [ u8 ; 32 ] = self . x . to_bytes_le ( ) . into ( ) ;
106
- let self_y: [ u8 ; 32 ] = self . y . to_bytes_le ( ) . into ( ) ;
107
- let other_x: [ u8 ; 32 ] = other. x . to_bytes_le ( ) . into ( ) ;
108
- let other_y: [ u8 ; 32 ] = other. y . to_bytes_le ( ) . into ( ) ;
104
+ let mut combined_self: [ u8 ; 64 ] = [ 0 ; 64 ] ;
105
+ let mut combined_other: [ u8 ; 64 ] = [ 0 ; 64 ] ;
109
106
110
- let ( res_x, res_y) = if self_x == other_x && self_y == other_y {
111
- double_u8_le ( self_x, self_y)
107
+ // z being ONE means value is not identity
108
+ self . x . write_bytes_le (
109
+ ( & mut combined_self[ ..32 ] )
110
+ . try_into ( )
111
+ . expect ( "Expected 32 bytes" ) ,
112
+ ) ;
113
+ self . y . write_bytes_le (
114
+ ( & mut combined_self[ 32 ..] )
115
+ . try_into ( )
116
+ . expect ( "Expected 32 bytes" ) ,
117
+ ) ;
118
+
119
+ other. x . write_bytes_le (
120
+ ( & mut combined_other[ ..32 ] )
121
+ . try_into ( )
122
+ . expect ( "Expected 32 bytes" ) ,
123
+ ) ;
124
+ other. y . write_bytes_le (
125
+ ( & mut combined_other[ 32 ..] )
126
+ . try_into ( )
127
+ . expect ( "Expected 32 bytes" ) ,
128
+ ) ;
129
+
130
+ let result = if combined_self == combined_other {
131
+ double_u8_le ( combined_self)
112
132
} else {
113
- add_u8_le ( self_x , self_y , other_x , other_y )
133
+ add_u8_le ( combined_self , combined_other )
114
134
} ;
135
+ let ( res_x, res_y) = result. split_at ( 32 ) ;
115
136
116
137
let mut res = * self ;
117
- res. x = FieldElement :: from_bytes_unchecked_le ( & res_x) ;
118
- res. y = FieldElement :: from_bytes_unchecked_le ( & res_y) ;
138
+ res. x = FieldElement :: from_bytes_unchecked_le (
139
+ & res_x. try_into ( ) . expect ( "Expected 32 bytes" ) ,
140
+ ) ;
141
+ res. y = FieldElement :: from_bytes_unchecked_le (
142
+ & res_y. try_into ( ) . expect ( "Expected 32 bytes" ) ,
143
+ ) ;
119
144
return res;
120
145
}
121
146
@@ -203,21 +228,47 @@ impl ProjectivePoint {
203
228
if other. is_identity ( ) . into ( ) {
204
229
return * self ;
205
230
} else if self . z == FieldElement :: ONE {
206
- // z being ONE means value is not identity
207
- let self_x: [ u8 ; 32 ] = self . x . to_bytes_le ( ) . into ( ) ;
208
- let self_y: [ u8 ; 32 ] = self . y . to_bytes_le ( ) . into ( ) ;
209
- let other_x: [ u8 ; 32 ] = other. x . to_bytes_le ( ) . into ( ) ;
210
- let other_y: [ u8 ; 32 ] = other. y . to_bytes_le ( ) . into ( ) ;
231
+ let mut combined_self: [ u8 ; 64 ] = [ 0 ; 64 ] ;
232
+ let mut combined_other: [ u8 ; 64 ] = [ 0 ; 64 ] ;
211
233
212
- let ( res_x, res_y) = if self_x == other_x && self_y == other_y {
213
- double_u8_le ( self_x, self_y)
234
+ // z being ONE means value is not identity
235
+ self . x . write_bytes_le (
236
+ ( & mut combined_self[ ..32 ] )
237
+ . try_into ( )
238
+ . expect ( "Expected 32 bytes" ) ,
239
+ ) ;
240
+ self . y . write_bytes_le (
241
+ ( & mut combined_self[ 32 ..] )
242
+ . try_into ( )
243
+ . expect ( "Expected 32 bytes" ) ,
244
+ ) ;
245
+
246
+ other. x . write_bytes_le (
247
+ ( & mut combined_other[ ..32 ] )
248
+ . try_into ( )
249
+ . expect ( "Expected 32 bytes" ) ,
250
+ ) ;
251
+ other. y . write_bytes_le (
252
+ ( & mut combined_other[ 32 ..] )
253
+ . try_into ( )
254
+ . expect ( "Expected 32 bytes" ) ,
255
+ ) ;
256
+
257
+ let result = if combined_self == combined_other {
258
+ double_u8_le ( combined_self)
214
259
} else {
215
- add_u8_le ( self_x , self_y , other_x , other_y )
260
+ add_u8_le ( combined_self , combined_other )
216
261
} ;
217
262
263
+ let ( res_x, res_y) = result. split_at ( 32 ) ;
264
+
218
265
let mut res = * self ;
219
- res. x = FieldElement :: from_bytes_unchecked_le ( & res_x) ;
220
- res. y = FieldElement :: from_bytes_unchecked_le ( & res_y) ;
266
+ res. x = FieldElement :: from_bytes_unchecked_le (
267
+ & res_x. try_into ( ) . expect ( "Expected 32 bytes" ) ,
268
+ ) ;
269
+ res. y = FieldElement :: from_bytes_unchecked_le (
270
+ & res_y. try_into ( ) . expect ( "Expected 32 bytes" ) ,
271
+ ) ;
221
272
return res;
222
273
}
223
274
}
@@ -292,13 +343,30 @@ impl ProjectivePoint {
292
343
#[ cfg( all( target_os = "zkvm" , target_arch = "riscv32" ) ) ]
293
344
{
294
345
if self . z == FieldElement :: ONE {
346
+ let mut combined_self: [ u8 ; 64 ] = [ 0 ; 64 ] ;
347
+
295
348
// z being ONE means value is not identity
296
- let self_x: [ u8 ; 32 ] = self . x . to_bytes_le ( ) . into ( ) ;
297
- let self_y: [ u8 ; 32 ] = self . y . to_bytes_le ( ) . into ( ) ;
298
- let ( res_x, res_y) = double_u8_le ( self_x, self_y) ;
349
+ self . x . write_bytes_le (
350
+ ( & mut combined_self[ ..32 ] )
351
+ . try_into ( )
352
+ . expect ( "Expected 32 bytes" ) ,
353
+ ) ;
354
+ self . y . write_bytes_le (
355
+ ( & mut combined_self[ 32 ..] )
356
+ . try_into ( )
357
+ . expect ( "Expected 32 bytes" ) ,
358
+ ) ;
359
+
360
+ let result = double_u8_le ( combined_self) ;
361
+ let ( res_x, res_y) = result. split_at ( 32 ) ;
362
+
299
363
let mut res = * self ;
300
- res. x = FieldElement :: from_bytes_unchecked_le ( & res_x) ;
301
- res. y = FieldElement :: from_bytes_unchecked_le ( & res_y) ;
364
+ res. x = FieldElement :: from_bytes_unchecked_le (
365
+ & res_x. try_into ( ) . expect ( "Expected 32 bytes" ) ,
366
+ ) ;
367
+ res. y = FieldElement :: from_bytes_unchecked_le (
368
+ & res_y. try_into ( ) . expect ( "Expected 32 bytes" ) ,
369
+ ) ;
302
370
return res;
303
371
}
304
372
0 commit comments