Skip to content

Commit

Permalink
nicer naming
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jul 9, 2024
1 parent e8732ca commit d4b98d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn compute_encrypted_event_log<Event, NB, MB, OB>(
event: Event
) -> [u8; OB] where Event: EventInterface<NB, MB> {
// @todo Need to draw randomness from the full domain of Fq not only Fr
let eph_sk: Scalar = fr_to_private_key(unsafe_rand());
let eph_sk: Scalar = fr_to_fq(unsafe_rand());
let eph_pk = eph_sk.derive_public_key();

// TODO: (#7177) This value needs to be populated!
Expand All @@ -37,7 +37,7 @@ pub fn compute_encrypted_event_log<Event, NB, MB, OB>(
let incoming_header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, ivpk);
let outgoing_Header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, ovpk);
let incoming_body_ciphertext = EncryptedLogIncomingBody::from_event(event, randomness).compute_ciphertext(eph_sk, ivpk_app);
let outgoing_body_ciphertext: [u8; 176] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk_app).compute_ciphertext(fr_to_private_key(ovsk_app), eph_pk);
let outgoing_body_ciphertext: [u8; 176] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk_app).compute_ciphertext(fr_to_fq(ovsk_app), eph_pk);

let mut encrypted_bytes: [u8; OB] = [0; OB];
// @todo We ignore the tags for now
Expand Down Expand Up @@ -81,7 +81,7 @@ pub fn compute_encrypted_note_log<Note, N, NB, M>(
note: Note
) -> [u8; M] where Note: NoteInterface<N, NB> {
// @todo Need to draw randomness from the full domain of Fq not only Fr
let eph_sk: Scalar = fr_to_private_key(unsafe_rand());
let eph_sk: Scalar = fr_to_fq(unsafe_rand());
let eph_pk = eph_sk.derive_public_key();

// TODO: (#7177) This value needs to be populated!
Expand All @@ -94,7 +94,7 @@ pub fn compute_encrypted_note_log<Note, N, NB, M>(
let incoming_header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, ivpk);
let outgoing_Header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, ovpk);
let incoming_body_ciphertext = EncryptedLogIncomingBody::from_note(note, storage_slot).compute_ciphertext(eph_sk, ivpk_app);
let outgoing_body_ciphertext: [u8; 176] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk_app).compute_ciphertext(fr_to_private_key(ovsk_app), eph_pk);
let outgoing_body_ciphertext: [u8; 176] = EncryptedLogOutgoingBody::new(eph_sk, recipient, ivpk_app).compute_ciphertext(fr_to_fq(ovsk_app), eph_pk);

let mut encrypted_bytes: [u8; M] = [0; M];
// @todo We ignore the tags for now
Expand Down Expand Up @@ -129,7 +129,9 @@ pub fn compute_encrypted_note_log<Note, N, NB, M>(
encrypted_bytes
}

fn fr_to_private_key(r: Field) -> Scalar {
/// Converts a base field elememt to scalar field element.
/// This is fine because modulus of the base field is smaller than the modulus of the scalar field.
fn fr_to_fq(r: Field) -> Scalar {
let r_bytes = r.to_be_bytes(32);

let mut high_bytes = [0; 32];
Expand All @@ -155,7 +157,7 @@ fn compute_ivpk_app(ivpk: Point, contract_address: AztecAddress) -> Point {
// for example user could define ivpk = infinity using the registry
assert((ivpk.x != 0) & (ivpk.y != 0), "ivpk is infinite");
let i = fr_to_private_key(poseidon2_hash([contract_address.to_field(), ivpk.x, ivpk.y, GENERATOR_INDEX__IVSK_M]));
let i = fr_to_fq(poseidon2_hash([contract_address.to_field(), ivpk.x, ivpk.y, GENERATOR_INDEX__IVSK_M]));
let I = i.derive_public_key();
let embed_I = Point { x: I.x, y: I.y, is_infinite: false };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ impl Serialize<SCALAR_SIZE> for Scalar {
fn serialize(self) -> [Field; SCALAR_SIZE] {
[self.hi, self.lo]
}
}
}

0 comments on commit d4b98d8

Please sign in to comment.