diff --git a/yarn-project/aztec-nr/aztec/src/context.nr b/yarn-project/aztec-nr/aztec/src/context.nr index 053299fc1cc..7fc18eb3fa5 100644 --- a/yarn-project/aztec-nr/aztec/src/context.nr +++ b/yarn-project/aztec-nr/aztec/src/context.nr @@ -33,7 +33,7 @@ use dep::protocol_types::{ storage_update_request::StorageUpdateRequest, }, hash::hash_args, - point::Point, + grumpkin_point::GrumpkinPoint, }; // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) @@ -313,7 +313,7 @@ impl PrivateContext { global_variables_hash: fields[151], }, contract_deployment_data: ContractDeploymentData { - deployer_public_key: Point { + deployer_public_key: GrumpkinPoint { x: fields[152], y: fields[153], }, diff --git a/yarn-project/aztec-nr/aztec/src/history/contract_inclusion.nr b/yarn-project/aztec-nr/aztec/src/history/contract_inclusion.nr index 8e71cc5729f..053fb5734b0 100644 --- a/yarn-project/aztec-nr/aztec/src/history/contract_inclusion.nr +++ b/yarn-project/aztec-nr/aztec/src/history/contract_inclusion.nr @@ -4,7 +4,7 @@ use dep::protocol_types::{ new_contract_data::NewContractData as ContractLeafPreimage, }, address::{AztecAddress, EthAddress}, - point::Point, + grumpkin_point::GrumpkinPoint, }; use dep::std::merkle::compute_merkle_root; @@ -22,7 +22,7 @@ use crate::{ // it is what it expects. The constructor param check is the reason of why we pass in the preimage of contract's // aztec address instead of just the address. pub fn prove_contract_inclusion( - deployer_public_key: Point, + deployer_public_key: GrumpkinPoint, contract_address_salt: Field, function_tree_root: Field, constructor_hash: Field, diff --git a/yarn-project/aztec-nr/aztec/src/log.nr b/yarn-project/aztec-nr/aztec/src/log.nr index 6c6119025e8..bc9141debdb 100644 --- a/yarn-project/aztec-nr/aztec/src/log.nr +++ b/yarn-project/aztec-nr/aztec/src/log.nr @@ -1,15 +1,15 @@ use crate::context::{PrivateContext, PublicContext}; use crate::oracle; -use crate::types::point::Point; use dep::protocol_types::{ address::AztecAddress, + grumpkin_point::GrumpkinPoint, }; pub fn emit_encrypted_log( context: &mut PrivateContext, contract_address: AztecAddress, storage_slot: Field, - encryption_pub_key: Point, + encryption_pub_key: GrumpkinPoint, log: [Field; N] ) { let _ = oracle::logs::emit_encrypted_log(contract_address, storage_slot, encryption_pub_key, log); diff --git a/yarn-project/aztec-nr/aztec/src/oracle/get_public_key.nr b/yarn-project/aztec-nr/aztec/src/oracle/get_public_key.nr index b22f8ae84de..d39e7389f2c 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/get_public_key.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/get_public_key.nr @@ -1,5 +1,10 @@ -use crate::types::point::Point; -use dep::protocol_types::address::AztecAddress; +use dep::protocol_types::{ + address::{ + AztecAddress, + PartialAddress, + }, + grumpkin_point::GrumpkinPoint, +}; #[oracle(getPublicKeyAndPartialAddress)] 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 get_public_key_and_partial_address_oracle(address) } -pub fn get_public_key(address: AztecAddress) -> Point { +pub fn get_public_key(address: AztecAddress) -> GrumpkinPoint { let result = get_public_key_and_partial_address_internal(address); - let pub_key_x = result[0]; - let pub_key_y = result[1]; - let partial_address = result[2]; + let pub_key = GrumpkinPoint::new(result[0], result[1]); + let partial_address = PartialAddress::from_field(result[2]); - let calculated_address = AztecAddress::compute(pub_key_x, pub_key_y, partial_address); + let calculated_address = AztecAddress::compute(pub_key, partial_address); assert(calculated_address.eq(address)); - Point::new(pub_key_x, pub_key_y) + pub_key } diff --git a/yarn-project/aztec-nr/aztec/src/oracle/get_secret_key.nr b/yarn-project/aztec-nr/aztec/src/oracle/get_secret_key.nr index d05415e1893..a4da1c2a585 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/get_secret_key.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/get_secret_key.nr @@ -1,11 +1,13 @@ use crate::oracle::get_public_key::get_public_key; -use crate::types::point::Point; -use dep::protocol_types::address::AztecAddress; +use dep::protocol_types::{ + address::AztecAddress, + grumpkin_point::GrumpkinPoint, +}; #[oracle(getSecretKey)] -fn get_secret_key_oracle(_owner: Point) -> [Field; dep::std::grumpkin_scalar::GRUMPKIN_SCALAR_SERIALIZED_LEN] {} +fn get_secret_key_oracle(_owner: GrumpkinPoint) -> [Field; dep::std::grumpkin_scalar::GRUMPKIN_SCALAR_SERIALIZED_LEN] {} -unconstrained fn get_secret_key_internal(owner_public_key: Point) -> dep::std::grumpkin_scalar::GrumpkinScalar { +unconstrained fn get_secret_key_internal(owner_public_key: GrumpkinPoint) -> dep::std::grumpkin_scalar::GrumpkinScalar { dep::std::grumpkin_scalar::deserialize_grumpkin_scalar(get_secret_key_oracle(owner_public_key)) } diff --git a/yarn-project/aztec-nr/aztec/src/oracle/logs.nr b/yarn-project/aztec-nr/aztec/src/oracle/logs.nr index c97b326e838..eefed0a547d 100644 --- a/yarn-project/aztec-nr/aztec/src/oracle/logs.nr +++ b/yarn-project/aztec-nr/aztec/src/oracle/logs.nr @@ -1,21 +1,35 @@ -use crate::types::point::Point; use dep::protocol_types::{ address::AztecAddress, constants::NUM_FIELDS_PER_SHA256, + grumpkin_point::GrumpkinPoint, }; // TODO: Should take encrypted data. #[oracle(emitEncryptedLog)] -fn emit_encrypted_log_oracle(_contract_address: AztecAddress, _storage_slot: Field, _encryption_pub_key: Point, _preimage: [Field; N]) -> Field {} +fn emit_encrypted_log_oracle( + _contract_address: AztecAddress, + _storage_slot: Field, + _encryption_pub_key: GrumpkinPoint, + _preimage: [Field; N] +) -> Field {} -unconstrained pub fn emit_encrypted_log(contract_address: AztecAddress, storage_slot: Field, encryption_pub_key: Point, preimage: [Field; N]) -> [Field; NUM_FIELDS_PER_SHA256] { +unconstrained pub fn emit_encrypted_log( + contract_address: AztecAddress, + storage_slot: Field, + encryption_pub_key: GrumpkinPoint, + preimage: [Field; N] +) -> [Field; NUM_FIELDS_PER_SHA256] { [emit_encrypted_log_oracle(contract_address, storage_slot, encryption_pub_key, preimage), 0] } #[oracle(emitUnencryptedLog)] fn emit_unencrypted_log_oracle(_contract_address: AztecAddress, _event_selector: Field, _message: T) -> Field {} -unconstrained pub fn emit_unencrypted_log(contract_address: AztecAddress, event_selector: Field, message: T) -> [Field; NUM_FIELDS_PER_SHA256] { +unconstrained pub fn emit_unencrypted_log( + contract_address: AztecAddress, + event_selector: Field, + message: T +) -> [Field; NUM_FIELDS_PER_SHA256] { // https://github.com/AztecProtocol/aztec-packages/issues/885 [emit_unencrypted_log_oracle(contract_address, event_selector, message), 0] } diff --git a/yarn-project/aztec-nr/aztec/src/types.nr b/yarn-project/aztec-nr/aztec/src/types.nr index 268c6a8f8ce..18f6888ae32 100644 --- a/yarn-project/aztec-nr/aztec/src/types.nr +++ b/yarn-project/aztec-nr/aztec/src/types.nr @@ -1,3 +1,2 @@ -mod point; mod vec; // This can/should be moved out into an official noir library mod type_serialization; diff --git a/yarn-project/aztec-nr/aztec/src/types/point.nr b/yarn-project/aztec-nr/aztec/src/types/point.nr deleted file mode 100644 index f50be1fe2bb..00000000000 --- a/yarn-project/aztec-nr/aztec/src/types/point.nr +++ /dev/null @@ -1,27 +0,0 @@ -use crate::types::type_serialization::TypeSerializationInterface; - -struct Point { - x: Field, - y: Field, -} - -impl Point { - pub fn new(x: Field, y: Field) -> Self { - Point { x, y } - } -} - -global POINT_SERIALIZED_LEN: Field = 2; - -fn deserializePoint(fields: [Field; POINT_SERIALIZED_LEN]) -> Point { - Point { x: fields[0], y: fields[1] } -} - -fn serializePoint(point: Point) -> [Field; POINT_SERIALIZED_LEN] { - [point.x, point.y] -} - -global PointSerializationMethods = TypeSerializationInterface { - deserialize: deserializePoint, - serialize: serializePoint, -}; diff --git a/yarn-project/noir-contracts/src/contracts/card_game_contract/src/cards.nr b/yarn-project/noir-contracts/src/contracts/card_game_contract/src/cards.nr index 4f524ef95c0..255834dbeb6 100644 --- a/yarn-project/noir-contracts/src/contracts/card_game_contract/src/cards.nr +++ b/yarn-project/noir-contracts/src/contracts/card_game_contract/src/cards.nr @@ -1,5 +1,10 @@ -use dep::protocol_types::constants::{MAX_NOTES_PER_PAGE, MAX_READ_REQUESTS_PER_CALL}; -use dep::protocol_types::address::AztecAddress; +use dep::protocol_types::{ + address::AztecAddress, + constants::{ + MAX_NOTES_PER_PAGE, + MAX_READ_REQUESTS_PER_CALL, + }, +}; use dep::aztec::{ context::{PrivateContext, PublicContext, Context}, note::{ @@ -9,7 +14,6 @@ use dep::aztec::{ }, oracle::get_secret_key::get_secret_key, state_vars::set::Set, - types::point::Point, }; use dep::std; use dep::std::{ @@ -88,7 +92,10 @@ struct Deck { set: Set, } -pub fn filter_cards(notes: [Option; MAX_READ_REQUESTS_PER_CALL], desired_cards: [Card; N]) -> [Option; MAX_READ_REQUESTS_PER_CALL] { +pub fn filter_cards( + notes: [Option; MAX_READ_REQUESTS_PER_CALL], + desired_cards: [Card; N] +) -> [Option; MAX_READ_REQUESTS_PER_CALL] { let mut selected = [Option::none(); MAX_READ_REQUESTS_PER_CALL]; let mut found = [false; N]; @@ -210,8 +217,10 @@ pub fn get_pack_cards(seed: Field, owner: AztecAddress) -> [Card; PACK_CARDS] { } pub fn compute_deck_strength(cards: [Card; N]) -> Field { - cards.fold(0, + cards.fold( + 0, |acc, card: Card| { acc + card.strength as Field - }) + } + ) } diff --git a/yarn-project/noir-contracts/src/contracts/inclusion_proofs_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/inclusion_proofs_contract/src/main.nr index 8a0d20bd5ce..6b5f635b245 100644 --- a/yarn-project/noir-contracts/src/contracts/inclusion_proofs_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/inclusion_proofs_contract/src/main.nr @@ -6,7 +6,7 @@ contract InclusionProofs { AztecAddress, EthAddress, }, - point::Point, + grumpkin_point::GrumpkinPoint, }; use dep::aztec::{ state_vars::{ @@ -211,7 +211,7 @@ contract InclusionProofs { // contract's aztec address instead of just the address. #[aztec(private)] fn test_contract_inclusion_proof( - deployer_public_key: Point, + deployer_public_key: GrumpkinPoint, contract_address_salt: Field, function_tree_root: Field, constructor_hash: Field, diff --git a/yarn-project/noir-contracts/src/contracts/schnorr_hardcoded_account_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/schnorr_hardcoded_account_contract/src/main.nr index 70af212ca67..faef2015a90 100644 --- a/yarn-project/noir-contracts/src/contracts/schnorr_hardcoded_account_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/schnorr_hardcoded_account_contract/src/main.nr @@ -4,8 +4,8 @@ contract SchnorrHardcodedAccount { use dep::std; use dep::aztec::{ abi::{ PrivateCircuitPublicInputs, PrivateContextInputs, Hasher }, - types::{ vec::BoundedVec, point::Point }, context::PrivateContext, + types::vec::BoundedVec, }; use dep::authwit:: { @@ -58,10 +58,12 @@ contract SchnorrHardcodedAccount { } // Verify signature using hardcoded public key - let verification = std::schnorr::verify_signature(public_key_x, + let verification = std::schnorr::verify_signature( + public_key_x, public_key_y, signature, - message_hash.to_be_bytes(32)); + message_hash.to_be_bytes(32) + ); assert(verification == true); true } diff --git a/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/auth_oracle.nr b/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/auth_oracle.nr index 5b6b3dd7219..35aff5d7cca 100644 --- a/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/auth_oracle.nr +++ b/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/auth_oracle.nr @@ -1,10 +1,13 @@ -use dep::aztec::types::point::Point; use dep::authwit::auth_witness; +use dep::protocol_types::{ + address::PartialAddress, + grumpkin_point::GrumpkinPoint, +}; struct AuthWitness { - owner: Point, + owner: GrumpkinPoint, signature: [u8; 64], - partial_address: Field, + partial_address: PartialAddress, } impl AuthWitness { @@ -14,9 +17,9 @@ impl AuthWitness { signature[i] = values[i + 2] as u8; } Self { - owner: Point::new(values[0], values[1]), + owner: GrumpkinPoint::new(values[0], values[1]), signature, - partial_address: values[66], + partial_address: PartialAddress::from_field(values[66]), } } } diff --git a/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/util.nr b/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/util.nr index 3a097cbd5dc..963b721f71d 100644 --- a/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/util.nr +++ b/yarn-project/noir-contracts/src/contracts/schnorr_single_key_account_contract/src/util.nr @@ -12,5 +12,5 @@ pub fn recover_address(message_hash: Field, witness: AuthWitness) -> AztecAddres ); assert(verification == true); - AztecAddress::compute(witness.owner.x, witness.owner.y, witness.partial_address) + AztecAddress::compute(witness.owner, witness.partial_address) } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/complete_address.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/complete_address.nr index 1bf1ed8dfe0..5a76fb03591 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/complete_address.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/complete_address.nr @@ -1,27 +1,30 @@ -use crate::point::Point; -use crate::address::AztecAddress; -use crate::hash::{compute_partial_address,compute_contract_address_from_partial}; +use crate::{ + address::{ + AztecAddress, + PartialAddress, + }, + grumpkin_point::GrumpkinPoint, +}; -struct CompleteAddress{ +struct CompleteAddress { address : AztecAddress, - public_key : Point, - // TODO(David): Can we type this as AztecAddress instead of Field? - partial_address: Field, + public_key : GrumpkinPoint, + partial_address: PartialAddress, } impl CompleteAddress{ fn assert_is_zero(self) { self.address.assert_is_zero(); self.public_key.assert_is_zero(); - assert(self.partial_address == 0); + self.partial_address.assert_is_zero(); } - pub fn compute(point : Point, contract_address_salt : Field, function_tree_root : Field, constructor_hash : Field) -> CompleteAddress { - let partial_address = compute_partial_address(contract_address_salt, function_tree_root, constructor_hash); + pub fn compute(public_key : GrumpkinPoint, contract_address_salt : Field, function_tree_root : Field, constructor_hash : Field) -> CompleteAddress { + let partial_address = PartialAddress::compute(contract_address_salt, function_tree_root, constructor_hash); CompleteAddress{ - address : compute_contract_address_from_partial(point, partial_address), - public_key : point, + address : AztecAddress::compute(public_key, partial_address), + public_key, partial_address, } } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/address.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/address.nr index 30d761df875..b60330d0c40 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/address.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/address.nr @@ -1,7 +1,11 @@ use crate::{ - constants::GENERATOR_INDEX__CONTRACT_ADDRESS, + constants::{ + GENERATOR_INDEX__CONTRACT_ADDRESS, + GENERATOR_INDEX__PARTIAL_ADDRESS, + }, hash::pedersen_hash, utils, + grumpkin_point::GrumpkinPoint, }; // Aztec address @@ -28,10 +32,10 @@ impl AztecAddress { } } - pub fn compute(pub_key_x: Field, pub_key_y: Field, partial_address: Field) -> AztecAddress { + pub fn compute(pub_key: GrumpkinPoint, partial_address: PartialAddress) -> AztecAddress { AztecAddress::from_field( pedersen_hash( - [pub_key_x, pub_key_y, partial_address], + [pub_key.x, pub_key.y, partial_address.to_field()], GENERATOR_INDEX__CONTRACT_ADDRESS ) ) @@ -128,3 +132,36 @@ impl EthAddress{ } } +// Partial address +struct PartialAddress { + inner : Field +} + +impl PartialAddress { + pub fn from_field(field : Field) -> Self { + Self { + inner : field + } + } + + pub fn compute(contract_address_salt : Field, function_tree_root : Field, constructor_hash : Field) -> Self { + PartialAddress::from_field( + pedersen_hash([ + // TODO why the zeroes? + 0, + 0, + contract_address_salt, + function_tree_root, + constructor_hash + ], GENERATOR_INDEX__PARTIAL_ADDRESS) + ) + } + + pub fn to_field(self) -> Field { + self.inner + } + + pub fn assert_is_zero(self) { + assert(self.to_field() == 0); + } +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/deployment_data.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/deployment_data.nr index c20a49d78d3..5369de614fc 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/deployment_data.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/contrakt/deployment_data.nr @@ -4,11 +4,11 @@ use crate::constants::{ GENERATOR_INDEX__CONTRACT_DEPLOYMENT_DATA, }; use crate::hash::pedersen_hash; -use crate::point::Point; +use crate::grumpkin_point::GrumpkinPoint; // docs:start:contract-deployment-data struct ContractDeploymentData { - deployer_public_key : Point, + deployer_public_key : GrumpkinPoint, constructor_vk_hash : Field, function_tree_root : Field, contract_address_salt : Field, diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/point.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/grumpkin_point.nr similarity index 66% rename from yarn-project/noir-protocol-circuits/src/crates/types/src/point.nr rename to yarn-project/noir-protocol-circuits/src/crates/types/src/grumpkin_point.nr index 1f6b5da720e..364d19a1549 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/point.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/grumpkin_point.nr @@ -1,20 +1,23 @@ -// TODO: change this to be called Grumpkin Point -struct Point { +global GRUMPKIN_POINT_SERIALIZED_LEN: Field = 2; + +struct GrumpkinPoint { x: Field, y: Field, } -global POINT_SERIALIZED_LEN: Field = 2; +impl GrumpkinPoint { + pub fn new(x: Field, y: Field) -> Self { + Self { x, y } + } -impl Point { pub fn zero() -> Self { - Point { + Self { x: 0, y: 0, } } - fn serialize(self) -> [Field; POINT_SERIALIZED_LEN] { + fn serialize(self) -> [Field; GRUMPKIN_POINT_SERIALIZED_LEN] { [self.x, self.y] } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/hash.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/hash.nr index e9457f53b93..ca40eaae4dc 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/hash.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/hash.nr @@ -1,6 +1,5 @@ use crate::address::{AztecAddress, EthAddress}; use crate::mocked::VerificationKey; -use crate::point::Point; use crate::abis::function_selector::FunctionSelector; use crate::abis::function_leaf_preimage::FunctionLeafPreimage; use crate::abis::new_contract_data::NewContractData as ContractLeafPreimage; @@ -250,26 +249,6 @@ pub fn compute_logs_hash(previous_log_hash : [Field;2], current_log_hash : [Fiel ]) } -pub fn compute_partial_address(contract_address_salt : Field, function_tree_root : Field, constructor_hash : Field) -> Field { - pedersen_hash([ - // TODO why the zeroes? - 0, - 0, - contract_address_salt, - function_tree_root, - constructor_hash - ], GENERATOR_INDEX__PARTIAL_ADDRESS) -} - -pub fn compute_contract_address_from_partial(point : Point, partial_address : Field) -> AztecAddress { - let field = pedersen_hash([ - point.x, - point.y, - partial_address - ], GENERATOR_INDEX__CONTRACT_ADDRESS); - AztecAddress::from_field(field) -} - pub fn compute_commitment_nonce(first_nullifier : Field, commitment_index : Field) -> Field { pedersen_hash([ first_nullifier, diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/interop_testing.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/interop_testing.nr index 58b7b0cd9a3..c764e5bfc0f 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/interop_testing.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/interop_testing.nr @@ -1,5 +1,5 @@ use crate::abis::complete_address::CompleteAddress; -use crate::point::Point; +use crate::grumpkin_point::GrumpkinPoint; use crate::transaction::request::TxRequest; use crate::address::{AztecAddress, EthAddress}; use crate::transaction::context::TxContext; @@ -13,48 +13,50 @@ use crate::abis::public_circuit_public_inputs::PublicCircuitPublicInputs; #[test] fn compute_complete_address() { - let point = Point{ - x : 1, - y : 2 - }; + let point = GrumpkinPoint { x: 1, y: 2 }; let contract_address_salt = 3; let function_tree_root = 4; let constructor_hash = 5; - - let complete_address = CompleteAddress::compute(point, contract_address_salt, function_tree_root, constructor_hash); - - assert(complete_address.partial_address == 0x197673f31940878b2d6c681223dbed9cfacd2f722cbe30155225b2ada17778db); - assert(complete_address.address.to_field() == 0x1a6e89b034478713c7a9f1c77fb80af995f708f6f208bf352b4dda2124739109); + + let complete_address = CompleteAddress::compute( + point, + contract_address_salt, + function_tree_root, + constructor_hash + ); + + assert( + complete_address.partial_address.to_field() + == 0x197673f31940878b2d6c681223dbed9cfacd2f722cbe30155225b2ada17778db + ); + assert( + complete_address.address.to_field() + == 0x1a6e89b034478713c7a9f1c77fb80af995f708f6f208bf352b4dda2124739109 + ); assert(complete_address.public_key.x == 1); assert(complete_address.public_key.y == 2); } - #[test] fn compute_tx_request_hash() { let tx_request = TxRequest { - origin : AztecAddress::from_field(1), - args_hash : 3, - tx_context : TxContext { - is_fee_payment_tx : false, - is_rebate_payment_tx : false, - is_contract_deployment_tx : true, - contract_deployment_data : ContractDeploymentData{ - deployer_public_key : Point{x : 1, y : 2}, - constructor_vk_hash : 1, - function_tree_root : 2, - contract_address_salt : 3, - portal_contract_address : EthAddress::from_field(1), + origin: AztecAddress::from_field(1), + args_hash: 3, + tx_context: TxContext { + is_fee_payment_tx: false, + is_rebate_payment_tx: false, + is_contract_deployment_tx: true, + contract_deployment_data: ContractDeploymentData { + deployer_public_key: GrumpkinPoint { x: 1, y: 2 }, + constructor_vk_hash: 1, + function_tree_root: 2, + contract_address_salt: 3, + portal_contract_address: EthAddress::from_field(1) }, - chain_id : 0, - version : 0, + chain_id: 0, + version: 0 }, - function_data : FunctionData { - selector : FunctionSelector::from_u32(2), - is_internal : false, - is_private : true, - is_constructor : true, - } + function_data: FunctionData { selector: FunctionSelector::from_u32(2), is_internal: false, is_private: true, is_constructor: true } }; assert(tx_request.hash() == 0x0b487ff2900ae1178e131bfe333fdbc351beef658f7c0d62db2801429b1aab75); } @@ -62,8 +64,8 @@ fn compute_tx_request_hash() { #[test] fn compute_l2_l1_hash() { // All zeroes - let hash_result = compute_l2_to_l1_hash(AztecAddress::from_field(0), 0, EthAddress::from_field(0), 0, 0); - assert(hash_result == 0x2266ac2f9f0c19c015239ef5ea85862fc6fac00db73779b220a4d49c4856c2e1); + let hash_result = compute_l2_to_l1_hash(AztecAddress::from_field(0), 0, EthAddress::from_field(0), 0, 0); + assert(hash_result == 0x2266ac2f9f0c19c015239ef5ea85862fc6fac00db73779b220a4d49c4856c2e1); // Non-zero case let hash_result = compute_l2_to_l1_hash(AztecAddress::from_field(1), 2, EthAddress::from_field(3), 4, 5); @@ -83,18 +85,12 @@ fn smoke_sha256_to_field() { 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159 ]; let result = sha256_to_field(full_buffer); - assert( result == 0x142a6d57007171f6eaa33d55976d9dbe739c889c8e920f115f7808dea184c718); + assert(result == 0x142a6d57007171f6eaa33d55976d9dbe739c889c8e920f115f7808dea184c718); } #[test] fn compute_function_leaf() { - let leaf = FunctionLeafPreimage { - selector: FunctionSelector::from_u32(27), - is_internal: false, - is_private: true, - vk_hash: 1, - acir_hash: 2, - }; + let leaf = FunctionLeafPreimage { selector: FunctionSelector::from_u32(27), is_internal: false, is_private: true, vk_hash: 1, acir_hash: 2 }; assert_eq(leaf.hash(), 0x1ad8ece7f40e63d011ae47c6ce6cdaf31d632a23f5cf35bbeaaf69c8302afdbc); } @@ -102,22 +98,12 @@ fn compute_function_leaf() { #[test] fn compute_call_stack_item_request() { let contract_address = AztecAddress::from_field(1); - let function_data = FunctionData { - selector: FunctionSelector::from_u32(2), - is_internal: false, - is_private: false, - is_constructor: false, - }; + let function_data = FunctionData { selector: FunctionSelector::from_u32(2), is_internal: false, is_private: false, is_constructor: false }; let mut public_inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); public_inputs.new_commitments[0] = 1; - let call_stack_item = PublicCallStackItem { - contract_address, - public_inputs, - is_execution_request: true, - function_data, - }; + let call_stack_item = PublicCallStackItem { contract_address, public_inputs, is_execution_request: true, function_data }; assert_eq(call_stack_item.hash(), 0x1d51d7758d792c9cd6edd8e8ec5f1f9fb1f974abc1af6bb4cf9f2328ef306c96); } @@ -125,22 +111,12 @@ fn compute_call_stack_item_request() { #[test] fn compute_call_stack_item() { let contract_address = AztecAddress::from_field(1); - let function_data = FunctionData { - selector: FunctionSelector::from_u32(2), - is_internal: false, - is_private: false, - is_constructor: false, - }; + let function_data = FunctionData { selector: FunctionSelector::from_u32(2), is_internal: false, is_private: false, is_constructor: false }; let mut public_inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed(); public_inputs.new_commitments[0] = 1; - let call_stack_item = PublicCallStackItem { - contract_address, - public_inputs, - is_execution_request: false, - function_data, - }; + let call_stack_item = PublicCallStackItem { contract_address, public_inputs, is_execution_request: false, function_data }; assert_eq(call_stack_item.hash(), 0x0a370c67b66e30901470c11a199764a914fc0fcfbc737ed03153079b2765813a); } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/lib.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/lib.nr index 53d1f07fa70..bde59b6156c 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/lib.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/lib.nr @@ -1,6 +1,6 @@ mod utils; mod address; -mod point; +mod grumpkin_point; // This is intentionally spelled like this // since contract is a reserved keyword, so it cannot // be used as an ident. diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr index 48cc27863d2..8b824658236 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures.nr @@ -6,12 +6,12 @@ mod read_requests; use crate::address::AztecAddress; use crate::abis::block_header::BlockHeader; -use crate::point::Point; +use crate::grumpkin_point::GrumpkinPoint; use crate::tests::fixtures; global MSG_SENDER = AztecAddress { inner: 27 }; -global DEPLOYER_PUBLIC_KEY = Point { x: 123456789, y: 123456789 }; +global DEPLOYER_PUBLIC_KEY = GrumpkinPoint { x: 123456789, y: 123456789 }; global BLOCK_HEADER = BlockHeader { note_hash_tree_root: fixtures::note_hash_tree::ROOT,