Skip to content

Commit 44458be

Browse files
authored
feat!: typing partial address, deduplicating Point, Point -> GrumpkinPoint (AztecProtocol#3814)
Fixes AztecProtocol#3682
1 parent f091f49 commit 44458be

File tree

21 files changed

+183
-179
lines changed

21 files changed

+183
-179
lines changed

yarn-project/aztec-nr/aztec/src/context.nr

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use dep::protocol_types::{
3333
storage_update_request::StorageUpdateRequest,
3434
},
3535
hash::hash_args,
36-
point::Point,
36+
grumpkin_point::GrumpkinPoint,
3737
};
3838

3939
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165)
@@ -313,7 +313,7 @@ impl PrivateContext {
313313
global_variables_hash: fields[151],
314314
},
315315
contract_deployment_data: ContractDeploymentData {
316-
deployer_public_key: Point {
316+
deployer_public_key: GrumpkinPoint {
317317
x: fields[152],
318318
y: fields[153],
319319
},

yarn-project/aztec-nr/aztec/src/history/contract_inclusion.nr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use dep::protocol_types::{
44
new_contract_data::NewContractData as ContractLeafPreimage,
55
},
66
address::{AztecAddress, EthAddress},
7-
point::Point,
7+
grumpkin_point::GrumpkinPoint,
88
};
99
use dep::std::merkle::compute_merkle_root;
1010

@@ -22,7 +22,7 @@ use crate::{
2222
// it is what it expects. The constructor param check is the reason of why we pass in the preimage of contract's
2323
// aztec address instead of just the address.
2424
pub fn prove_contract_inclusion(
25-
deployer_public_key: Point,
25+
deployer_public_key: GrumpkinPoint,
2626
contract_address_salt: Field,
2727
function_tree_root: Field,
2828
constructor_hash: Field,

yarn-project/aztec-nr/aztec/src/log.nr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use crate::context::{PrivateContext, PublicContext};
22
use crate::oracle;
3-
use crate::types::point::Point;
43
use dep::protocol_types::{
54
address::AztecAddress,
5+
grumpkin_point::GrumpkinPoint,
66
};
77

88
pub fn emit_encrypted_log<N>(
99
context: &mut PrivateContext,
1010
contract_address: AztecAddress,
1111
storage_slot: Field,
12-
encryption_pub_key: Point,
12+
encryption_pub_key: GrumpkinPoint,
1313
log: [Field; N]
1414
) {
1515
let _ = oracle::logs::emit_encrypted_log(contract_address, storage_slot, encryption_pub_key, log);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
use crate::types::point::Point;
2-
use dep::protocol_types::address::AztecAddress;
1+
use dep::protocol_types::{
2+
address::{
3+
AztecAddress,
4+
PartialAddress,
5+
},
6+
grumpkin_point::GrumpkinPoint,
7+
};
38

49
#[oracle(getPublicKeyAndPartialAddress)]
510
fn get_public_key_and_partial_address_oracle(_address: AztecAddress) -> [Field; 3] {}
@@ -8,14 +13,13 @@ unconstrained fn get_public_key_and_partial_address_internal(address: AztecAddre
813
get_public_key_and_partial_address_oracle(address)
914
}
1015

11-
pub fn get_public_key(address: AztecAddress) -> Point {
16+
pub fn get_public_key(address: AztecAddress) -> GrumpkinPoint {
1217
let result = get_public_key_and_partial_address_internal(address);
13-
let pub_key_x = result[0];
14-
let pub_key_y = result[1];
15-
let partial_address = result[2];
18+
let pub_key = GrumpkinPoint::new(result[0], result[1]);
19+
let partial_address = PartialAddress::from_field(result[2]);
1620

17-
let calculated_address = AztecAddress::compute(pub_key_x, pub_key_y, partial_address);
21+
let calculated_address = AztecAddress::compute(pub_key, partial_address);
1822
assert(calculated_address.eq(address));
1923

20-
Point::new(pub_key_x, pub_key_y)
24+
pub_key
2125
}

yarn-project/aztec-nr/aztec/src/oracle/get_secret_key.nr

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use crate::oracle::get_public_key::get_public_key;
2-
use crate::types::point::Point;
3-
use dep::protocol_types::address::AztecAddress;
2+
use dep::protocol_types::{
3+
address::AztecAddress,
4+
grumpkin_point::GrumpkinPoint,
5+
};
46

57
#[oracle(getSecretKey)]
6-
fn get_secret_key_oracle(_owner: Point) -> [Field; dep::std::grumpkin_scalar::GRUMPKIN_SCALAR_SERIALIZED_LEN] {}
8+
fn get_secret_key_oracle(_owner: GrumpkinPoint) -> [Field; dep::std::grumpkin_scalar::GRUMPKIN_SCALAR_SERIALIZED_LEN] {}
79

8-
unconstrained fn get_secret_key_internal(owner_public_key: Point) -> dep::std::grumpkin_scalar::GrumpkinScalar {
10+
unconstrained fn get_secret_key_internal(owner_public_key: GrumpkinPoint) -> dep::std::grumpkin_scalar::GrumpkinScalar {
911
dep::std::grumpkin_scalar::deserialize_grumpkin_scalar(get_secret_key_oracle(owner_public_key))
1012
}
1113

Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1-
use crate::types::point::Point;
21
use dep::protocol_types::{
32
address::AztecAddress,
43
constants::NUM_FIELDS_PER_SHA256,
4+
grumpkin_point::GrumpkinPoint,
55
};
66

77
// TODO: Should take encrypted data.
88
#[oracle(emitEncryptedLog)]
9-
fn emit_encrypted_log_oracle<N>(_contract_address: AztecAddress, _storage_slot: Field, _encryption_pub_key: Point, _preimage: [Field; N]) -> Field {}
9+
fn emit_encrypted_log_oracle<N>(
10+
_contract_address: AztecAddress,
11+
_storage_slot: Field,
12+
_encryption_pub_key: GrumpkinPoint,
13+
_preimage: [Field; N]
14+
) -> Field {}
1015

11-
unconstrained pub fn emit_encrypted_log<N>(contract_address: AztecAddress, storage_slot: Field, encryption_pub_key: Point, preimage: [Field; N]) -> [Field; NUM_FIELDS_PER_SHA256] {
16+
unconstrained pub fn emit_encrypted_log<N>(
17+
contract_address: AztecAddress,
18+
storage_slot: Field,
19+
encryption_pub_key: GrumpkinPoint,
20+
preimage: [Field; N]
21+
) -> [Field; NUM_FIELDS_PER_SHA256] {
1222
[emit_encrypted_log_oracle(contract_address, storage_slot, encryption_pub_key, preimage), 0]
1323
}
1424

1525
#[oracle(emitUnencryptedLog)]
1626
fn emit_unencrypted_log_oracle<T>(_contract_address: AztecAddress, _event_selector: Field, _message: T) -> Field {}
1727

18-
unconstrained pub fn emit_unencrypted_log<T>(contract_address: AztecAddress, event_selector: Field, message: T) -> [Field; NUM_FIELDS_PER_SHA256] {
28+
unconstrained pub fn emit_unencrypted_log<T>(
29+
contract_address: AztecAddress,
30+
event_selector: Field,
31+
message: T
32+
) -> [Field; NUM_FIELDS_PER_SHA256] {
1933
// https://github.com/AztecProtocol/aztec-packages/issues/885
2034
[emit_unencrypted_log_oracle(contract_address, event_selector, message), 0]
2135
}
-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
mod point;
21
mod vec; // This can/should be moved out into an official noir library
32
mod type_serialization;

yarn-project/aztec-nr/aztec/src/types/point.nr

-27
This file was deleted.

yarn-project/noir-contracts/src/contracts/card_game_contract/src/cards.nr

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
use dep::protocol_types::constants::{MAX_NOTES_PER_PAGE, MAX_READ_REQUESTS_PER_CALL};
2-
use dep::protocol_types::address::AztecAddress;
1+
use dep::protocol_types::{
2+
address::AztecAddress,
3+
constants::{
4+
MAX_NOTES_PER_PAGE,
5+
MAX_READ_REQUESTS_PER_CALL,
6+
},
7+
};
38
use dep::aztec::{
49
context::{PrivateContext, PublicContext, Context},
510
note::{
@@ -9,7 +14,6 @@ use dep::aztec::{
914
},
1015
oracle::get_secret_key::get_secret_key,
1116
state_vars::set::Set,
12-
types::point::Point,
1317
};
1418
use dep::std;
1519
use dep::std::{
@@ -88,7 +92,10 @@ struct Deck {
8892
set: Set<ValueNote, VALUE_NOTE_LEN>,
8993
}
9094

91-
pub fn filter_cards<N>(notes: [Option<ValueNote>; MAX_READ_REQUESTS_PER_CALL], desired_cards: [Card; N]) -> [Option<ValueNote>; MAX_READ_REQUESTS_PER_CALL] {
95+
pub fn filter_cards<N>(
96+
notes: [Option<ValueNote>; MAX_READ_REQUESTS_PER_CALL],
97+
desired_cards: [Card; N]
98+
) -> [Option<ValueNote>; MAX_READ_REQUESTS_PER_CALL] {
9299
let mut selected = [Option::none(); MAX_READ_REQUESTS_PER_CALL];
93100

94101
let mut found = [false; N];
@@ -210,8 +217,10 @@ pub fn get_pack_cards(seed: Field, owner: AztecAddress) -> [Card; PACK_CARDS] {
210217
}
211218

212219
pub fn compute_deck_strength<N>(cards: [Card; N]) -> Field {
213-
cards.fold(0,
220+
cards.fold(
221+
0,
214222
|acc, card: Card| {
215223
acc + card.strength as Field
216-
})
224+
}
225+
)
217226
}

yarn-project/noir-contracts/src/contracts/inclusion_proofs_contract/src/main.nr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ contract InclusionProofs {
66
AztecAddress,
77
EthAddress,
88
},
9-
point::Point,
9+
grumpkin_point::GrumpkinPoint,
1010
};
1111
use dep::aztec::{
1212
state_vars::{
@@ -211,7 +211,7 @@ contract InclusionProofs {
211211
// contract's aztec address instead of just the address.
212212
#[aztec(private)]
213213
fn test_contract_inclusion_proof(
214-
deployer_public_key: Point,
214+
deployer_public_key: GrumpkinPoint,
215215
contract_address_salt: Field,
216216
function_tree_root: Field,
217217
constructor_hash: Field,

yarn-project/noir-contracts/src/contracts/schnorr_hardcoded_account_contract/src/main.nr

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ contract SchnorrHardcodedAccount {
44
use dep::std;
55
use dep::aztec::{
66
abi::{ PrivateCircuitPublicInputs, PrivateContextInputs, Hasher },
7-
types::{ vec::BoundedVec, point::Point },
87
context::PrivateContext,
8+
types::vec::BoundedVec,
99
};
1010

1111
use dep::authwit:: {
@@ -58,10 +58,12 @@ contract SchnorrHardcodedAccount {
5858
}
5959

6060
// Verify signature using hardcoded public key
61-
let verification = std::schnorr::verify_signature(public_key_x,
61+
let verification = std::schnorr::verify_signature(
62+
public_key_x,
6263
public_key_y,
6364
signature,
64-
message_hash.to_be_bytes(32));
65+
message_hash.to_be_bytes(32)
66+
);
6567
assert(verification == true);
6668
true
6769
}

yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/auth_oracle.nr

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
use dep::aztec::types::point::Point;
21
use dep::authwit::auth_witness;
2+
use dep::protocol_types::{
3+
address::PartialAddress,
4+
grumpkin_point::GrumpkinPoint,
5+
};
36

47
struct AuthWitness {
5-
owner: Point,
8+
owner: GrumpkinPoint,
69
signature: [u8; 64],
7-
partial_address: Field,
10+
partial_address: PartialAddress,
811
}
912

1013
impl AuthWitness {
@@ -14,9 +17,9 @@ impl AuthWitness {
1417
signature[i] = values[i + 2] as u8;
1518
}
1619
Self {
17-
owner: Point::new(values[0], values[1]),
20+
owner: GrumpkinPoint::new(values[0], values[1]),
1821
signature,
19-
partial_address: values[66],
22+
partial_address: PartialAddress::from_field(values[66]),
2023
}
2124
}
2225
}

yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/util.nr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ pub fn recover_address(message_hash: Field, witness: AuthWitness) -> AztecAddres
1212
);
1313
assert(verification == true);
1414

15-
AztecAddress::compute(witness.owner.x, witness.owner.y, witness.partial_address)
15+
AztecAddress::compute(witness.owner, witness.partial_address)
1616
}

yarn-project/noir-protocol-circuits/src/crates/types/src/abis/complete_address.nr

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
use crate::point::Point;
2-
use crate::address::AztecAddress;
3-
use crate::hash::{compute_partial_address,compute_contract_address_from_partial};
1+
use crate::{
2+
address::{
3+
AztecAddress,
4+
PartialAddress,
5+
},
6+
grumpkin_point::GrumpkinPoint,
7+
};
48

5-
struct CompleteAddress{
9+
struct CompleteAddress {
610
address : AztecAddress,
7-
public_key : Point,
8-
// TODO(David): Can we type this as AztecAddress instead of Field?
9-
partial_address: Field,
11+
public_key : GrumpkinPoint,
12+
partial_address: PartialAddress,
1013
}
1114

1215
impl CompleteAddress{
1316
fn assert_is_zero(self) {
1417
self.address.assert_is_zero();
1518
self.public_key.assert_is_zero();
16-
assert(self.partial_address == 0);
19+
self.partial_address.assert_is_zero();
1720
}
1821

19-
pub fn compute(point : Point, contract_address_salt : Field, function_tree_root : Field, constructor_hash : Field) -> CompleteAddress {
20-
let partial_address = compute_partial_address(contract_address_salt, function_tree_root, constructor_hash);
22+
pub fn compute(public_key : GrumpkinPoint, contract_address_salt : Field, function_tree_root : Field, constructor_hash : Field) -> CompleteAddress {
23+
let partial_address = PartialAddress::compute(contract_address_salt, function_tree_root, constructor_hash);
2124

2225
CompleteAddress{
23-
address : compute_contract_address_from_partial(point, partial_address),
24-
public_key : point,
26+
address : AztecAddress::compute(public_key, partial_address),
27+
public_key,
2528
partial_address,
2629
}
2730
}

0 commit comments

Comments
 (0)