@@ -12,30 +12,26 @@ use crate::{
1212 encrypted_logs::header::EncryptedLogHeader ,
1313 keys::point_to_symmetric_key:: point_to_symmetric_key ,
1414};
15+ use protocol_types::public_keys::AddressPoint ;
1516
1617pub fn compute_encrypted_log <let P : u32 , let M : u32 >(
1718 contract_address : AztecAddress ,
1819 ovsk_app : Field ,
1920 ovpk : OvpkM ,
20- ivpk : IvpkM ,
2121 recipient : AztecAddress ,
2222 plaintext : [u8 ; P ],
2323) -> [u8 ; M ] {
2424 let (eph_sk , eph_pk ) = generate_ephemeral_key_pair ();
2525
2626 let header = EncryptedLogHeader ::new (contract_address );
2727
28- let incoming_header_ciphertext : [u8 ; 48 ] = header .compute_ciphertext (eph_sk , recipient );
28+ let incoming_header_ciphertext : [u8 ; 48 ] =
29+ header .compute_ciphertext (eph_sk , recipient .to_address_point ());
2930 let outgoing_header_ciphertext : [u8 ; 48 ] = header .compute_ciphertext (eph_sk , ovpk );
3031 let incoming_body_ciphertext =
31- compute_incoming_body_ciphertext (plaintext , eph_sk , IvpkM { inner : recipient .to_point () });
32- let outgoing_body_ciphertext : [u8 ; 144 ] = compute_outgoing_body_ciphertext (
33- recipient ,
34- IvpkM { inner : recipient .to_point () },
35- fr_to_fq (ovsk_app ),
36- eph_sk ,
37- eph_pk ,
38- );
32+ compute_incoming_body_ciphertext (plaintext , eph_sk , recipient .to_address_point ());
33+ let outgoing_body_ciphertext : [u8 ; 144 ] =
34+ compute_outgoing_body_ciphertext (recipient , fr_to_fq (ovsk_app ), eph_sk , eph_pk );
3935
4036 let mut encrypted_bytes : [u8 ; M ] = [0 ; M ];
4137 // @todo We ignore the tags for now
@@ -96,9 +92,9 @@ fn generate_ephemeral_key_pair() -> (Scalar, Point) {
9692pub fn compute_incoming_body_ciphertext <let P : u32 >(
9793 plaintext : [u8 ; P ],
9894 eph_sk : Scalar ,
99- ivpk : IvpkM ,
95+ address_point : AddressPoint ,
10096) -> [u8 ] {
101- let full_key = point_to_symmetric_key (eph_sk , ivpk .to_point ());
97+ let full_key = point_to_symmetric_key (eph_sk , address_point .to_point ());
10298 let mut sym_key = [0 ; 16 ];
10399 let mut iv = [0 ; 16 ];
104100
@@ -113,7 +109,6 @@ pub fn compute_incoming_body_ciphertext<let P: u32>(
113109/// be able to derive the key with which the incoming log can be decrypted.
114110pub fn compute_outgoing_body_ciphertext (
115111 recipient : AztecAddress ,
116- recipient_ivpk : IvpkM ,
117112 ovsk_app : Scalar ,
118113 eph_sk : Scalar ,
119114 eph_pk : Point ,
@@ -126,7 +121,7 @@ pub fn compute_outgoing_body_ciphertext(
126121 let serialized_eph_sk_low : [u8 ; 32 ] = eph_sk .lo .to_be_bytes ();
127122
128123 let address_bytes : [u8 ; 32 ] = recipient .to_field ().to_be_bytes ();
129- let serialized_recipient_ivpk = point_to_bytes (recipient_ivpk .to_point ());
124+ let serialized_recipient_ivpk = point_to_bytes (recipient . to_address_point () .to_point ());
130125
131126 for i in 0 ..32 {
132127 buffer [i ] = serialized_eph_sk_high [i ];
@@ -163,6 +158,7 @@ mod test {
163158 address::AztecAddress , public_keys ::{OvpkM , IvpkM }, point::Point , scalar::Scalar ,
164159 };
165160 use std::test::OracleMock ;
161+ use protocol_types::public_keys::AddressPoint ;
166162
167163 #[test]
168164 unconstrained fn test_encrypted_log_matches_typescript () {
@@ -203,16 +199,10 @@ mod test {
203199 0x25afb798ea6d0b8c1618e50fdeafa463059415013d3b7c75d46abf5e242be70c ,
204200 );
205201
206- let log : [u8 ; 448 ] = compute_encrypted_log (
207- contract_address ,
208- ovsk_app ,
209- ovpk_m ,
210- ivpk_m ,
211- recipient ,
212- plaintext ,
213- );
202+ let log : [u8 ; 448 ] =
203+ compute_encrypted_log (contract_address , ovsk_app , ovpk_m , recipient , plaintext );
214204
215- // The following value was generated by `tagged_log .test.ts`
205+ // The following value was generated by `encrypted_log_payload .test.ts`
216206 // --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
217207 let encrypted_log_from_typescript = [
218208 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 ,
@@ -249,7 +239,7 @@ mod test {
249239 lo : 0x00000000000000000000000000000000649e7ca01d9de27b21624098b897babd ,
250240 hi : 0x0000000000000000000000000000000023b3127c127b1f29a7adff5cccf8fb06 ,
251241 };
252- let ivpk = IvpkM {
242+ let address_point = AddressPoint {
253243 inner : Point {
254244 x : 0x2688431c705a5ff3e6c6f2573c9e3ba1c1026d2251d0dbbf2d810aa53fd1d186 ,
255245 y : 0x1e96887b117afca01c00468264f4f80b5bb16d94c1808a448595f115556e5c8e ,
@@ -267,7 +257,7 @@ mod test {
267257
268258 // `compute_incoming_body_ciphertext(...)` function then derives symmetric key from `eph_sk` and `ivpk` and encrypts
269259 // the note plaintext using AES-128.
270- let ciphertext = compute_incoming_body_ciphertext (plaintext , eph_sk , ivpk );
260+ let ciphertext = compute_incoming_body_ciphertext (plaintext , eph_sk , address_point );
271261
272262 // The following value was generated by `encrypted_note_log_incoming_body.test.ts`.
273263 // --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
@@ -297,39 +287,31 @@ mod test {
297287 lo : 0x00000000000000000000000000000000d0d302ee245dfaf2807e604eec4715fe ,
298288 hi : 0x000000000000000000000000000000000f096b423017226a18461115fa8d34bb ,
299289 };
300- let recipient_ivsk = Scalar {
301- lo : 0x000000000000000000000000000000004828f8f95676ebb481df163f87fd4022 ,
302- hi : 0x000000000000000000000000000000000f4d97c25d578f9348251a71ca17ae31 ,
303- };
290+
304291 let sender_ovsk_app = Scalar {
305292 lo : 0x0000000000000000000000000000000074d2e28c6bc5176ac02cf7c7d36a444e ,
306293 hi : 0x00000000000000000000000000000000089c6887cb1446d86c64e81afc78048b ,
307294 };
308295
309296 let eph_pk = derive_public_key (eph_sk );
310- let recipient_ivpk = IvpkM { inner : derive_public_key (recipient_ivsk ) };
311-
312- let recipient = AztecAddress ::from_field (0xdeadbeef );
313-
314- let ciphertext = compute_outgoing_body_ciphertext (
315- recipient ,
316- recipient_ivpk ,
317- sender_ovsk_app ,
318- eph_sk ,
319- eph_pk ,
297+ let recipient = AztecAddress ::from_field (
298+ 0x25afb798ea6d0b8c1618e50fdeafa463059415013d3b7c75d46abf5e242be70c ,
320299 );
321300
322- // The following value was generated by `encrypted_log_outgoing_body.test.ts`
301+ let ciphertext =
302+ compute_outgoing_body_ciphertext (recipient , sender_ovsk_app , eph_sk , eph_pk );
303+
304+ // The following value was generated by `encrypted_log_payload.test.ts`
323305 // --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
324306 let outgoing_body_ciphertext_from_typescript = [
325307 127 , 182 , 227 , 75 , 192 , 197 , 54 , 47 , 168 , 134 , 233 , 148 , 251 , 46 , 86 , 12 , 73 , 50 , 238 ,
326308 50 , 31 , 174 , 27 , 202 , 110 , 77 , 161 , 197 , 244 , 124 , 17 , 100 , 143 , 150 , 232 , 14 , 156 , 248 ,
327309 43 , 177 , 16 , 82 , 244 , 103 , 88 , 74 , 84 , 200 , 15 , 65 , 187 , 14 , 163 , 60 , 91 , 22 , 104 , 31 ,
328- 211 , 190 , 124 , 121 , 79 , 92 , 239 , 65 , 185 , 106 , 51 , 178 , 168 , 137 , 84 , 43 , 79 , 158 , 151 ,
329- 152 , 83 , 42 , 170 , 13 , 106 , 209 , 254 , 74 , 39 , 145 , 73 , 215 , 17 , 234 , 196 , 89 , 30 , 58 ,
330- 120 , 127 , 88 , 69 , 121 , 61 , 18 , 206 , 89 , 118 , 243 , 238 , 177 , 71 , 73 , 47 , 147 , 4 , 155 , 25 ,
331- 173 , 248 , 206 , 52 , 17 , 180 , 122 , 186 , 106 , 191 , 252 , 102 , 197 , 91 , 16 , 39 , 94 , 91 , 224 ,
332- 30 , 168 , 177 , 26 , 144 , 5 , 124 , 128 , 6 ,
310+ 211 , 190 , 124 , 121 , 79 , 92 , 238 , 182 , 194 , 225 , 34 , 71 , 67 , 116 , 27 , 231 , 68 , 161 , 147 ,
311+ 94 , 53 , 195 , 83 , 237 , 172 , 52 , 173 , 229 , 26 , 234 , 107 , 43 , 82 , 68 , 16 , 105 , 37 , 125 ,
312+ 117 , 86 , 133 , 50 , 21 , 92 , 74 , 229 , 105 , 141 , 83 , 229 , 255 , 251 , 21 , 61 , 234 , 61 , 168 ,
313+ 221 , 106 , 231 , 8 , 73 , 208 , 60 , 251 , 46 , 251 , 228 , 148 , 144 , 187 , 195 , 38 , 18 , 223 , 153 ,
314+ 8 , 121 , 178 , 84 , 237 , 148 , 254 , 219 , 59 , 62 ,
333315 ];
334316
335317 assert_eq (outgoing_body_ciphertext_from_typescript , ciphertext );
0 commit comments