diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 97ec479bea3..107ebc2d0d8 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -152,7 +152,7 @@ library Constants { uint256 internal constant GAS_SETTINGS_LENGTH = 7; uint256 internal constant CALL_CONTEXT_LENGTH = 5; uint256 internal constant CONTENT_COMMITMENT_LENGTH = 4; - uint256 internal constant CONTRACT_INSTANCE_LENGTH = 5; + uint256 internal constant CONTRACT_INSTANCE_LENGTH = 16; uint256 internal constant CONTRACT_STORAGE_READ_LENGTH = 3; uint256 internal constant CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 3; uint256 internal constant ETH_ADDRESS_LENGTH = 1; diff --git a/noir-projects/aztec-nr/aztec/src/deploy.nr b/noir-projects/aztec-nr/aztec/src/deploy.nr index d916b384f80..adf5523c5a6 100644 --- a/noir-projects/aztec-nr/aztec/src/deploy.nr +++ b/noir-projects/aztec-nr/aztec/src/deploy.nr @@ -20,13 +20,29 @@ pub fn deploy_contract(context: &mut PrivateContext, target: AztecAddress) { serialized_args[0] = instance.salt; serialized_args[1] = instance.contract_class_id.to_field(); serialized_args[2] = instance.initialization_hash; - serialized_args[3] = instance.public_keys_hash.to_field(); - serialized_args[4] = universal_deploy as Field; + + let serialized_public_keys = instance.public_keys.serialize(); + serialized_args[3] = serialized_public_keys[0]; + serialized_args[4] = serialized_public_keys[1]; + serialized_args[5] = serialized_public_keys[2]; + serialized_args[6] = serialized_public_keys[3]; + serialized_args[7] = serialized_public_keys[4]; + serialized_args[8] = serialized_public_keys[5]; + serialized_args[9] = serialized_public_keys[6]; + serialized_args[10] = serialized_public_keys[7]; + serialized_args[11] = serialized_public_keys[8]; + serialized_args[12] = serialized_public_keys[9]; + serialized_args[13] = serialized_public_keys[10]; + serialized_args[14] = serialized_public_keys[11]; + + serialized_args[15] = universal_deploy as Field; let _call_result = context.call_private_function( DEPLOYER_CONTRACT_ADDRESS, comptime { - FunctionSelector::from_signature("deploy(Field,(Field),Field,(Field),bool)") + FunctionSelector::from_signature( + "deploy(Field,(Field),Field,(Field,Field,Field,Field,Field,Field,Field,Field,Field,Field,Field,Field),bool)" + ) }, serialized_args ); diff --git a/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr b/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr index bca64c13f1a..48a37a1120e 100644 --- a/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/contract_instance_deployer_contract/src/main.nr @@ -3,9 +3,9 @@ use dep::aztec::macros::aztec; #[aztec] contract ContractInstanceDeployer { use dep::aztec::protocol_types::{ - address::{AztecAddress, PublicKeysHash, PartialAddress}, contract_class_id::ContractClassId, - constants::DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE, abis::log_hash::LogHash, - traits::Serialize + address::{AztecAddress, PublicKeysHash, PublicKeys, PartialAddress}, + contract_class_id::ContractClassId, constants::DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE, + abis::log_hash::LogHash, traits::Serialize }; use dep::aztec::{ hash::compute_unencrypted_log_hash, oracle::logs::emit_unencrypted_log_private, @@ -22,7 +22,7 @@ contract ContractInstanceDeployer { salt: Field, contract_class_id: ContractClassId, initialization_hash: Field, - public_keys_hash: PublicKeysHash, + public_keys: PublicKeys, deployer: AztecAddress, } @@ -32,7 +32,7 @@ contract ContractInstanceDeployer { salt: Field, contract_class_id: ContractClassId, initialization_hash: Field, - public_keys_hash: PublicKeysHash, + public_keys: PublicKeys, universal_deploy: bool ) { // TODO(@spalladino): assert nullifier_exists silo(contract_class_id, ContractClassRegisterer) @@ -45,7 +45,7 @@ contract ContractInstanceDeployer { let partial_address = PartialAddress::compute(contract_class_id, salt, initialization_hash, deployer); - let address = AztecAddress::compute(public_keys_hash, partial_address); + let address = AztecAddress::compute(public_keys.hash(), partial_address); // Emit the address as a nullifier to be able to prove that this instance has been (not) deployed context.push_nullifier(address.to_field()); @@ -55,7 +55,7 @@ contract ContractInstanceDeployer { DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE, contract_class_id, address, - public_keys_hash, + public_keys, initialization_hash, salt, deployer, 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 1e6937a133c..4a5e317ecbf 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -228,7 +228,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 = 16; 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 c10fa38c944..78baf76fe69 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 @@ -1,5 +1,8 @@ use crate::{ - address::{aztec_address::AztecAddress, partial_address::PartialAddress, public_keys_hash::PublicKeysHash}, + address::{ + aztec_address::AztecAddress, partial_address::PartialAddress, public_keys_hash::PublicKeysHash, + public_keys::PublicKeys +}, contract_class_id::ContractClassId, constants::CONTRACT_INSTANCE_LENGTH, traits::{Deserialize, Hash, Serialize} }; @@ -9,12 +12,12 @@ pub struct ContractInstance { deployer: AztecAddress, contract_class_id : ContractClassId, initialization_hash : Field, - public_keys_hash : PublicKeysHash, + public_keys : PublicKeys, } impl Eq for ContractInstance { fn eq(self, other: Self) -> bool { - self.public_keys_hash.eq(other.public_keys_hash) + self.public_keys.eq(other.public_keys) & self.initialization_hash.eq(other.initialization_hash) & self.contract_class_id.eq(other.contract_class_id) & self.salt.eq(other.salt) @@ -23,12 +26,24 @@ impl Eq for ContractInstance { impl Serialize for ContractInstance { fn serialize(self) -> [Field; CONTRACT_INSTANCE_LENGTH] { + let public_keys_serialized = self.public_keys.serialize(); [ self.salt, self.deployer.to_field(), self.contract_class_id.to_field(), self.initialization_hash, - self.public_keys_hash.to_field() + public_keys_serialized[0], + public_keys_serialized[1], + public_keys_serialized[2], + public_keys_serialized[3], + public_keys_serialized[4], + public_keys_serialized[5], + public_keys_serialized[6], + public_keys_serialized[7], + public_keys_serialized[8], + public_keys_serialized[9], + public_keys_serialized[10], + public_keys_serialized[11] ] } } @@ -40,7 +55,22 @@ 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: PublicKeys::deserialize( + [ + serialized[4], + serialized[5], + serialized[6], + serialized[7], + serialized[8], + serialized[9], + serialized[10], + serialized[11], + serialized[12], + serialized[13], + serialized[14], + serialized[15] + ] + ) } } } @@ -54,7 +84,7 @@ impl Hash for ContractInstance { impl ContractInstance { fn to_address(self) -> AztecAddress { AztecAddress::compute( - self.public_keys_hash, + self.public_keys.hash(), PartialAddress::compute( self.contract_class_id, self.salt, diff --git a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts index 71d838e614c..d0e9b281e0e 100644 --- a/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts +++ b/yarn-project/aztec.js/src/account_manager/deploy_account_method.ts @@ -1,4 +1,4 @@ -import { type Fr } from '@aztec/circuits.js'; +import { type PublicKeys } from '@aztec/circuits.js'; import { type ContractArtifact, type FunctionArtifact, @@ -23,7 +23,7 @@ export class DeployAccountMethod extends DeployMethod { constructor( authWitnessProvider: AuthWitnessProvider, - publicKeysHash: Fr, + publicKeys: PublicKeys, wallet: Wallet, artifact: ContractArtifact, args: any[] = [], @@ -31,7 +31,7 @@ export class DeployAccountMethod extends DeployMethod { feePaymentNameOrArtifact?: string | FunctionArtifact, ) { super( - publicKeysHash, + publicKeys, wallet, artifact, (address, wallet) => Contract.at(address, artifact, wallet), diff --git a/yarn-project/aztec.js/src/account_manager/index.ts b/yarn-project/aztec.js/src/account_manager/index.ts index d7012cfb266..1448f6d7212 100644 --- a/yarn-project/aztec.js/src/account_manager/index.ts +++ b/yarn-project/aztec.js/src/account_manager/index.ts @@ -1,5 +1,10 @@ import { CompleteAddress, type PXE } from '@aztec/circuit-types'; -import { type ContractInstanceWithAddress, deriveKeys, getContractInstanceFromDeployParams } from '@aztec/circuits.js'; +import { + type ContractInstanceWithAddress, + type PublicKeys, + deriveKeys, + getContractInstanceFromDeployParams, +} from '@aztec/circuits.js'; import { Fr } from '@aztec/foundation/fields'; import { type AccountContract } from '../account/contract.js'; @@ -32,17 +37,24 @@ export class AccountManager { // TODO(@spalladino): Does it make sense to have both completeAddress and instance? private completeAddress?: CompleteAddress; private instance?: ContractInstanceWithAddress; - private publicKeysHash?: Fr; + private publicKeys?: PublicKeys; constructor(private pxe: PXE, private secretKey: Fr, private accountContract: AccountContract, salt?: Salt) { this.salt = salt !== undefined ? new Fr(salt) : Fr.random(); } protected getPublicKeysHash() { - if (!this.publicKeysHash) { - this.publicKeysHash = deriveKeys(this.secretKey).publicKeys.hash(); + if (!this.publicKeys) { + this.publicKeys = deriveKeys(this.secretKey).publicKeys; } - return this.publicKeysHash; + return this.publicKeys.hash(); + } + + protected getPublicKeys() { + if (!this.publicKeys) { + this.publicKeys = deriveKeys(this.secretKey).publicKeys; + } + return this.publicKeys; } /** @@ -87,7 +99,7 @@ export class AccountManager { this.instance = getContractInstanceFromDeployParams(this.accountContract.getContractArtifact(), { constructorArgs: this.accountContract.getDeploymentArgs(), salt: this.salt, - publicKeysHash: this.getPublicKeysHash(), + publicKeys: this.getPublicKeys(), }); } return this.instance; @@ -146,7 +158,7 @@ export class AccountManager { const args = this.accountContract.getDeploymentArgs() ?? []; return new DeployAccountMethod( this.accountContract.getAuthWitnessProvider(this.getCompleteAddress()), - this.getPublicKeysHash(), + this.getPublicKeys(), deployWallet, this.accountContract.getContractArtifact(), args, diff --git a/yarn-project/aztec.js/src/contract/contract.ts b/yarn-project/aztec.js/src/contract/contract.ts index 66c946579c9..d54b3b50095 100644 --- a/yarn-project/aztec.js/src/contract/contract.ts +++ b/yarn-project/aztec.js/src/contract/contract.ts @@ -1,3 +1,4 @@ +import { PublicKeys } from '@aztec/circuits.js'; import { type ContractArtifact } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; @@ -38,25 +39,25 @@ export class Contract extends ContractBase { */ public static deploy(wallet: Wallet, artifact: ContractArtifact, args: any[], constructorName?: string) { const postDeployCtor = (address: AztecAddress, wallet: Wallet) => Contract.at(address, artifact, wallet); - return new DeployMethod(Fr.ZERO, wallet, artifact, postDeployCtor, args, constructorName); + return new DeployMethod(PublicKeys.empty(), wallet, artifact, postDeployCtor, args, constructorName); } /** * Creates a tx to deploy a new instance of a contract using the specified public keys hash to derive the address. - * @param publicKeysHash - Hash of public keys to use for deriving the address. + * @param publicKeys - Hash of public keys to use for deriving the address. * @param wallet - The wallet for executing the deployment. * @param artifact - Build artifact of the contract. * @param args - Arguments for the constructor. * @param constructorName - The name of the constructor function to call. */ - public static deployWithPublicKeysHash( - publicKeysHash: Fr, + public static deployWithPublicKeys( + publicKeys: PublicKeys, wallet: Wallet, artifact: ContractArtifact, args: any[], constructorName?: string, ) { const postDeployCtor = (address: AztecAddress, wallet: Wallet) => Contract.at(address, artifact, wallet); - return new DeployMethod(publicKeysHash, wallet, artifact, postDeployCtor, args, constructorName); + return new DeployMethod(publicKeys, wallet, artifact, postDeployCtor, args, constructorName); } } diff --git a/yarn-project/aztec.js/src/contract/deploy_method.ts b/yarn-project/aztec.js/src/contract/deploy_method.ts index 1a58dec0a65..3de69dc4f58 100644 --- a/yarn-project/aztec.js/src/contract/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract/deploy_method.ts @@ -2,6 +2,7 @@ import { type FunctionCall, type TxExecutionRequest } from '@aztec/circuit-types import { AztecAddress, type ContractInstanceWithAddress, + PublicKeys, computePartialAddress, getContractClassFromArtifact, getContractInstanceFromDeployParams, @@ -52,7 +53,7 @@ export class DeployMethod extends Bas private constructorArtifact: FunctionArtifact | undefined; constructor( - private publicKeysHash: Fr, + private publicKeys: PublicKeys, wallet: Wallet, private artifact: ContractArtifact, private postDeployCtor: (address: AztecAddress, wallet: Wallet) => Promise, @@ -221,7 +222,7 @@ export class DeployMethod extends Bas this.instance = getContractInstanceFromDeployParams(this.artifact, { constructorArgs: this.args, salt: options.contractAddressSalt, - publicKeysHash: this.publicKeysHash, + publicKeys: this.publicKeys, constructorArtifact: this.constructorArtifact, deployer: options.universalDeploy ? AztecAddress.ZERO : this.wallet.getAddress(), }); diff --git a/yarn-project/aztec.js/src/deployment/contract_deployer.ts b/yarn-project/aztec.js/src/deployment/contract_deployer.ts index a0016008ea4..23ffe4d0ff7 100644 --- a/yarn-project/aztec.js/src/deployment/contract_deployer.ts +++ b/yarn-project/aztec.js/src/deployment/contract_deployer.ts @@ -1,4 +1,4 @@ -import { type AztecAddress } from '@aztec/circuits.js'; +import { type AztecAddress, PublicKeys } from '@aztec/circuits.js'; import { type ContractArtifact } from '@aztec/foundation/abi'; import { Fr } from '@aztec/foundation/fields'; @@ -14,7 +14,7 @@ export class ContractDeployer { constructor( private artifact: ContractArtifact, private wallet: Wallet, - private publicKeysHash?: Fr, + private publicKeys?: PublicKeys, private constructorName?: string, ) {} @@ -30,7 +30,7 @@ export class ContractDeployer { public deploy(...args: any[]) { const postDeployCtor = (address: AztecAddress, wallet: Wallet) => Contract.at(address, this.artifact, wallet); return new DeployMethod( - this.publicKeysHash ?? Fr.ZERO, + this.publicKeys ?? PublicKeys.empty(), this.wallet, this.artifact, postDeployCtor, diff --git a/yarn-project/aztec.js/src/deployment/deploy_instance.ts b/yarn-project/aztec.js/src/deployment/deploy_instance.ts index 1a35fc77a21..24b5fa65d82 100644 --- a/yarn-project/aztec.js/src/deployment/deploy_instance.ts +++ b/yarn-project/aztec.js/src/deployment/deploy_instance.ts @@ -11,7 +11,7 @@ import { getDeployerContract } from './protocol_contracts.js'; */ export function deployInstance(wallet: Wallet, instance: ContractInstanceWithAddress): ContractFunctionInteraction { const deployerContract = getDeployerContract(wallet); - const { salt, contractClassId, publicKeysHash, deployer } = instance; + const { salt, contractClassId, publicKeys, deployer } = instance; const isUniversalDeploy = deployer.isZero(); if (!isUniversalDeploy && !wallet.getAddress().equals(deployer)) { throw new Error( @@ -22,7 +22,7 @@ export function deployInstance(wallet: Wallet, instance: ContractInstanceWithAdd salt, contractClassId, instance.initializationHash, - publicKeysHash, + publicKeys, isUniversalDeploy, ); } diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 291c91e825d..ae43357b894 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -73,6 +73,7 @@ export { AccountWallet, AccountWalletWithSecretKey, SignerlessWallet, type Walle export { AztecAddress, EthAddress, + PublicKeys, Fq, Fr, GlobalVariables, diff --git a/yarn-project/aztec/src/cli/cmds/start_pxe.ts b/yarn-project/aztec/src/cli/cmds/start_pxe.ts index 674657fd303..fe9126f0319 100644 --- a/yarn-project/aztec/src/cli/cmds/start_pxe.ts +++ b/yarn-project/aztec/src/cli/cmds/start_pxe.ts @@ -2,6 +2,7 @@ import { type ContractArtifact, type ContractInstanceWithAddress, Fr, + PublicKeys, getContractClassFromArtifact, } from '@aztec/aztec.js'; import { type AztecNode, createAztecNodeClient } from '@aztec/circuit-types'; @@ -104,7 +105,7 @@ export async function addPXE( address, deployer: AztecAddress.ZERO, contractClassId: getContractClassFromArtifact(artifact!).id, - publicKeysHash: Fr.ZERO, + publicKeys: PublicKeys.empty(), }; 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 5ed7f8c4c6a..0cf88e31fc0 100644 --- a/yarn-project/bb-prover/src/avm_proving.test.ts +++ b/yarn-project/bb-prover/src/avm_proving.test.ts @@ -4,9 +4,10 @@ import { FunctionSelector, Gas, GlobalVariables, + PublicKeys, SerializableContractInstance, } 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 { @@ -70,7 +71,12 @@ const proveAndVerifyAvmTestContract = async ( deployer: new Fr(0x456), contractClassId: new Fr(0x789), initializationHash: new Fr(0x101112), - publicKeysHash: new Fr(0x161718), + publicKeys: new PublicKeys( + new Point(new Fr(0x131415), new Fr(0x161718), false), + new Point(new Fr(0x192021), new Fr(0x222324), false), + new Point(new Fr(0x252627), new Fr(0x282930), false), + new Point(new Fr(0x313233), new Fr(0x343536), false), + ), }).withAddress(environment.address); worldStateDB.getContractInstance.mockResolvedValue(Promise.resolve(contractInstance)); diff --git a/yarn-project/builder/src/contract-interface-gen/typescript.ts b/yarn-project/builder/src/contract-interface-gen/typescript.ts index a703990bc61..34c06fab270 100644 --- a/yarn-project/builder/src/contract-interface-gen/typescript.ts +++ b/yarn-project/builder/src/contract-interface-gen/typescript.ts @@ -84,25 +84,25 @@ function generateDeploy(input: ContractArtifact) { * Creates a tx to deploy a new instance of this contract. */ public static deploy(wallet: Wallet, ${args}) { - return new DeployMethod<${contractName}>(Fr.ZERO, wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(1)); + return new DeployMethod<${contractName}>(PublicKeys.empty(), wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(1)); } /** * Creates a tx to deploy a new instance of this contract using the specified public keys hash to derive the address. */ - public static deployWithPublicKeysHash(publicKeysHash: Fr, wallet: Wallet, ${args}) { - return new DeployMethod<${contractName}>(publicKeysHash, wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(2)); + public static deployWithPublicKeys(publicKeys: PublicKeys, wallet: Wallet, ${args}) { + return new DeployMethod<${contractName}>(publicKeys, wallet, ${artifactName}, ${contractName}.at, Array.from(arguments).slice(2)); } /** * Creates a tx to deploy a new instance of this contract using the specified constructor method. */ public static deployWithOpts( - opts: { publicKeysHash?: Fr; method?: M; wallet: Wallet }, + opts: { publicKeys?: PublicKeys; method?: M; wallet: Wallet }, ...args: Parameters<${contractName}['methods'][M]> ) { return new DeployMethod<${contractName}>( - opts.publicKeysHash ?? Fr.ZERO, + opts.publicKeys ?? PublicKeys.empty(), opts.wallet, ${artifactName}, ${contractName}.at, @@ -363,6 +363,7 @@ import { NoteSelector, Point, type PublicKey, + PublicKeys, type UnencryptedL2Log, type Wallet, type WrappedFieldLike, diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index c8827126195..a9515614501 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -137,7 +137,7 @@ export const GAS_LENGTH = 2; export const GAS_SETTINGS_LENGTH = 7; export const CALL_CONTEXT_LENGTH = 5; export const CONTENT_COMMITMENT_LENGTH = 4; -export const CONTRACT_INSTANCE_LENGTH = 5; +export const CONTRACT_INSTANCE_LENGTH = 16; export const CONTRACT_STORAGE_READ_LENGTH = 3; export const CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH = 3; export const ETH_ADDRESS_LENGTH = 1; 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 ac6eca06396..a23519948ef 100644 --- a/yarn-project/circuits.js/src/contract/contract_address.test.ts +++ b/yarn-project/circuits.js/src/contract/contract_address.test.ts @@ -57,10 +57,10 @@ 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).publicKeys; const address = computeContractAddressFromInstance({ - publicKeysHash, + publicKeys, salt, contractClassId, initializationHash, diff --git a/yarn-project/circuits.js/src/contract/contract_address.ts b/yarn-project/circuits.js/src/contract/contract_address.ts index 7b5edd83db0..571d8a33f74 100644 --- a/yarn-project/circuits.js/src/contract/contract_address.ts +++ b/yarn-project/circuits.js/src/contract/contract_address.ts @@ -22,10 +22,10 @@ import { type ContractInstance } from './interfaces/contract_instance.js'; export function computeContractAddressFromInstance( instance: | ContractInstance - | ({ contractClassId: Fr; saltedInitializationHash: Fr } & Pick), + | ({ contractClassId: Fr; saltedInitializationHash: Fr } & Pick), ): AztecAddress { const partialAddress = computePartialAddress(instance); - const publicKeysHash = instance.publicKeysHash; + const publicKeysHash = instance.publicKeys.hash(); return computeAddress(publicKeysHash, partialAddress); } diff --git a/yarn-project/circuits.js/src/contract/contract_instance.ts b/yarn-project/circuits.js/src/contract/contract_instance.ts index df56cb18d40..49a5f413481 100644 --- a/yarn-project/circuits.js/src/contract/contract_instance.ts +++ b/yarn-project/circuits.js/src/contract/contract_instance.ts @@ -11,6 +11,7 @@ import { type FieldsOf } from '@aztec/foundation/types'; import { getContractClassFromArtifact } from '../contract/contract_class.js'; import { computeContractClassId } from '../contract/contract_class_id.js'; +import { PublicKeys } from '../types/public_keys.js'; import { computeContractAddressFromInstance, computeInitializationHash, @@ -26,7 +27,7 @@ export class SerializableContractInstance { public readonly deployer: AztecAddress; public readonly contractClassId: Fr; public readonly initializationHash: Fr; - public readonly publicKeysHash: Fr; + public readonly publicKeys: PublicKeys; constructor(instance: ContractInstance) { if (instance.version !== VERSION) { @@ -36,7 +37,7 @@ export class SerializableContractInstance { this.deployer = instance.deployer; this.contractClassId = instance.contractClassId; this.initializationHash = instance.initializationHash; - this.publicKeysHash = instance.publicKeysHash; + this.publicKeys = instance.publicKeys; } public toBuffer() { @@ -46,7 +47,7 @@ export class SerializableContractInstance { this.deployer, this.contractClassId, this.initializationHash, - this.publicKeysHash, + this.publicKeys, ); } @@ -63,7 +64,7 @@ export class SerializableContractInstance { deployer: reader.readObject(AztecAddress), contractClassId: reader.readObject(Fr), initializationHash: reader.readObject(Fr), - publicKeysHash: reader.readObject(Fr), + publicKeys: reader.readObject(PublicKeys), }); } @@ -74,7 +75,7 @@ export class SerializableContractInstance { deployer: AztecAddress.random(), contractClassId: Fr.random(), initializationHash: Fr.random(), - publicKeysHash: Fr.random(), + publicKeys: PublicKeys.random(), ...opts, }); } @@ -86,7 +87,7 @@ export class SerializableContractInstance { deployer: AztecAddress.zero(), contractClassId: Fr.zero(), initializationHash: Fr.zero(), - publicKeysHash: Fr.zero(), + publicKeys: PublicKeys.empty(), }); } } @@ -104,7 +105,7 @@ export function getContractInstanceFromDeployParams( constructorArgs?: any[]; skipArgsDecoding?: boolean; salt?: Fr; - publicKeysHash?: Fr; + publicKeys?: PublicKeys; deployer?: AztecAddress; }, ): ContractInstanceWithAddress { @@ -121,12 +122,12 @@ export function getContractInstanceFromDeployParams( args, ) : computeInitializationHash(constructorArtifact, args); - const publicKeysHash = opts.publicKeysHash ?? Fr.ZERO; + const publicKeys = opts.publicKeys ?? PublicKeys.empty(); const instance: ContractInstance = { contractClassId, initializationHash, - publicKeysHash, + publicKeys, salt, deployer, version: 1, 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 2694bdb7f2d..8938f8422a2 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 @@ -4,6 +4,7 @@ import { Fr } from '@aztec/foundation/fields'; import { BufferReader } from '@aztec/foundation/serialize'; import { DEPLOYER_CONTRACT_ADDRESS, DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE } from '../../constants.gen.js'; +import { PublicKeys } from '../../types/public_keys.js'; import { type ContractInstanceWithAddress } from '../interfaces/contract_instance.js'; /** Event emitted from the ContractInstanceDeployer. */ @@ -14,7 +15,7 @@ export class ContractInstanceDeployedEvent { public readonly salt: Fr, public readonly contractClassId: Fr, public readonly initializationHash: Fr, - public readonly publicKeysHash: Fr, + public readonly publicKeys: PublicKeys, public readonly deployer: AztecAddress, ) {} @@ -40,7 +41,7 @@ export class ContractInstanceDeployedEvent { const salt = reader.readObject(Fr); const contractClassId = reader.readObject(Fr); const initializationHash = reader.readObject(Fr); - const publicKeysHash = reader.readObject(Fr); + const publicKeys = reader.readObject(PublicKeys); const deployer = reader.readObject(AztecAddress); return new ContractInstanceDeployedEvent( @@ -49,7 +50,7 @@ export class ContractInstanceDeployedEvent { salt, contractClassId, initializationHash, - publicKeysHash, + publicKeys, deployer, ); } @@ -64,7 +65,7 @@ export class ContractInstanceDeployedEvent { version: this.version, contractClassId: this.contractClassId, initializationHash: this.initializationHash, - publicKeysHash: this.publicKeysHash, + publicKeys: this.publicKeys, salt: this.salt, deployer: this.deployer, }; diff --git a/yarn-project/circuits.js/src/contract/interfaces/contract_instance.ts b/yarn-project/circuits.js/src/contract/interfaces/contract_instance.ts index 3c3a9923a0f..24d6dc83f2b 100644 --- a/yarn-project/circuits.js/src/contract/interfaces/contract_instance.ts +++ b/yarn-project/circuits.js/src/contract/interfaces/contract_instance.ts @@ -1,6 +1,8 @@ import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { type Fr } from '@aztec/foundation/fields'; +import { type PublicKeys } from '../../types/public_keys.js'; + const VERSION = 1 as const; /** A contract instance is a concrete deployment of a contract class. A contract instance always references a contract class, which dictates what code it executes when called. A contract instance has state (both private and public), as well as an address that acts as its identifier. A contract instance can be called into. */ @@ -15,8 +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. */ - publicKeysHash: Fr; + publicKeys: PublicKeys; } export type ContractInstanceWithAddress = ContractInstance & { address: AztecAddress }; diff --git a/yarn-project/circuits.js/src/structs/avm/avm.ts b/yarn-project/circuits.js/src/structs/avm/avm.ts index 6239bf2c951..c6613d726ab 100644 --- a/yarn-project/circuits.js/src/structs/avm/avm.ts +++ b/yarn-project/circuits.js/src/structs/avm/avm.ts @@ -2,6 +2,7 @@ import { Fr } from '@aztec/foundation/fields'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { type FieldsOf } from '@aztec/foundation/types'; +import { PublicKeys } from '../../types/public_keys.js'; import { Gas } from '../gas.js'; import { PublicCircuitPublicInputs } from '../public_circuit_public_inputs.js'; import { Vector } from '../shared.js'; @@ -176,7 +177,7 @@ export class AvmContractInstanceHint { public readonly deployer: Fr, public readonly contractClassId: Fr, public readonly initializationHash: Fr, - public readonly publicKeysHash: Fr, + public readonly publicKeys: PublicKeys, ) {} /** * Serializes the inputs to a buffer. @@ -206,7 +207,7 @@ export class AvmContractInstanceHint { this.deployer.isZero() && this.contractClassId.isZero() && this.initializationHash.isZero() && - this.publicKeysHash.isZero() + this.publicKeys.isEmpty() ); } @@ -216,7 +217,17 @@ export class AvmContractInstanceHint { * @returns A new AvmHint instance. */ static from(fields: FieldsOf): AvmContractInstanceHint { - return new AvmContractInstanceHint(...AvmContractInstanceHint.getFields(fields)); + const contractInstanceHintFields = AvmContractInstanceHint.getFields(fields); + + return new AvmContractInstanceHint( + contractInstanceHintFields[0], + contractInstanceHintFields[1], + contractInstanceHintFields[2], + contractInstanceHintFields[3], + contractInstanceHintFields[4], + contractInstanceHintFields[5], + PublicKeys.fromFields(contractInstanceHintFields.slice(6, 18)), + ); } /** @@ -232,8 +243,8 @@ export class AvmContractInstanceHint { fields.deployer, fields.contractClassId, fields.initializationHash, - fields.publicKeysHash, - ] as const; + ...fields.publicKeys.toFields(), + ] as [Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr]; } /** @@ -250,7 +261,7 @@ export class AvmContractInstanceHint { Fr.fromBuffer(reader), Fr.fromBuffer(reader), Fr.fromBuffer(reader), - Fr.fromBuffer(reader), + PublicKeys.fromBuffer(reader), ); } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 969f981f30c..5b65b215483 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -116,6 +116,7 @@ import { PublicKernelCircuitPublicInputs, PublicKernelData, PublicKernelTailCircuitPrivateInputs, + PublicKeys, RECURSIVE_PROOF_LENGTH, ReadRequest, RevertCode, @@ -1427,7 +1428,12 @@ export function makeAvmContractInstanceHint(seed = 0): AvmContractInstanceHint { new Fr(seed + 0x3), new Fr(seed + 0x4), new Fr(seed + 0x5), - new Fr(seed + 0x6), + new PublicKeys( + new Point(new Fr(seed + 0x6), new Fr(seed + 0x7), false), + new Point(new Fr(seed + 0x8), new Fr(seed + 0x9), false), + new Point(new Fr(seed + 0x10), new Fr(seed + 0x11), false), + new Point(new Fr(seed + 0x12), new Fr(seed + 0x13), false), + ), ); } diff --git a/yarn-project/circuits.js/src/types/public_keys.ts b/yarn-project/circuits.js/src/types/public_keys.ts index b20a36e9661..57bb3400d50 100644 --- a/yarn-project/circuits.js/src/types/public_keys.ts +++ b/yarn-project/circuits.js/src/types/public_keys.ts @@ -45,6 +45,10 @@ export class PublicKeys { return new PublicKeys(Point.ZERO, Point.ZERO, Point.ZERO, Point.ZERO); } + static random(): PublicKeys { + return new PublicKeys(Point.random(), Point.random(), Point.random(), Point.random()); + } + /** * Determines if this PublicKeys instance is equal to the given PublicKeys instance. * Equality is based on the content of their respective buffers. diff --git a/yarn-project/cli-wallet/src/cmds/deploy.ts b/yarn-project/cli-wallet/src/cmds/deploy.ts index 5d5779b41b6..71d131d444b 100644 --- a/yarn-project/cli-wallet/src/cmds/deploy.ts +++ b/yarn-project/cli-wallet/src/cmds/deploy.ts @@ -1,5 +1,5 @@ import { type AccountWalletWithSecretKey, ContractDeployer, type DeployMethod, Fr, type PXE } from '@aztec/aztec.js'; -import { type PublicKeys } from '@aztec/circuits.js'; +import { PublicKeys } from '@aztec/circuits.js'; import { GITHUB_TAG_PREFIX, encodeArgs, getContractArtifact } from '@aztec/cli/utils'; import { getInitializer } from '@aztec/foundation/abi'; import { type DebugLogger, type LogFn } from '@aztec/foundation/log'; @@ -37,7 +37,7 @@ export async function deploy( ); } - const deployer = new ContractDeployer(contractArtifact, wallet, publicKeys?.hash() ?? Fr.ZERO, initializer); + const deployer = new ContractDeployer(contractArtifact, wallet, publicKeys ?? PublicKeys.empty(), initializer); let args = []; if (rawArgs.length > 0) { diff --git a/yarn-project/cli/src/cmds/pxe/add_contract.ts b/yarn-project/cli/src/cmds/pxe/add_contract.ts index b83ce19bd70..cd81ccc00d1 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 { PublicKeys } from '@aztec/circuits.js'; import { computeContractAddressFromInstance } from '@aztec/circuits.js/contract'; import { type DebugLogger, type LogFn } from '@aztec/foundation/log'; @@ -23,7 +23,7 @@ export async function addContract( salt, initializationHash, contractClassId: getContractClassFromArtifact(artifact).id, - publicKeysHash: publicKeys?.hash() ?? Fr.ZERO, + publicKeys: publicKeys ?? PublicKeys.empty(), address, deployer: deployer ?? AztecAddress.ZERO, }; diff --git a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts index 50875af260d..42af1309103 100644 --- a/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts +++ b/yarn-project/end-to-end/src/e2e_crowdfunding_and_claim.test.ts @@ -57,7 +57,7 @@ describe('e2e_crowdfunding_and_claim', () => { let claimContract: ClaimContract; let crowdfundingSecretKey; - let crowdfundingPublicKeysHash; + let crowdfundingPublicKeys; let pxe: PXE; let cheatCodes: CheatCodes; let deadline: number; // end of crowdfunding period @@ -114,10 +114,10 @@ describe('e2e_crowdfunding_and_claim', () => { logger.info(`Reward Token deployed to ${rewardToken.address}`); crowdfundingSecretKey = Fr.random(); - crowdfundingPublicKeysHash = deriveKeys(crowdfundingSecretKey).publicKeys.hash(); + crowdfundingPublicKeys = deriveKeys(crowdfundingSecretKey).publicKeys; - const crowdfundingDeployment = CrowdfundingContract.deployWithPublicKeysHash( - crowdfundingPublicKeysHash, + const crowdfundingDeployment = CrowdfundingContract.deployWithPublicKeys( + crowdfundingPublicKeys, operatorWallet, donationToken.address, operatorWallet.getAddress(), 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 3f7379ee526..36641e9296b 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 { type ContractClassIdPreimage, PublicKeys } 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', () => { @@ -148,7 +148,7 @@ describe('e2e_deploy_contract contract class registration', () => { expect(deployed!.address).toEqual(instance.address); expect(deployed!.contractClassId).toEqual(contractClass.id); expect(deployed!.initializationHash).toEqual(instance.initializationHash); - expect(deployed!.publicKeysHash).toEqual(instance.publicKeysHash); + expect(deployed!.publicKeys).toEqual(instance.publicKeys); expect(deployed!.salt).toEqual(instance.salt); expect(deployed!.deployer).toEqual(instance.deployer); }); 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 ffafbb038e7..ec32d515422 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 @@ -8,6 +8,7 @@ import { type DebugLogger, Fr, type PXE, + type PublicKeys, type Wallet, createDebugLogger, getContractInstanceFromDeployParams, @@ -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 3c085962cf8..595a13e31ed 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); 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/end-to-end/src/e2e_escrow_contract.test.ts b/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts index d21c675cdc7..610617d419d 100644 --- a/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_escrow_contract.test.ts @@ -10,7 +10,7 @@ import { computeSecretHash, deriveKeys, } from '@aztec/aztec.js'; -import { computePartialAddress } from '@aztec/circuits.js'; +import { type PublicKeys, computePartialAddress } from '@aztec/circuits.js'; import { EscrowContract } from '@aztec/noir-contracts.js/Escrow'; import { TokenContract } from '@aztec/noir-contracts.js/Token'; @@ -30,7 +30,7 @@ describe('e2e_escrow_contract', () => { let recipient: AztecAddress; let escrowSecretKey: Fr; - let escrowPublicKeysHash: Fr; + let escrowPublicKeys: PublicKeys; beforeEach(async () => { // Setup environment @@ -46,8 +46,8 @@ describe('e2e_escrow_contract', () => { // Generate private key for escrow contract, register key in pxe service, and deploy // Note that we need to register it first if we want to emit an encrypted note for it in the constructor escrowSecretKey = Fr.random(); - escrowPublicKeysHash = deriveKeys(escrowSecretKey).publicKeys.hash(); - const escrowDeployment = EscrowContract.deployWithPublicKeysHash(escrowPublicKeysHash, wallet, owner); + escrowPublicKeys = deriveKeys(escrowSecretKey).publicKeys; + const escrowDeployment = EscrowContract.deployWithPublicKeys(escrowPublicKeys, wallet, owner); const escrowInstance = escrowDeployment.getInstance(); await pxe.registerAccount(escrowSecretKey, computePartialAddress(escrowInstance)); escrowContract = await escrowDeployment.send().deployed(); diff --git a/yarn-project/end-to-end/src/e2e_fees/account_init.test.ts b/yarn-project/end-to-end/src/e2e_fees/account_init.test.ts index 0a3c08f7f5e..4cd12d6eeec 100644 --- a/yarn-project/end-to-end/src/e2e_fees/account_init.test.ts +++ b/yarn-project/end-to-end/src/e2e_fees/account_init.test.ts @@ -183,7 +183,7 @@ describe('e2e_fees account_init', () => { const [alicesInitialGas] = await t.getGasBalanceFn(aliceAddress); // bob generates the private keys for his account on his own - const bobsPublicKeysHash = deriveKeys(bobsSecretKey).publicKeys.hash(); + const bobsPublicKeys = deriveKeys(bobsSecretKey).publicKeys; const bobsSigningPubKey = new Schnorr().computePublicKey(bobsPrivateSigningKey); const bobsInstance = bobsAccountManager.getInstance(); @@ -192,8 +192,8 @@ describe('e2e_fees account_init', () => { // and deploys bob's account, paying the fee from her balance const paymentMethod = new FeeJuicePaymentMethod(aliceAddress); - const tx = await SchnorrAccountContract.deployWithPublicKeysHash( - bobsPublicKeysHash, + const tx = await SchnorrAccountContract.deployWithPublicKeys( + bobsPublicKeys, aliceWallet, bobsSigningPubKey.x, bobsSigningPubKey.y, diff --git a/yarn-project/end-to-end/src/e2e_new_addresses.test.ts b/yarn-project/end-to-end/src/e2e_new_addresses.test.ts new file mode 100644 index 00000000000..0cd726e2365 --- /dev/null +++ b/yarn-project/end-to-end/src/e2e_new_addresses.test.ts @@ -0,0 +1,20 @@ +import { type Logger } from '@aztec/foundation/log'; + +import { beforeEach, describe, it } from '@jest/globals'; + +import { setup } from './fixtures/utils.js'; + +describe('e2e new addresses', () => { + let teardown: () => void; + let logger: Logger; + + beforeEach(async () => { + ({ teardown, logger } = await setup(1)); + }); + + afterAll(() => teardown()); + + it('Correctly runs setup', () => { + logger.info('Done'); + }); +}); diff --git a/yarn-project/end-to-end/src/shared/browser.ts b/yarn-project/end-to-end/src/shared/browser.ts index fe70c7f5acc..65d6a150aef 100644 --- a/yarn-project/end-to-end/src/shared/browser.ts +++ b/yarn-project/end-to-end/src/shared/browser.ts @@ -246,7 +246,7 @@ export const browserTestSuite = ( const owner = knownAccounts[0]; const ownerAddress = owner.getAddress(); const tx = new DeployMethod( - owner.getCompleteAddress().publicKeys.hash(), + owner.getCompleteAddress().publicKeys, owner, TokenContractArtifact, (a: AztecJs.AztecAddress) => Contract.at(a, TokenContractArtifact, owner), diff --git a/yarn-project/ivc-integration/src/avm_integration.test.ts b/yarn-project/ivc-integration/src/avm_integration.test.ts index 424d91212b5..c5dd1dddd77 100644 --- a/yarn-project/ivc-integration/src/avm_integration.test.ts +++ b/yarn-project/ivc-integration/src/avm_integration.test.ts @@ -11,6 +11,7 @@ import { FunctionSelector, Gas, GlobalVariables, + PublicKeys, SerializableContractInstance, } from '@aztec/circuits.js'; import { @@ -20,7 +21,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'; @@ -163,7 +164,12 @@ const proveAvmTestContract = async ( deployer: new Fr(0x456), contractClassId: new Fr(0x789), initializationHash: new Fr(0x101112), - publicKeysHash: new Fr(0x161718), + publicKeys: new PublicKeys( + new Point(new Fr(0x131415), new Fr(0x161718), false), + new Point(new Fr(0x192021), new Fr(0x222324), false), + new Point(new Fr(0x252627), new Fr(0x282930), false), + new Point(new Fr(0x313233), new Fr(0x343536), false), + ), }).withAddress(environment.address); worldStateDB.getContractInstance.mockResolvedValue(await Promise.resolve(contractInstance)); 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 e9411e3d587..2fbc53f23e8 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 @@ -3,6 +3,7 @@ import { type ContractClass, type ContractInstance, FunctionSelector, + PublicKeys, computeContractAddressFromInstance, computeContractClassId, computeContractClassIdPreimage, @@ -18,13 +19,13 @@ 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), + publicKeys: PublicKeys.empty(), salt: new Fr(56789), privateFunctions: [ { selector: FunctionSelector.fromField(new Fr(1010101)), vkHash: new Fr(0) }, @@ -36,7 +37,7 @@ describe('Data generation for noir tests', () => { const parentContract: FixtureContractData = { artifactHash: new Fr(1212), packedBytecode: Buffer.from([3, 4, 3, 4]), - publicKeysHash: new Fr(4545), + publicKeys: PublicKeys.empty(), salt: new Fr(5656), privateFunctions: [{ selector: FunctionSelector.fromField(new Fr(334455)), vkHash: new Fr(0) }], toString: () => 'parentContract', @@ -70,7 +71,7 @@ describe('Data generation for noir tests', () => { address: `AztecAddress { inner: ${address.toString()} }`, partial_address: `PartialAddress { inner: ${partialAddress.toString()} }`, contract_class_id: `ContractClassId { inner: ${contractClassId.toString()} }`, - public_keys_hash: `PublicKeysHash { inner: ${contract.publicKeysHash.toString()} }`, + public_keys_hash: `PublicKeys { inner: ${contract.publicKeys.toString()} }`, salted_initialization_hash: `SaltedInitializationHash { inner: ${saltedInitializationHash.toString()} }`, deployer: `AztecAddress { inner: ${deployer.toString()} }`, }), diff --git a/yarn-project/protocol-contracts/src/protocol_contract_data.ts b/yarn-project/protocol-contracts/src/protocol_contract_data.ts index 65c74d2c8f5..7cc5bfad540 100644 --- a/yarn-project/protocol-contracts/src/protocol_contract_data.ts +++ b/yarn-project/protocol-contracts/src/protocol_contract_data.ts @@ -51,7 +51,7 @@ export const ProtocolContractAddress: Record export const ProtocolContractLeaf = { AuthRegistry: Fr.fromString('0x2ace300b02ca5ab0a25052b1e852913a47292096997ca09f758c0e3624e84560'), - ContractInstanceDeployer: Fr.fromString('0x25d93dc07b5baaf53a98caeae2679df3528cb83e11e2640a57a0a53abbaaadb9'), + ContractInstanceDeployer: Fr.fromString('0x21e432f60f69ac5eb7582c26c03c6c7e4a3eb577720774bc8e1521561ca752a1'), ContractClassRegisterer: Fr.fromString('0x1b6d5873cef5a35f681ab9468527f356c96e09b3c64603aef404ec2ad80aa3a9'), MultiCallEntrypoint: Fr.fromString('0x0966ead8d11933bb3c72547bb997898971715f2275acd4c7d5d86fdf614ba1a2'), FeeJuice: Fr.fromString('0x24388f7ef1b9c9e661721f3331a989a2f10cba300539471e4401c38629b27816'), @@ -59,5 +59,5 @@ export const ProtocolContractLeaf = { }; export const protocolContractTreeRoot = Fr.fromString( - '0x25e5bd75edc23b6b74ef6235acd1a1a27bcada41199a11c089a1c4e3e59bc774', + '0x0ce9f44ae6605f375e5f5267ceb769861703ce8e4235f16f7afc137ec34dcf06', ); 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 d6b0dc1385f..9faad730fc1 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.test.ts @@ -17,6 +17,7 @@ import { PrivateCircuitPublicInputs, PrivateKernelCircuitPublicInputs, PrivateKernelTailCircuitPublicInputs, + PublicKeys, ScopedNoteHash, type TxRequest, VK_TREE_HEIGHT, @@ -147,7 +148,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 9101803cadf..2ef1b61f69b 100644 --- a/yarn-project/pxe/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/pxe/src/kernel_prover/kernel_prover.ts @@ -208,7 +208,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 } = @@ -225,7 +225,7 @@ export class KernelProver { return PrivateCallData.from({ callStackItem, vk, - publicKeysHash, + publicKeysHash: publicKeys.hash(), 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 5511100a5e1..9143e941250 100644 --- a/yarn-project/pxe/src/kernel_prover/proving_data_oracle.ts +++ b/yarn-project/pxe/src/kernel_prover/proving_data_oracle.ts @@ -7,6 +7,7 @@ import { type MembershipWitness, type NOTE_HASH_TREE_HEIGHT, type Point, + PublicKeys, type VK_TREE_HEIGHT, type VerificationKeyAsFields, } from '@aztec/circuits.js'; @@ -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/simulator/src/acvm/oracle/oracle.ts b/yarn-project/simulator/src/acvm/oracle/oracle.ts index 9a93f41e2a4..a2b53d7987d 100644 --- a/yarn-project/simulator/src/acvm/oracle/oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/oracle.ts @@ -70,7 +70,7 @@ export class Oracle { instance.deployer, instance.contractClassId, instance.initializationHash, - instance.publicKeysHash, + ...instance.publicKeys.toFields(), ].map(toACVMField); } diff --git a/yarn-project/simulator/src/avm/avm_simulator.test.ts b/yarn-project/simulator/src/avm/avm_simulator.test.ts index 521e6c5b257..a4f36f95f3f 100644 --- a/yarn-project/simulator/src/avm/avm_simulator.test.ts +++ b/yarn-project/simulator/src/avm/avm_simulator.test.ts @@ -1,10 +1,10 @@ -import { GasFees } from '@aztec/circuits.js'; +import { GasFees, PublicKeys } from '@aztec/circuits.js'; import { Grumpkin } from '@aztec/circuits.js/barretenberg'; 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'; @@ -839,7 +839,12 @@ describe('AVM simulator: transpiled Noir contracts', () => { deployer: AztecAddress.fromBigInt(0x456n), contractClassId: new Fr(0x789), initializationHash: new Fr(0x101112), - publicKeysHash: new Fr(0x161718), + publicKeys: new PublicKeys( + new Point(new Fr(0x131415), new Fr(0x161718), false), + new Point(new Fr(0x192021), new Fr(0x222324), false), + new Point(new Fr(0x252627), new Fr(0x282930), false), + new Point(new Fr(0x313233), new Fr(0x343536), false), + ), }; mockGetContractInstance(worldStateDB, contractInstance); diff --git a/yarn-project/simulator/src/avm/opcodes/contract.test.ts b/yarn-project/simulator/src/avm/opcodes/contract.test.ts index 0beaf45e886..7247b38575d 100644 --- a/yarn-project/simulator/src/avm/opcodes/contract.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/contract.test.ts @@ -59,7 +59,7 @@ describe('Contract opcodes', () => { new Field(contractInstance.deployer), new Field(contractInstance.contractClassId), new Field(contractInstance.initializationHash), - new Field(contractInstance.publicKeysHash), + ...contractInstance.publicKeys.toFields().map(f => new Field(f)), ]); expect(trace.traceGetContractInstance).toHaveBeenCalledTimes(1); diff --git a/yarn-project/simulator/src/avm/opcodes/contract.ts b/yarn-project/simulator/src/avm/opcodes/contract.ts index e8c7c743479..b825122bc30 100644 --- a/yarn-project/simulator/src/avm/opcodes/contract.ts +++ b/yarn-project/simulator/src/avm/opcodes/contract.ts @@ -39,7 +39,8 @@ export class GetContractInstance extends Instruction { instance.deployer.toField(), instance.contractClassId, instance.initializationHash, - instance.publicKeysHash, + // This this okay ? + ...instance.publicKeys.toFields(), ].map(f => new Field(f)); memory.setSlice(dstOffset, data); diff --git a/yarn-project/simulator/src/public/enqueued_call_side_effect_trace.ts b/yarn-project/simulator/src/public/enqueued_call_side_effect_trace.ts index 5b2ec340990..547b719c93f 100644 --- a/yarn-project/simulator/src/public/enqueued_call_side_effect_trace.ts +++ b/yarn-project/simulator/src/public/enqueued_call_side_effect_trace.ts @@ -319,7 +319,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI instance.deployer, instance.contractClassId, instance.initializationHash, - instance.publicKeysHash, + instance.publicKeys, ), ); this.log.debug(`CONTRACT_INSTANCE cnt: ${this.sideEffectCounter}`); diff --git a/yarn-project/simulator/src/public/side_effect_trace.ts b/yarn-project/simulator/src/public/side_effect_trace.ts index f3a47dde6b4..f023e09adbe 100644 --- a/yarn-project/simulator/src/public/side_effect_trace.ts +++ b/yarn-project/simulator/src/public/side_effect_trace.ts @@ -222,7 +222,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface { instance.deployer, instance.contractClassId, instance.initializationHash, - instance.publicKeysHash, + instance.publicKeys, ), ); this.logger.debug(`CONTRACT_INSTANCE cnt: ${this.sideEffectCounter}`); diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index e97311d7772..fc9dfa004a0 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'; @@ -100,6 +101,7 @@ export class TXEService { initializer: ForeignCallArray, _length: ForeignCallSingle, args: ForeignCallArray, + // TODO: Fix this publicKeysHash: ForeignCallSingle, ) { const initializerStr = fromArray(initializer) @@ -115,7 +117,7 @@ export class TXEService { constructorArgs: decodedArgs, skipArgsDecoding: true, salt: Fr.ONE, - publicKeysHash: publicKeysHashFr, + publicKeys: PublicKeys.empty(), constructorArtifact: initializerStr ? initializerStr : undefined, deployer: AztecAddress.ZERO, }); @@ -129,7 +131,7 @@ export class TXEService { instance.deployer, instance.contractClassId, instance.initializationHash, - instance.publicKeysHash, + instance.publicKeys.hash(), ]), ]); } @@ -173,13 +175,12 @@ 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 artifact = SchnorrAccountContractArtifact; const instance = getContractInstanceFromDeployParams(artifact, { constructorArgs: args, skipArgsDecoding: true, salt: Fr.ONE, - publicKeysHash: hash, + publicKeys: keys.publicKeys, constructorArtifact: 'constructor', deployer: AztecAddress.ZERO, }); @@ -508,7 +509,7 @@ export class TXEService { instance.deployer, instance.contractClassId, instance.initializationHash, - instance.publicKeysHash, + instance.publicKeys.hash(), ]), ]); } @@ -523,7 +524,7 @@ export class TXEService { instance.deployer, instance.contractClassId, instance.initializationHash, - instance.publicKeysHash, + instance.publicKeys.hash(), ]), ]); }