diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr index b858bfdaa1db..c7e8e51e0280 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/encrypted_event_emission.nr @@ -1,7 +1,6 @@ use crate::{ context::PrivateContext, event::event_interface::EventInterface, - encrypted_logs::payload::compute_encrypted_log, - keys::getters::get_ovsk_app, oracle::random::random + encrypted_logs::payload::compute_encrypted_log, keys::getters::get_ovsk_app, oracle::random::random }; use dep::protocol_types::{address::{AztecAddress, public_keys::{OvpkM, IvpkM}}, hash::sha256_to_field}; diff --git a/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr b/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr index 7b7d826a00ca..6d7f767541ce 100644 --- a/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr +++ b/noir-projects/aztec-nr/aztec/src/encrypted_logs/payload.nr @@ -25,9 +25,7 @@ pub fn compute_encrypted_log( let header = EncryptedLogHeader::new(contract_address); let address_point = recipient.to_point(); - let address_ivpk = IvpkM { - inner: address_point, - }; + let address_ivpk = IvpkM { inner: address_point }; let incoming_header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, address_ivpk); let outgoing_header_ciphertext: [u8; 48] = header.compute_ciphertext(eph_sk, ovpk); diff --git a/noir-projects/aztec-nr/aztec/src/keys/getters/mod.nr b/noir-projects/aztec-nr/aztec/src/keys/getters/mod.nr index 23714fa2ce52..694f22629bfc 100644 --- a/noir-projects/aztec-nr/aztec/src/keys/getters/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/keys/getters/mod.nr @@ -24,9 +24,10 @@ pub fn get_public_keys(account: AztecAddress) -> PublicKeys { let (hinted_canonical_public_keys, partial_address) = unsafe { get_public_keys_and_partial_address(account) }; - // assert_eq( - // account, AztecAddress::compute(hinted_canonical_public_keys.hash(), partial_address), "Invalid public keys hint for address" - // ); + + assert_eq( + account, AztecAddress::compute_from_public_keys(hinted_canonical_public_keys, partial_address), "Invalid public keys hint for address" + ); hinted_canonical_public_keys } diff --git a/noir-projects/aztec-nr/aztec/src/oracle/get_contract_instance.nr b/noir-projects/aztec-nr/aztec/src/oracle/get_contract_instance.nr index 1c941247e732..392e85c189fa 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/get_contract_instance.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/get_contract_instance.nr @@ -24,7 +24,7 @@ pub fn get_contract_instance(address: AztecAddress) -> ContractInstance { }; // The to_address function combines all values in the instance object to produce an address, so by checking that we // get the expected address we validate the entire struct. - // assert_eq(instance.to_address(), address); + assert_eq(instance.to_address(), address); instance } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator.nr index 26e6e7d89714..9628ed548dcf 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/components/private_call_data_validator.nr @@ -195,12 +195,12 @@ impl PrivateCallDataValidator { ); // println(f"computed_partial_address={computed_partial_address}"); - let computed_address = AztecAddress::compute(self.data.public_keys_hash, computed_partial_address); + let computed_address = AztecAddress::compute_from_public_keys(self.data.public_keys, computed_partial_address); // println(f"computed_address={computed_address}"); - // assert( - // !computed_address.eq(contract_address), "computed contract address does not match expected one" - // ); + assert( + computed_address.eq(contract_address), "computed contract address does not match expected one" + ); } fn validate_call(self) { diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_contract_address.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_contract_address.nr index b14ab5cef718..d5eb746c1542 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_contract_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/private_call_data_validator_builder/validate_contract_address.nr @@ -56,7 +56,7 @@ fn validate_contract_address_incorrect_partial_address_preimage_fails() { fn validate_contract_address_incorrect_address_preimage_fails() { let mut builder = PrivateCallDataValidatorBuilder::new(); - builder.private_call.public_keys_hash.inner = builder.private_call.public_keys_hash.inner + 1; + builder.private_call.public_keys.ivpk_m.inner.x = builder.private_call.public_keys.ivpk_m.inner.x + 1; builder.validate(); } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr index b60eed12cad0..cdf4d0fd527a 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_kernel/private_call_data.nr @@ -1,6 +1,6 @@ use crate::{ abis::{private_call_stack_item::PrivateCallStackItem}, - address::{SaltedInitializationHash, PublicKeysHash}, constants::FUNCTION_TREE_HEIGHT, + address::{SaltedInitializationHash, PublicKeysHash, PublicKeys}, constants::FUNCTION_TREE_HEIGHT, merkle_tree::membership::MembershipWitness, recursion::{verification_key::VerificationKey} }; @@ -10,7 +10,7 @@ pub struct PrivateCallData { vk: VerificationKey, salted_initialization_hash: SaltedInitializationHash, - public_keys_hash: PublicKeysHash, + public_keys: PublicKeys, contract_class_artifact_hash: Field, contract_class_public_bytecode_commitment: Field, function_leaf_membership_witness: MembershipWitness, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr index 565ef1d67255..b448abe81f60 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr @@ -1,5 +1,5 @@ use crate::{ - address::{partial_address::PartialAddress, public_keys_hash::PublicKeysHash}, + address::{partial_address::PartialAddress, public_keys::PublicKeys, public_keys_hash::PublicKeysHash}, constants::{AZTEC_ADDRESS_LENGTH, GENERATOR_INDEX__CONTRACT_ADDRESS_V1}, hash::poseidon2_hash_with_separator, traits::{Empty, FromField, ToField, Serialize, Deserialize}, utils @@ -10,8 +10,11 @@ global BN254_FR_MODULUS_DIV_2: Field = 10944121435919637611123202872628637544274 // We do below because `use crate::point::Point;` does not work use dep::std::embedded_curve_ops::EmbeddedCurvePoint as Point; -use std::ec::{sqrt, pow}; -use crate::debug_log::debug_log_format; +use std::{ + ec::{sqrt, pow}, + embedded_curve_ops::{fixed_base_scalar_mul as derive_public_key, EmbeddedCurveScalar} +}; +use crate::constants::GENERATOR_INDEX__PUBLIC_KEYS_HASH; // Aztec address pub struct AztecAddress { @@ -68,6 +71,32 @@ impl AztecAddress { ) } + pub fn compute_from_public_keys(public_keys: PublicKeys, partial_address: PartialAddress) -> AztecAddress { + let public_keys_hash = public_keys.hash(); + + let pre_address = poseidon2_hash_with_separator( + [public_keys_hash.to_field(), partial_address.to_field()], + GENERATOR_INDEX__CONTRACT_ADDRESS_V1 + ); + + let address_point = derive_public_key(EmbeddedCurveScalar::from_field(pre_address)).add(public_keys.ivpk_m.to_point()); + AztecAddress::from_field(address_point.x) + } + + pub fn compute_new( + public_keys_hash: PublicKeysHash, + partial_address: PartialAddress, + ivpk_m: Point + ) -> AztecAddress { + let pre_address = poseidon2_hash_with_separator( + [public_keys_hash.to_field(), partial_address.to_field()], + GENERATOR_INDEX__CONTRACT_ADDRESS_V1 + ); + + let address_point = derive_public_key(EmbeddedCurveScalar::from_field(pre_address)).add(ivpk_m); + AztecAddress::from_field(address_point.x) + } + pub fn is_zero(self) -> bool { self.inner == 0 } @@ -100,11 +129,7 @@ impl AztecAddress { y = (BN254_FR_MODULUS_DIV_2 + BN254_FR_MODULUS_DIV_2 + 1) - y; } - Point { - x: self.inner, - y, - is_infinite: false - } + Point { x: self.inner, y, is_infinite: false } } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 2f86635ef9c3..2ec5f24ae616 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -221,7 +221,7 @@ global GAS_LENGTH: u32 = 2; global GAS_SETTINGS_LENGTH: u32 = GAS_LENGTH * 2 + GAS_FEES_LENGTH + /* inclusion_fee */ 1; global CALL_CONTEXT_LENGTH: u32 = 5; global CONTENT_COMMITMENT_LENGTH: u32 = 4; -global CONTRACT_INSTANCE_LENGTH: u32 = 5; +global CONTRACT_INSTANCE_LENGTH: u32 = 8; global CONTRACT_STORAGE_READ_LENGTH: u32 = 3; global CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH: u32 = 3; global ETH_ADDRESS_LENGTH: u32 = 1; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/contract_instance.nr b/noir-projects/noir-protocol-circuits/crates/types/src/contract_instance.nr index c10fa38c944b..c7518ae823b4 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/contract_instance.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/contract_instance.nr @@ -4,12 +4,16 @@ use crate::{ traits::{Deserialize, Hash, Serialize} }; +use dep::std::embedded_curve_ops::EmbeddedCurvePoint as Point; + pub struct ContractInstance { salt : Field, deployer: AztecAddress, contract_class_id : ContractClassId, initialization_hash : Field, public_keys_hash : PublicKeysHash, + // Refactor this to use the correct type + ivpk_m: Point, } impl Eq for ContractInstance { @@ -18,6 +22,7 @@ impl Eq for ContractInstance { & self.initialization_hash.eq(other.initialization_hash) & self.contract_class_id.eq(other.contract_class_id) & self.salt.eq(other.salt) + & self.ivpk_m.eq(other.ivpk_m) } } @@ -28,7 +33,10 @@ impl Serialize for ContractInstance { self.deployer.to_field(), self.contract_class_id.to_field(), self.initialization_hash, - self.public_keys_hash.to_field() + self.public_keys_hash.to_field(), + self.ivpk_m.x, + self.ivpk_m.y, + self.ivpk_m.is_infinite as Field ] } } @@ -40,7 +48,8 @@ impl Deserialize for ContractInstance { deployer: AztecAddress::from_field(serialized[1]), contract_class_id: ContractClassId::from_field(serialized[2]), initialization_hash: serialized[3], - public_keys_hash: PublicKeysHash::from_field(serialized[4]) + public_keys_hash: PublicKeysHash::from_field(serialized[4]), + ivpk_m: Point { x: serialized[5], y: serialized[6], is_infinite: serialized[7] as bool } } } } @@ -53,14 +62,15 @@ impl Hash for ContractInstance { impl ContractInstance { fn to_address(self) -> AztecAddress { - AztecAddress::compute( + AztecAddress::compute_new( self.public_keys_hash, PartialAddress::compute( self.contract_class_id, self.salt, self.initialization_hash, self.deployer - ) + ), + self.ivpk_m ) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr index 1bd4a1c6e1bb..82b1b96211f9 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr @@ -30,7 +30,7 @@ use crate::{ ScopedKeyValidationRequestAndGenerator } }, - address::{AztecAddress, EthAddress, SaltedInitializationHash, PublicKeysHash}, + address::{AztecAddress, EthAddress, SaltedInitializationHash, PublicKeysHash, PublicKeys}, constants::{ FUNCTION_TREE_HEIGHT, MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_TX, MAX_L2_TO_L1_MSGS_PER_TX, MAX_PUBLIC_DATA_READS_PER_CALL, @@ -134,7 +134,7 @@ pub struct FixtureBuilder { // Private call. salted_initialization_hash: SaltedInitializationHash, - public_keys_hash: PublicKeysHash, + public_keys: PublicKeys, contract_class_artifact_hash: Field, contract_class_public_bytecode_commitment: Field, function_leaf_membership_witness: MembershipWitness, @@ -182,7 +182,7 @@ impl FixtureBuilder { builder.function_data = contract_function.data; builder.function_leaf_membership_witness = contract_function.membership_witness; builder.salted_initialization_hash = contract_data.salted_initialization_hash; - builder.public_keys_hash = contract_data.public_keys_hash; + builder.public_keys = contract_data.public_keys; builder.contract_class_artifact_hash = contract_data.artifact_hash; builder.contract_class_public_bytecode_commitment = contract_data.public_bytecode_commitment; builder.acir_hash = contract_function.acir_hash; @@ -319,7 +319,7 @@ impl FixtureBuilder { vk: self.vk, function_leaf_membership_witness: self.function_leaf_membership_witness, salted_initialization_hash: self.salted_initialization_hash, - public_keys_hash: self.public_keys_hash, + public_keys: self.public_keys, contract_class_artifact_hash: self.contract_class_artifact_hash, contract_class_public_bytecode_commitment: self.contract_class_public_bytecode_commitment, acir_hash: self.acir_hash @@ -1220,7 +1220,7 @@ impl Empty for FixtureBuilder { returns_hash: 0, function_leaf_membership_witness: MembershipWitness::empty(), salted_initialization_hash: SaltedInitializationHash::from_field(0), - public_keys_hash: PublicKeysHash::from_field(0), + public_keys: PublicKeys::empty(), contract_class_artifact_hash: 0, contract_class_public_bytecode_commitment: 0, acir_hash: 0, diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/contracts.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/contracts.nr index 319ffb287e18..3d5ef0098c74 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/contracts.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixtures/contracts.nr @@ -1,5 +1,5 @@ use crate::{ - address::{AztecAddress, PublicKeysHash, SaltedInitializationHash, PartialAddress}, + address::{AztecAddress, PublicKeysHash, SaltedInitializationHash, PartialAddress, PublicKeys}, contract_class_id::ContractClassId }; @@ -10,7 +10,7 @@ pub struct ContractData { contract_class_id: ContractClassId, private_functions_root: Field, public_bytecode_commitment: Field, - public_keys_hash: PublicKeysHash, + public_keys: PublicKeys, salted_initialization_hash: SaltedInitializationHash, partial_address: PartialAddress, deployer: AztecAddress, @@ -25,7 +25,7 @@ global default_contract = ContractData { address: AztecAddress { inner: 0x0e66d7cd9692428c550b93c9ef5f49ca9f02c03e98cb3c922d8c773f78f79fed }, partial_address: PartialAddress { inner: 0x0cf203c94c91bed28440b00ecd888d88cce1f86ddf2aa8d33acbb9b6fc06d382 }, contract_class_id: ContractClassId { inner: 0x28e91aaf764bc6083e2796ff884079ad895d4b948d6ce8f37f01b29d0bc95a21 }, - public_keys_hash: PublicKeysHash { inner: 0x000000000000000000000000000000000000000000000000000000000000b26e }, + public_keys: PublicKeys::empty(), salted_initialization_hash: SaltedInitializationHash { inner: 0x13a939daa511233e5446905ed2cadbee14948fa75df183b53b5c14b612bffe88 }, deployer: AztecAddress { inner: 0x0000000000000000000000000000000000000000000000000000000000000000 } }; @@ -39,7 +39,7 @@ global parent_contract = ContractData { address: AztecAddress { inner: 0x24415b2e716d6c7099580ab8e383fd5b16dc9fb441aa308571d8e24a2257da24 }, partial_address: PartialAddress { inner: 0x245df9f519d616473880260dd64b19a838081bb44dc17cd6ea5d870a63d2bf57 }, contract_class_id: ContractClassId { inner: 0x00236b0dc6c537d5106543053c5b85c4cbe95b0474f8238b094bae63f1cbcfee }, - public_keys_hash: PublicKeysHash { inner: 0x00000000000000000000000000000000000000000000000000000000000011c1 }, + public_keys: PublicKeys::empty(), salted_initialization_hash: SaltedInitializationHash { inner: 0x24bd6ac7a182e2cf25e437c72f53544ef81dfd97d9afee23abb07a638e7be749 }, deployer: AztecAddress { inner: 0x0000000000000000000000000000000000000000000000000000000000000000 } }; diff --git a/yarn-project/aztec.js/src/account_manager/index.ts b/yarn-project/aztec.js/src/account_manager/index.ts index a3b8c6801bc4..aa2f6663c252 100644 --- a/yarn-project/aztec.js/src/account_manager/index.ts +++ b/yarn-project/aztec.js/src/account_manager/index.ts @@ -33,7 +33,6 @@ export class AccountManager { // TODO(@spalladino): Does it make sense to have both completeAddress and instance? private completeAddress: CompleteAddress; private instance: ContractInstanceWithAddress; - private publicKeysHash?: Fr; constructor(private pxe: PXE, private secretKey: Fr, private accountContract: AccountContract, salt?: Salt) { this.salt = salt !== undefined ? new Fr(salt) : Fr.random(); @@ -47,15 +46,10 @@ export class AccountManager { }); this.completeAddress = CompleteAddress.fromSecretKeyAndInstance(this.secretKey, this.instance); - - this.instance.address = this.completeAddress.address; } protected getPublicKeysHash() { - if (!this.publicKeysHash) { - this.publicKeysHash = deriveKeys(this.secretKey).publicKeys.hash(); - } - return this.publicKeysHash; + return deriveKeys(this.secretKey).publicKeys.hash(); } /** @@ -74,10 +68,6 @@ export class AccountManager { * @returns The address, partial address, and encryption public key. */ public getCompleteAddress(): CompleteAddress { - if (!this.completeAddress) { - const instance = this.getInstance(); - this.completeAddress = CompleteAddress.fromSecretKeyAndInstance(this.secretKey, instance); - } return this.completeAddress; } diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index 12029f9d2939..24f18b5aafb9 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -223,7 +223,7 @@ export class DeployMethod extends Bas this.instance = getContractInstanceFromDeployParams(this.artifact, { constructorArgs: this.args, salt: options.contractAddressSalt, - publicKeysHash: this.publicKeysHash, + publicKeys: this.completeAddress?.publicKeys, constructorArtifact: this.constructorArtifact, deployer: options.universalDeploy ? AztecAddress.ZERO : this.wallet.getAddress(), }); diff --git a/yarn-project/aztec/src/cli/cmds/start_pxe.ts b/yarn-project/aztec/src/cli/cmds/start_pxe.ts index 674657fd3032..e768ea9141e8 100644 --- a/yarn-project/aztec/src/cli/cmds/start_pxe.ts +++ b/yarn-project/aztec/src/cli/cmds/start_pxe.ts @@ -19,6 +19,7 @@ import { import { L2BasicContractsMap, Network } from '@aztec/types/network'; import { extractRelevantOptions } from '../util.js'; +import { Point, PublicKeys } from '@aztec/circuits.js'; const contractAddressesUrl = 'http://static.aztec.network'; @@ -105,6 +106,7 @@ export async function addPXE( deployer: AztecAddress.ZERO, contractClassId: getContractClassFromArtifact(artifact!).id, publicKeysHash: Fr.ZERO, + ivpkM: Point.ZERO, }; userLog(`Registering ${name} at ${address.toString()}`); await pxe.registerContract({ artifact, instance }); diff --git a/yarn-project/bb-prover/src/avm_proving.test.ts b/yarn-project/bb-prover/src/avm_proving.test.ts index 20645d878e5f..5b1d22182acc 100644 --- a/yarn-project/bb-prover/src/avm_proving.test.ts +++ b/yarn-project/bb-prover/src/avm_proving.test.ts @@ -1,5 +1,5 @@ import { AvmCircuitInputs, AvmVerificationKeyData, FunctionSelector, Gas, GlobalVariables } from '@aztec/circuits.js'; -import { Fr } from '@aztec/foundation/fields'; +import { Fr, Point } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; import { AvmSimulator, PublicSideEffectTrace, type WorldStateDB } from '@aztec/simulator'; import { @@ -65,6 +65,7 @@ const proveAndVerifyAvmTestContract = async ( contractClassId: new Fr(0x789), initializationHash: new Fr(0x101112), publicKeysHash: new Fr(0x161718), + ivpkM: new Point(new Fr(123), new Fr(456), false), }).withAddress(environment.address); worldStateDB.getContractInstance.mockResolvedValue(Promise.resolve(contractInstance)); diff --git a/yarn-project/circuits.js/src/contract/contract_address.test.ts b/yarn-project/circuits.js/src/contract/contract_address.test.ts index ac6eca063967..87f8a377286d 100644 --- a/yarn-project/circuits.js/src/contract/contract_address.test.ts +++ b/yarn-project/circuits.js/src/contract/contract_address.test.ts @@ -57,7 +57,9 @@ describe('ContractAddress', () => { const contractClassId = new Fr(4n); const initializationHash = new Fr(5n); const deployer = AztecAddress.fromField(new Fr(7)); - const publicKeysHash = deriveKeys(secretKey).publicKeys.hash(); + const { publicKeys } = deriveKeys(secretKey); + + const publicKeysHash = publicKeys.hash(); const address = computeContractAddressFromInstance({ publicKeysHash, @@ -66,6 +68,7 @@ describe('ContractAddress', () => { initializationHash, deployer, version: 1, + ivpkM: publicKeys.masterIncomingViewingPublicKey, }).toString(); expect(address).toMatchSnapshot(); diff --git a/yarn-project/circuits.js/src/contract/events/contract_instance_deployed_event.ts b/yarn-project/circuits.js/src/contract/events/contract_instance_deployed_event.ts index 95376bcd588b..645f1f2597e1 100644 --- a/yarn-project/circuits.js/src/contract/events/contract_instance_deployed_event.ts +++ b/yarn-project/circuits.js/src/contract/events/contract_instance_deployed_event.ts @@ -1,6 +1,6 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; import { toBigIntBE } from '@aztec/foundation/bigint-buffer'; -import { Fr } from '@aztec/foundation/fields'; +import { Fr, Point } from '@aztec/foundation/fields'; import { BufferReader } from '@aztec/foundation/serialize'; import { type ContractInstanceWithAddress } from '@aztec/types/contracts'; @@ -16,6 +16,7 @@ export class ContractInstanceDeployedEvent { public readonly initializationHash: Fr, public readonly publicKeysHash: Fr, public readonly deployer: AztecAddress, + public readonly ivpkM: Point, ) {} static isContractInstanceDeployedEvent(log: Buffer) { @@ -42,6 +43,7 @@ export class ContractInstanceDeployedEvent { const initializationHash = reader.readObject(Fr); const publicKeysHash = reader.readObject(Fr); const deployer = reader.readObject(AztecAddress); + const ivpkM = reader.readObject(Point); return new ContractInstanceDeployedEvent( address, @@ -51,6 +53,7 @@ export class ContractInstanceDeployedEvent { initializationHash, publicKeysHash, deployer, + ivpkM, ); } @@ -67,6 +70,7 @@ export class ContractInstanceDeployedEvent { publicKeysHash: this.publicKeysHash, salt: this.salt, deployer: this.deployer, + ivpkM: this.ivpkM, }; } } diff --git a/yarn-project/circuits.js/src/structs/complete_address.ts b/yarn-project/circuits.js/src/structs/complete_address.ts index dcdd2cfef5ba..d1faebe1642b 100644 --- a/yarn-project/circuits.js/src/structs/complete_address.ts +++ b/yarn-project/circuits.js/src/structs/complete_address.ts @@ -41,7 +41,7 @@ export class CompleteAddress { const { publicKeys, masterIncomingViewingSecretKey } = deriveKeys(secretKey); const oldAddress = computeAddress(publicKeys.hash(), partialAddress); - const combined = masterIncomingViewingSecretKey.add(oldAddress.toFq()); + const combined = masterIncomingViewingSecretKey.add(new Fq(oldAddress.toBigInt())); const addressPoint = derivePublicKeyFromSecretKey(combined); diff --git a/yarn-project/circuits.js/src/structs/kernel/private_call_data.ts b/yarn-project/circuits.js/src/structs/kernel/private_call_data.ts index 14253da6f58d..58b061711c72 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_call_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_call_data.ts @@ -6,6 +6,7 @@ import { FUNCTION_TREE_HEIGHT } from '../../constants.gen.js'; import { MembershipWitness } from '../membership_witness.js'; import { PrivateCallStackItem } from '../private_call_stack_item.js'; import { VerificationKeyAsFields } from '../verification_key.js'; +import { PublicKeys } from '../../types/public_keys.js'; /** * Private call data. @@ -31,7 +32,7 @@ export class PrivateCallData { /** * Public keys hash of the contract instance. */ - public publicKeysHash: Fr, + public publicKeys: PublicKeys, /** * Salted initialization hash of the contract instance. */ @@ -57,7 +58,7 @@ export class PrivateCallData { fields.vk, fields.contractClassArtifactHash, fields.contractClassPublicBytecodeCommitment, - fields.publicKeysHash, + fields.publicKeys, fields.saltedInitializationHash, fields.functionLeafMembershipWitness, fields.acirHash, @@ -88,7 +89,7 @@ export class PrivateCallData { reader.readObject(VerificationKeyAsFields), reader.readObject(Fr), reader.readObject(Fr), - reader.readObject(Fr), + reader.readObject(PublicKeys), reader.readObject(Fr), reader.readObject(MembershipWitness.deserializer(FUNCTION_TREE_HEIGHT)), reader.readObject(Fr), diff --git a/yarn-project/circuits.js/src/types/public_keys.ts b/yarn-project/circuits.js/src/types/public_keys.ts index be151aa9745a..231c8e63f40e 100644 --- a/yarn-project/circuits.js/src/types/public_keys.ts +++ b/yarn-project/circuits.js/src/types/public_keys.ts @@ -41,6 +41,10 @@ export class PublicKeys { ); } + static random(): PublicKeys { + return new PublicKeys(Point.random(), Point.random(), Point.random(), Point.random()); + } + static empty(): PublicKeys { return new PublicKeys(Point.ZERO, Point.ZERO, Point.ZERO, Point.ZERO); } diff --git a/yarn-project/cli/src/cmds/pxe/add_contract.ts b/yarn-project/cli/src/cmds/pxe/add_contract.ts index b83ce19bd707..e2e2e721648c 100644 --- a/yarn-project/cli/src/cmds/pxe/add_contract.ts +++ b/yarn-project/cli/src/cmds/pxe/add_contract.ts @@ -1,6 +1,6 @@ import { AztecAddress, type ContractInstanceWithAddress, Fr, getContractClassFromArtifact } from '@aztec/aztec.js'; import { createCompatibleClient } from '@aztec/aztec.js'; -import { type PublicKeys } from '@aztec/circuits.js'; +import { Point, type PublicKeys } from '@aztec/circuits.js'; import { computeContractAddressFromInstance } from '@aztec/circuits.js/contract'; import { type DebugLogger, type LogFn } from '@aztec/foundation/log'; @@ -26,6 +26,7 @@ export async function addContract( publicKeysHash: publicKeys?.hash() ?? Fr.ZERO, address, deployer: deployer ?? AztecAddress.ZERO, + ivpkM: new Point(new Fr(123), new Fr(456), false), }; const computed = computeContractAddressFromInstance(instance); if (!computed.equals(address)) { diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts index 3f7379ee5265..75e96cc962c8 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract/contract_class_registration.test.ts @@ -18,7 +18,7 @@ import { deployInstance, registerContractClass, } from '@aztec/aztec.js/deployment'; -import { type ContractClassIdPreimage } from '@aztec/circuits.js'; +import { PublicKeys, type ContractClassIdPreimage } from '@aztec/circuits.js'; import { FunctionSelector, FunctionType } from '@aztec/foundation/abi'; import { writeTestData } from '@aztec/foundation/testing'; import { StatefulTestContract } from '@aztec/noir-contracts.js'; @@ -104,11 +104,11 @@ describe('e2e_deploy_contract contract class registration', () => { const deployInstance = async (opts: { constructorName?: string; deployer?: AztecAddress } = {}) => { const initArgs = [wallet.getAddress(), wallet.getAddress(), 42] as StatefulContractCtorArgs; const salt = Fr.random(); - const publicKeysHash = Fr.random(); + const publicKeys = PublicKeys.random(); const instance = getContractInstanceFromDeployParams(artifact, { constructorArgs: initArgs, salt, - publicKeysHash, + publicKeys, constructorArtifact: opts.constructorName, deployer: opts.deployer, }); @@ -128,13 +128,13 @@ describe('e2e_deploy_contract contract class registration', () => { const registered = await t.registerContract(wallet, StatefulTestContract, { constructorName: opts.constructorName, salt: instance.salt, - publicKeysHash, + publicKeys, initArgs, deployer: opts.deployer, }); expect(registered.address).toEqual(instance.address); const contract = await StatefulTestContract.at(instance.address, wallet); - return { contract, initArgs, instance, publicKeysHash }; + return { contract, initArgs, instance, publicKeys }; }; describe('using a private constructor', () => { diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract/deploy_test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract/deploy_test.ts index ffafbb038e76..c6d707cb98d0 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract/deploy_test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract/deploy_test.ts @@ -15,6 +15,7 @@ import { import { type StatefulTestContract } from '@aztec/noir-contracts.js'; import { type ISnapshotManager, addAccounts, createSnapshotManager } from '../fixtures/snapshot_manager.js'; +import { PublicKeys } from '@aztec/circuits.js'; const { E2E_DATA_PATH: dataPath } = process.env; @@ -61,18 +62,18 @@ export class DeployTest { contractArtifact: ContractArtifactClass, opts: { salt?: Fr; - publicKeysHash?: Fr; + publicKeys?: PublicKeys; initArgs?: any[]; constructorName?: string; deployer?: AztecAddress; } = {}, ): Promise { - const { salt, publicKeysHash, initArgs, constructorName, deployer } = opts; + const { salt, publicKeys, initArgs, constructorName, deployer } = opts; const instance = getContractInstanceFromDeployParams(contractArtifact.artifact, { constructorArgs: initArgs ?? [], constructorArtifact: constructorName, salt, - publicKeysHash, + publicKeys, deployer, }); await wallet.registerContract({ artifact: contractArtifact.artifact, instance }); diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract/legacy.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract/legacy.test.ts index 3c085962cf80..2894fe98a7bf 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract/legacy.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract/legacy.test.ts @@ -33,13 +33,13 @@ describe('e2e_deploy_contract legacy', () => { */ it('should deploy a test contract', async () => { const salt = Fr.random(); - const publicKeysHash = wallet.getCompleteAddress().publicKeys.hash(); + const publicKeys = wallet.getCompleteAddress().publicKeys; const deploymentData = getContractInstanceFromDeployParams(TestContractArtifact, { salt, - publicKeysHash, + publicKeys, deployer: wallet.getAddress(), }); - const deployer = new ContractDeployer(TestContractArtifact, wallet, publicKeysHash); + const deployer = new ContractDeployer(TestContractArtifact, wallet, publicKeys.hash()); const receipt = await deployer.deploy().send({ contractAddressSalt: salt }).wait({ wallet }); expect(receipt.contract.address).toEqual(deploymentData.address); expect(await pxe.getContractInstance(deploymentData.address)).toBeDefined(); diff --git a/yarn-project/foundation/src/fields/fields.ts b/yarn-project/foundation/src/fields/fields.ts index bb9a9479af6e..9e57b97177be 100644 --- a/yarn-project/foundation/src/fields/fields.ts +++ b/yarn-project/foundation/src/fields/fields.ts @@ -308,10 +308,6 @@ export class Fr extends BaseField { value: this.toString(), }; } - - toFq() { - return new Fq(this.toBigInt()); - } } // For deserializing JSON. @@ -392,7 +388,6 @@ export class Fq extends BaseField { }; } - // Can I do this ? add(rhs: Fq) { return new Fq((this.toBigInt() + rhs.toBigInt()) % Fq.MODULUS); } diff --git a/yarn-project/ivc-integration/src/avm_integration.test.ts b/yarn-project/ivc-integration/src/avm_integration.test.ts index 0811ca4c6bf1..d0d40286482c 100644 --- a/yarn-project/ivc-integration/src/avm_integration.test.ts +++ b/yarn-project/ivc-integration/src/avm_integration.test.ts @@ -14,7 +14,7 @@ import { AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS, PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH, } from '@aztec/circuits.js/constants'; -import { Fr } from '@aztec/foundation/fields'; +import { Fr, Point } from '@aztec/foundation/fields'; import { createDebugLogger } from '@aztec/foundation/log'; import { BufferReader } from '@aztec/foundation/serialize'; import { type FixedLengthArray } from '@aztec/noir-protocol-circuits-types/types'; @@ -159,6 +159,7 @@ const proveAvmTestContract = async ( contractClassId: new Fr(0x789), initializationHash: new Fr(0x101112), publicKeysHash: new Fr(0x161718), + ivpkM: new Point(new Fr(123), new Fr(456), false), }).withAddress(environment.address); worldStateDB.getContractInstance.mockResolvedValue(await Promise.resolve(contractInstance)); diff --git a/yarn-project/key-store/src/key_store.ts b/yarn-project/key-store/src/key_store.ts index b87c6c9ffb05..2b628c91a59e 100644 --- a/yarn-project/key-store/src/key_store.ts +++ b/yarn-project/key-store/src/key_store.ts @@ -139,6 +139,16 @@ export class KeyStore { return Promise.resolve(new KeyValidationRequest(pkM, skApp)); } + public async getMasterNullifierPublicKey(account: AztecAddress): Promise { + const masterNullifierPublicKeyBuffer = this.#keys.get(`${account.toString()}-npk_m`); + if (!masterNullifierPublicKeyBuffer) { + throw new Error( + `Account ${account.toString()} does not exist. Registered accounts: ${await this.getAccounts()}.`, + ); + } + return Promise.resolve(Point.fromBuffer(masterNullifierPublicKeyBuffer)); + } + /** * Gets the master incoming viewing public key for a given account. * @throws If the account does not exist in the key store. diff --git a/yarn-project/noir-protocol-circuits-types/src/noir_test_gen.test.ts b/yarn-project/noir-protocol-circuits-types/src/noir_test_gen.test.ts index d4c7d2ee6d2f..463c09a6e104 100644 --- a/yarn-project/noir-protocol-circuits-types/src/noir_test_gen.test.ts +++ b/yarn-project/noir-protocol-circuits-types/src/noir_test_gen.test.ts @@ -9,7 +9,7 @@ import { computePrivateFunctionsTree, computeSaltedInitializationHash, } from '@aztec/circuits.js'; -import { Fr } from '@aztec/foundation/fields'; +import { Fr, Point } from '@aztec/foundation/fields'; import { setupCustomSnapshotSerializers } from '@aztec/foundation/testing'; import { type ContractClass, type ContractInstance } from '@aztec/types/contracts'; @@ -17,13 +17,14 @@ describe('Data generation for noir tests', () => { setupCustomSnapshotSerializers(expect); type FixtureContractData = Omit & - Pick & + Pick & Pick & { toString: () => string }; const defaultContract: FixtureContractData = { artifactHash: new Fr(12345), packedBytecode: Buffer.from([3, 4, 5, 6, 7]), publicKeysHash: new Fr(45678), + ivpkM: new Point(new Fr(123), new Fr(456), false), salt: new Fr(56789), privateFunctions: [ { selector: FunctionSelector.fromField(new Fr(1010101)), vkHash: new Fr(0) }, @@ -36,6 +37,7 @@ describe('Data generation for noir tests', () => { artifactHash: new Fr(1212), packedBytecode: Buffer.from([3, 4, 3, 4]), publicKeysHash: new Fr(4545), + ivpkM: new Point(new Fr(123), new Fr(456), false), salt: new Fr(5656), privateFunctions: [{ selector: FunctionSelector.fromField(new Fr(334455)), vkHash: new Fr(0) }], toString: () => 'parentContract', diff --git a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts index 0ef38b37192a..21e6561c7edb 100644 --- a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts @@ -113,6 +113,7 @@ import { type PublicKernelInnerCircuitPrivateInputs, type PublicKernelInnerData, type PublicKernelTailCircuitPrivateInputs, + type PublicKeys, PublicValidationRequestArrayLengths, PublicValidationRequests, type RECURSIVE_PROOF_LENGTH, @@ -242,6 +243,7 @@ import type { PublicKernelInnerData as PublicKernelInnerDataNoir, PublicKernelMergeCircuitPrivateInputs as PublicKernelMergeCircuitPrivateInputsNoir, PublicKernelTailCircuitPrivateInputs as PublicKernelTailCircuitPrivateInputsNoir, + PublicKeys as PublicKeysNoir, PublicValidationRequestArrayLengths as PublicValidationRequestArrayLengthsNoir, PublicValidationRequests as PublicValidationRequestsNoir, ReadRequest as ReadRequestNoir, @@ -1018,12 +1020,29 @@ export function mapPrivateCallDataToNoir(privateCallData: PrivateCallData): Priv function_leaf_membership_witness: mapMembershipWitnessToNoir(privateCallData.functionLeafMembershipWitness), contract_class_artifact_hash: mapFieldToNoir(privateCallData.contractClassArtifactHash), contract_class_public_bytecode_commitment: mapFieldToNoir(privateCallData.contractClassPublicBytecodeCommitment), - public_keys_hash: mapWrappedFieldToNoir(privateCallData.publicKeysHash), + public_keys: mapPublicKeysToNoir(privateCallData.publicKeys), salted_initialization_hash: mapWrappedFieldToNoir(privateCallData.saltedInitializationHash), acir_hash: mapFieldToNoir(privateCallData.acirHash), }; } +export function mapPublicKeysToNoir(publicKeys: PublicKeys): PublicKeysNoir { + return { + npk_m: { + inner: mapPointToNoir(publicKeys.masterNullifierPublicKey) + }, + ivpk_m: { + inner: mapPointToNoir(publicKeys.masterIncomingViewingPublicKey) + }, + ovpk_m: { + inner: mapPointToNoir(publicKeys.masterOutgoingViewingPublicKey) + }, + tpk_m: { + inner: mapPointToNoir(publicKeys.masterTaggingPublicKey) + } + }; +} + export function mapRevertCodeFromNoir(revertCode: NoirField): RevertCode { return RevertCode.fromField(mapFieldFromNoir(revertCode)); } diff --git a/yarn-project/pxe/src/kernel_oracle/index.ts b/yarn-project/pxe/src/kernel_oracle/index.ts index 294d72b7cbaa..c66c3da18c37 100644 --- a/yarn-project/pxe/src/kernel_oracle/index.ts +++ b/yarn-project/pxe/src/kernel_oracle/index.ts @@ -7,6 +7,7 @@ import { MembershipWitness, type NOTE_HASH_TREE_HEIGHT, type Point, + PublicKeys, VK_TREE_HEIGHT, type VerificationKeyAsFields, computeContractClassIdPreimage, @@ -35,9 +36,20 @@ export class KernelOracle implements ProvingDataOracle { public async getContractAddressPreimage(address: AztecAddress) { const instance = await this.contractDataOracle.getContractInstance(address); + const masterNullifierPublicKey = await this.keyStore.getMasterNullifierPublicKey(address); + const masterIncomingViewingPublicKey = await this.keyStore.getMasterIncomingViewingPublicKey(address); + const masterOutgoingViewingPublicKey = await this.keyStore.getMasterOutgoingViewingPublicKey(address); + const masterTaggingPublicKey = await this.keyStore.getMasterTaggingPublicKey(address); + return { saltedInitializationHash: computeSaltedInitializationHash(instance), ...instance, + publicKeys: new PublicKeys( + masterNullifierPublicKey, + masterIncomingViewingPublicKey, + masterOutgoingViewingPublicKey, + masterTaggingPublicKey, + ), }; } diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts index e2f7e1689e04..91d59fe4bf31 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts @@ -16,6 +16,7 @@ import { PrivateCircuitPublicInputs, PrivateKernelCircuitPublicInputs, PrivateKernelTailCircuitPublicInputs, + PublicKeys, ScopedNoteHash, type TxRequest, VK_TREE_HEIGHT, @@ -26,7 +27,7 @@ import { makeTxRequest } from '@aztec/circuits.js/testing'; import { NoteSelector } from '@aztec/foundation/abi'; import { makeTuple } from '@aztec/foundation/array'; import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { Fr } from '@aztec/foundation/fields'; +import { Fr, Point } from '@aztec/foundation/fields'; import { mock } from 'jest-mock-extended'; @@ -146,7 +147,7 @@ describe('Kernel Prover', () => { oracle.getContractAddressPreimage.mockResolvedValue({ contractClassId: Fr.random(), - publicKeysHash: Fr.random(), + publicKeys: PublicKeys.empty(), saltedInitializationHash: Fr.random(), }); oracle.getContractClassIdPreimage.mockResolvedValue({ diff --git a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts index f04276a5792e..54ea58fe0031 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -195,7 +195,7 @@ export class KernelProver { contractAddress, functionData.selector, ); - const { contractClassId, publicKeysHash, saltedInitializationHash } = await this.oracle.getContractAddressPreimage( + const { contractClassId, publicKeys, saltedInitializationHash } = await this.oracle.getContractAddressPreimage( contractAddress, ); const { artifactHash: contractClassArtifactHash, publicBytecodeCommitment: contractClassPublicBytecodeCommitment } = @@ -208,7 +208,7 @@ export class KernelProver { return PrivateCallData.from({ callStackItem, vk, - publicKeysHash, + publicKeys, contractClassArtifactHash, contractClassPublicBytecodeCommitment, saltedInitializationHash, diff --git a/yarn-project/pxe/src/kernel_prover/proving_data_oracle.ts b/yarn-project/pxe/src/kernel_prover/proving_data_oracle.ts index 5511100a5e13..130bf5191c44 100644 --- a/yarn-project/pxe/src/kernel_prover/proving_data_oracle.ts +++ b/yarn-project/pxe/src/kernel_prover/proving_data_oracle.ts @@ -1,5 +1,6 @@ import { type NullifierMembershipWitness } from '@aztec/circuit-types'; import { + PublicKeys, type FUNCTION_TREE_HEIGHT, type Fr, type FunctionSelector, @@ -20,7 +21,7 @@ export interface ProvingDataOracle { /** Retrieves the preimage of a contract address from the registered contract instances db. */ getContractAddressPreimage( address: AztecAddress, - ): Promise<{ saltedInitializationHash: Fr; publicKeysHash: Fr; contractClassId: Fr }>; + ): Promise<{ saltedInitializationHash: Fr; publicKeys: PublicKeys; contractClassId: Fr }>; /** Retrieves the preimage of a contract class id from the contract classes db. */ getContractClassIdPreimage( diff --git a/yarn-project/pxe/src/note_processor/note_processor.ts b/yarn-project/pxe/src/note_processor/note_processor.ts index ffe88b4b78c7..a91e2f31e158 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.ts @@ -1,7 +1,7 @@ import { type AztecNode, L1NotePayload, type L2Block } from '@aztec/circuit-types'; import { type NoteProcessorStats } from '@aztec/circuit-types/stats'; import { type CompleteAddress, INITIAL_L2_BLOCK_NUM, MAX_NOTE_HASHES_PER_TX, type PublicKey } from '@aztec/circuits.js'; -import { type Fr } from '@aztec/foundation/fields'; +import { Fq, type Fr } from '@aztec/foundation/fields'; import { type Logger, createDebugLogger } from '@aztec/foundation/log'; import { Timer } from '@aztec/foundation/timer'; import { type KeyStore } from '@aztec/key-store'; @@ -115,7 +115,7 @@ export class NoteProcessor { const deferredOutgoingNotes: DeferredNoteDao[] = []; const ivskM = await this.keyStore.getMasterSecretKey(this.ivpkM); - const addressIvskM = ivskM.add(this.account.getPreAddress().toFq()); + const addressIvskM = ivskM.add(new Fq(this.account.getPreAddress().toBigInt())); const ovskM = await this.keyStore.getMasterSecretKey(this.ovpkM); diff --git a/yarn-project/simulator/src/avm/avm_simulator.test.ts b/yarn-project/simulator/src/avm/avm_simulator.test.ts index e3820001f6f6..c6a5603467ab 100644 --- a/yarn-project/simulator/src/avm/avm_simulator.test.ts +++ b/yarn-project/simulator/src/avm/avm_simulator.test.ts @@ -4,7 +4,7 @@ import { computeVarArgsHash } from '@aztec/circuits.js/hash'; import { FunctionSelector } from '@aztec/foundation/abi'; import { AztecAddress } from '@aztec/foundation/aztec-address'; import { keccak256, keccakf1600, pedersenCommit, pedersenHash, poseidon2Hash, sha256 } from '@aztec/foundation/crypto'; -import { Fq, Fr } from '@aztec/foundation/fields'; +import { Fq, Fr, Point } from '@aztec/foundation/fields'; import { type Fieldable } from '@aztec/foundation/serialize'; import { randomInt } from 'crypto'; @@ -807,6 +807,7 @@ describe('AVM simulator: transpiled Noir contracts', () => { contractClassId: new Fr(0x789), initializationHash: new Fr(0x101112), publicKeysHash: new Fr(0x161718), + ivpkM: new Point(new Fr(123), new Fr(456), false), }; mockGetContractInstance(worldStateDB, contractInstance); diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index 02cbba5ee6cd..d4e3ea50aee2 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -6,6 +6,7 @@ import { Header, PUBLIC_DATA_SUBTREE_HEIGHT, PublicDataTreeLeaf, + PublicKeys, computePartialAddress, getContractInstanceFromDeployParams, } from '@aztec/circuits.js'; @@ -94,11 +95,13 @@ export class TXEService { _length: ForeignCallSingle, args: ForeignCallArray, publicKeysHash: ForeignCallSingle, + publicKeys: ForeignCallArray, ) { const initializerStr = fromArray(initializer) .map(char => String.fromCharCode(char.toNumber())) .join(''); const decodedArgs = fromArray(args); + const publicKeysFrArray = fromArray(publicKeys); const publicKeysHashFr = fromSingle(publicKeysHash); this.logger.debug( `Deploy ${artifact.name} with initializer ${initializerStr}(${decodedArgs}) and public keys hash ${publicKeysHashFr}`, @@ -108,7 +111,7 @@ export class TXEService { constructorArgs: decodedArgs, skipArgsDecoding: true, salt: Fr.ONE, - publicKeysHash: publicKeysHashFr, + publicKeys: PublicKeys.fromFields(publicKeysFrArray), constructorArtifact: initializerStr ? initializerStr : undefined, deployer: AztecAddress.ZERO, }); @@ -166,13 +169,13 @@ export class TXEService { async addAccount(secret: ForeignCallSingle) { const keys = (this.typedOracle as TXE).deriveKeys(fromSingle(secret)); const args = [keys.publicKeys.masterIncomingViewingPublicKey.x, keys.publicKeys.masterIncomingViewingPublicKey.y]; - const hash = keys.publicKeys.hash(); + // const hash = keys.publicKeys.hash(); const artifact = SchnorrAccountContractArtifact; const instance = getContractInstanceFromDeployParams(artifact, { constructorArgs: args, skipArgsDecoding: true, salt: Fr.ONE, - publicKeysHash: hash, + publicKeys: keys.publicKeys, constructorArtifact: 'constructor', deployer: AztecAddress.ZERO, }); diff --git a/yarn-project/types/src/contracts/contract_instance.ts b/yarn-project/types/src/contracts/contract_instance.ts index 3adf6e805ea6..2c7233df1d33 100644 --- a/yarn-project/types/src/contracts/contract_instance.ts +++ b/yarn-project/types/src/contracts/contract_instance.ts @@ -17,7 +17,7 @@ export interface ContractInstance { contractClassId: Fr; /** Hash of the selector and arguments to the constructor. */ initializationHash: Fr; - /** Optional hash of the struct of public keys used for encryption and nullifying by this contract. */ + // /** Optional hash of the struct of public keys used for encryption and nullifying by this contract. */ publicKeysHash: Fr; ivpkM: Point; }