Skip to content

Commit

Permalink
feat!: moving compute_address func to AztecAddress (AztecProtocol#3801)
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jan 3, 2024
1 parent be1e6f1 commit 3107aad
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
14 changes: 0 additions & 14 deletions yarn-project/aztec-nr/aztec/src/address.nr

This file was deleted.

1 change: 0 additions & 1 deletion yarn-project/aztec-nr/aztec/src/lib.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod abi;
mod address;
mod context;
mod hash;
mod history;
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/aztec-nr/aztec/src/oracle/get_public_key.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::types::point::Point;
use crate::address::compute_address;
use dep::protocol_types::address::AztecAddress;

#[oracle(getPublicKeyAndPartialAddress)]
Expand All @@ -15,7 +14,7 @@ pub fn get_public_key(address: AztecAddress) -> Point {
let pub_key_y = result[1];
let partial_address = result[2];

let calculated_address = compute_address(pub_key_x, pub_key_y, partial_address);
let calculated_address = AztecAddress::compute(pub_key_x, pub_key_y, partial_address);
assert(calculated_address.eq(address));

Point::new(pub_key_x, pub_key_y)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use dep::protocol_types::address::AztecAddress;
use dep::std::{schnorr::verify_signature};
use dep::aztec::address::compute_address;
use crate::auth_oracle::{AuthWitness};

pub fn recover_address(message_hash: Field, witness: AuthWitness) -> AztecAddress {
let message_bytes = message_hash.to_be_bytes(32);
let verification = verify_signature(witness.owner.x,
let verification = verify_signature(
witness.owner.x,
witness.owner.y,
witness.signature,
message_bytes);
message_bytes
);
assert(verification == true);

compute_address(witness.owner.x, witness.owner.y, witness.partial_address)
AztecAddress::compute(witness.owner.x, witness.owner.y, witness.partial_address)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::utils;
use crate::{
constants::GENERATOR_INDEX__CONTRACT_ADDRESS,
hash::pedersen_hash,
utils,
};

// Aztec address
struct AztecAddress {
Expand All @@ -24,6 +28,15 @@ impl AztecAddress {
}
}

pub fn compute(pub_key_x: Field, pub_key_y: Field, partial_address: Field) -> AztecAddress {
AztecAddress::from_field(
pedersen_hash(
[pub_key_x, pub_key_y, partial_address],
GENERATOR_INDEX__CONTRACT_ADDRESS
)
)
}

pub fn to_field(self) -> Field {
self.inner
}
Expand Down

0 comments on commit 3107aad

Please sign in to comment.