@@ -16,12 +16,12 @@ use crate::{
1616 keys::point_to_symmetric_key:: point_to_symmetric_key , oracle::random:: random ,
1717 utils::point:: point_to_bytes ,
1818};
19+ use protocol_types::public_keys::AddressPoint ;
1920
2021fn compute_private_log_payload <let P : u32 , let M : u32 >(
2122 contract_address : AztecAddress ,
2223 ovsk_app : Field ,
2324 ovpk : OvpkM ,
24- ivpk : IvpkM ,
2525 recipient : AztecAddress ,
2626 plaintext : [u8 ; P ],
2727 include_public_values_prefix : bool ,
@@ -30,17 +30,13 @@ fn compute_private_log_payload<let P: u32, let M: u32>(
3030
3131 let header = EncryptedLogHeader ::new (contract_address );
3232
33- let incoming_header_ciphertext : [u8 ; 48 ] = header .compute_ciphertext (eph_sk , recipient );
33+ let incoming_header_ciphertext : [u8 ; 48 ] =
34+ header .compute_ciphertext (eph_sk , recipient .to_address_point ());
3435 let outgoing_header_ciphertext : [u8 ; 48 ] = header .compute_ciphertext (eph_sk , ovpk );
3536 let incoming_body_ciphertext =
36- compute_incoming_body_ciphertext (plaintext , eph_sk , IvpkM { inner : recipient .to_point () });
37- let outgoing_body_ciphertext : [u8 ; 144 ] = compute_outgoing_body_ciphertext (
38- recipient ,
39- IvpkM { inner : recipient .to_point () },
40- fr_to_fq (ovsk_app ),
41- eph_sk ,
42- eph_pk ,
43- );
37+ compute_incoming_body_ciphertext (plaintext , eph_sk , recipient .to_address_point ());
38+ let outgoing_body_ciphertext : [u8 ; 144 ] =
39+ compute_outgoing_body_ciphertext (recipient , fr_to_fq (ovsk_app ), eph_sk , eph_pk );
4440
4541 // If we include the prefix for number of public values, we need to add 1 byte to the offset
4642 let mut offset = if include_public_values_prefix { 1 } else { 0 };
@@ -113,9 +109,9 @@ fn generate_ephemeral_key_pair() -> (Scalar, Point) {
113109pub fn compute_incoming_body_ciphertext <let P : u32 >(
114110 plaintext : [u8 ; P ],
115111 eph_sk : Scalar ,
116- ivpk : IvpkM ,
112+ address_point : AddressPoint ,
117113) -> [u8 ] {
118- let full_key = point_to_symmetric_key (eph_sk , ivpk .to_point ());
114+ let full_key = point_to_symmetric_key (eph_sk , address_point .to_point ());
119115 let mut sym_key = [0 ; 16 ];
120116 let mut iv = [0 ; 16 ];
121117
@@ -130,7 +126,6 @@ pub fn compute_incoming_body_ciphertext<let P: u32>(
130126/// be able to derive the key with which the incoming log can be decrypted.
131127pub fn compute_outgoing_body_ciphertext (
132128 recipient : AztecAddress ,
133- recipient_ivpk : IvpkM ,
134129 ovsk_app : Scalar ,
135130 eph_sk : Scalar ,
136131 eph_pk : Point ,
@@ -143,7 +138,7 @@ pub fn compute_outgoing_body_ciphertext(
143138 let serialized_eph_sk_low : [u8 ; 32 ] = eph_sk .lo .to_be_bytes ();
144139
145140 let address_bytes : [u8 ; 32 ] = recipient .to_field ().to_be_bytes ();
146- let serialized_recipient_ivpk = point_to_bytes (recipient_ivpk .to_point ());
141+ let serialized_recipient_ivpk = point_to_bytes (recipient . to_address_point () .to_point ());
147142
148143 for i in 0 ..32 {
149144 buffer [i ] = serialized_eph_sk_high [i ];
@@ -184,6 +179,7 @@ mod test {
184179 };
185180 use std::embedded_curve_ops::fixed_base_scalar_mul as derive_public_key ;
186181 use std::test::OracleMock ;
182+ use protocol_types::public_keys::AddressPoint ;
187183
188184 #[test]
189185 unconstrained fn test_encrypted_log_matches_typescript () {
@@ -228,13 +224,12 @@ mod test {
228224 contract_address ,
229225 ovsk_app ,
230226 ovpk_m ,
231- ivpk_m ,
232227 recipient ,
233228 plaintext ,
234229 false ,
235230 );
236231
237- // The following value was generated by `tagged_log .test.ts`
232+ // The following value was generated by `encrypted_log_payload .test.ts`
238233 // --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
239234 let encrypted_log_from_typescript = [
240235 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -271,7 +266,7 @@ mod test {
271266 lo : 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd ,
272267 hi : 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 ,
273268 };
274- let ivpk = IvpkM {
269+ let address_point = AddressPoint {
275270 inner : Point {
276271 x : 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186 ,
277272 y : 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e ,
@@ -289,7 +284,7 @@ mod test {
289284
290285 // `compute_incoming_body_ciphertext(...)` function then derives symmetric key from `eph_sk` and `ivpk` and encrypts
291286 // the note plaintext using AES-128.
292- let ciphertext = compute_incoming_body_ciphertext (plaintext , eph_sk , ivpk );
287+ let ciphertext = compute_incoming_body_ciphertext (plaintext , eph_sk , address_point );
293288
294289 // The following value was generated by `encrypted_note_log_incoming_body.test.ts`.
295290 // --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
@@ -319,39 +314,31 @@ mod test {
319314 lo : 0x00000000000000000000000000000000d0d302ee245dfaf2807e604eec4715fe ,
320315 hi : 0x000000000000000000000000000000000f096b423017226a18461115fa8d34bb ,
321316 };
322- let recipient_ivsk = Scalar {
323- lo : 0x000000000000000000000000000000004828f8f95676ebb481df163f87fd4022 ,
324- hi : 0x000000000000000000000000000000000f4d97c25d578f9348251a71ca17ae31 ,
325- };
317+
326318 let sender_ovsk_app = Scalar {
327319 lo : 0x0000000000000000000000000000000074d2e28c6bc5176ac02cf7c7d36a444e ,
328320 hi : 0x00000000000000000000000000000000089c6887cb1446d86c64e81afc78048b ,
329321 };
330322
331323 let eph_pk = derive_public_key (eph_sk );
332- let recipient_ivpk = IvpkM { inner : derive_public_key (recipient_ivsk ) };
333-
334- let recipient = AztecAddress ::from_field (0xdeadbeef );
335-
336- let ciphertext = compute_outgoing_body_ciphertext (
337- recipient ,
338- recipient_ivpk ,
339- sender_ovsk_app ,
340- eph_sk ,
341- eph_pk ,
324+ let recipient = AztecAddress ::from_field (
325+ 0x25afb798ea6d0b8c1618e50fdeafa463059415013d3b7c75d46abf5e242be70c ,
342326 );
343327
344- // The following value was generated by `encrypted_log_outgoing_body.test.ts`
328+ let ciphertext =
329+ compute_outgoing_body_ciphertext (recipient , sender_ovsk_app , eph_sk , eph_pk );
330+
331+ // The following value was generated by `encrypted_log_payload.test.ts`
345332 // --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
346333 let outgoing_body_ciphertext_from_typescript = [
347334 127 , 182 , 227 , 75 , 192 , 197 , 54 , 47 , 168 , 134 , 233 , 148 , 251 , 46 , 86 , 12 , 73 , 50 , 238 ,
348335 50 , 31 , 174 , 27 , 202 , 110 , 77 , 161 , 197 , 244 , 124 , 17 , 100 , 143 , 150 , 232 , 14 , 156 , 248 ,
349336 43 , 177 , 16 , 82 , 244 , 103 , 88 , 74 , 84 , 200 , 15 , 65 , 187 , 14 , 163 , 60 , 91 , 22 , 104 , 31 ,
350- 211 , 190 , 124 , 121 , 79 , 92 , 239 , 65 , 185 , 106 , 51 , 178 , 168 , 137 , 84 , 43 , 79 , 158 , 151 ,
351- 152 , 83 , 42 , 170 , 13 , 106 , 209 , 254 , 74 , 39 , 145 , 73 , 215 , 17 , 234 , 196 , 89 , 30 , 58 ,
352- 120 , 127 , 88 , 69 , 121 , 61 , 18 , 206 , 89 , 118 , 243 , 238 , 177 , 71 , 73 , 47 , 147 , 4 , 155 , 25 ,
353- 173 , 248 , 206 , 52 , 17 , 180 , 122 , 186 , 106 , 191 , 252 , 102 , 197 , 91 , 16 , 39 , 94 , 91 , 224 ,
354- 30 , 168 , 177 , 26 , 144 , 5 , 124 , 128 , 6 ,
337+ 211 , 190 , 124 , 121 , 79 , 92 , 238 , 182 , 194 , 225 , 34 , 71 , 67 , 116 , 27 , 231 , 68 , 161 , 147 ,
338+ 94 , 53 , 195 , 83 , 237 , 172 , 52 , 173 , 229 , 26 , 234 , 107 , 43 , 82 , 68 , 16 , 105 , 37 , 125 ,
339+ 117 , 86 , 133 , 50 , 21 , 92 , 74 , 229 , 105 , 141 , 83 , 229 , 255 , 251 , 21 , 61 , 234 , 61 , 168 ,
340+ 221 , 106 , 231 , 8 , 73 , 208 , 60 , 251 , 46 , 251 , 228 , 148 , 144 , 187 , 195 , 38 , 18 , 223 , 153 ,
341+ 8 , 121 , 178 , 84 , 237 , 148 , 254 , 219 , 59 , 62 ,
355342 ];
356343
357344 assert_eq (outgoing_body_ciphertext_from_typescript , ciphertext );
0 commit comments