From a4ca1f242f6ddd137f4031b1780bdc082c183b42 Mon Sep 17 00:00:00 2001 From: sklppy88 Date: Mon, 10 Feb 2025 15:16:29 +0000 Subject: [PATCH] init --- .../aztec/src/test/helpers/cheatcodes.nr | 6 ++--- .../src/test/helpers/test_environment.nr | 22 +++++++++++++++++-- .../aztec-nr/aztec/src/test/helpers/utils.nr | 10 ++++----- yarn-project/txe/src/index.ts | 16 +++++++++----- .../txe/src/txe_service/txe_service.ts | 6 ++++- 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr index d273db76f1e..d22cfc544b1 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr @@ -33,9 +33,9 @@ pub unconstrained fn deploy( name: str, initializer: str

, args: [Field], - public_keys_hash: Field, + secret: Field, ) -> ContractInstance { - let instance_fields = oracle_deploy(path, name, initializer, args, public_keys_hash); + let instance_fields = oracle_deploy(path, name, initializer, args, secret); ContractInstance::deserialize(instance_fields) } @@ -110,7 +110,7 @@ unconstrained fn oracle_deploy( name: str, initializer: str

, args: [Field], - public_keys_hash: Field, + secret: Field, ) -> [Field; CONTRACT_INSTANCE_LENGTH] {} #[oracle(directStorageWrite)] diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr index eba711b9f5b..d4101c31cae 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr @@ -95,11 +95,29 @@ impl TestEnvironment { path: str, name: str, ) -> Deployer { - Deployer { path, name, public_keys_hash: 0 } + Deployer { path, name, secret: 0 } } pub unconstrained fn deploy_self(_self: Self, name: str) -> Deployer<0, M> { - Deployer { path: "", name, public_keys_hash: 0 } + Deployer { path: "", name, secret: 0 } + } + + // Deploying with public keys assumes secret != 0 + pub unconstrained fn deploy_with_public_keys( + _self: Self, + path: str, + name: str, + secret: Field, + ) -> Deployer { + Deployer { path, name, secret } + } + + pub unconstrained fn deploy_self_with_public_keys( + _self: Self, + name: str, + secret: Field, + ) -> Deployer<0, M> { + Deployer { path: "", name, secret } } pub unconstrained fn assert_public_call_fails(_self: Self, call_interface: C) diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr index 3888f8fd5bd..3718f7a6218 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/utils.nr @@ -22,7 +22,7 @@ use crate::oracle::execution_cache; pub struct Deployer { pub path: str, pub name: str, - pub public_keys_hash: Field, + pub secret: Field, } impl Deployer { @@ -38,7 +38,7 @@ impl Deployer { self.name, call_interface.get_name(), call_interface.get_args(), - self.public_keys_hash, + self.secret, ); cheatcodes::advance_blocks_by(1); let inputs = cheatcodes::get_private_context_inputs(get_block_number() - 1); @@ -68,7 +68,7 @@ impl Deployer { self.name, call_interface.get_name(), call_interface.get_args(), - self.public_keys_hash, + self.secret, ); cheatcodes::advance_blocks_by(1); @@ -98,7 +98,7 @@ impl Deployer { self.name, call_interface.get_name(), call_interface.get_args(), - self.public_keys_hash, + self.secret, ); cheatcodes::advance_blocks_by(1); @@ -115,7 +115,7 @@ impl Deployer { } pub unconstrained fn without_initializer(self) -> ContractInstance { - cheatcodes::deploy(self.path, self.name, "", &[], self.public_keys_hash) + cheatcodes::deploy(self.path, self.name, "", &[], self.secret) } } diff --git a/yarn-project/txe/src/index.ts b/yarn-project/txe/src/index.ts index 51bd29cb8af..ec7fbfb9b0b 100644 --- a/yarn-project/txe/src/index.ts +++ b/yarn-project/txe/src/index.ts @@ -28,6 +28,7 @@ import { fromArray, fromSingle, toForeignCallResult, + toSingle, } from './util/encoding.js'; const TXESessions = new Map(); @@ -68,11 +69,13 @@ class TXEDispatcher { ); const decodedArgs = fromArray(inputs[4] as ForeignCallArray); - const publicKeysHashFr = fromSingle(inputs[5] as ForeignCallSingle); + const secret = fromSingle(inputs[5] as ForeignCallSingle); + const publicKeys = secret.equals(Fr.ZERO) ? PublicKeys.default() : (await deriveKeys(secret)).publicKeys; + const publicKeysHash = await publicKeys.hash(); const cacheKey = `${pathStr}-${contractName}-${initializer}-${decodedArgs .map(arg => arg.toString()) - .join('-')}-${publicKeysHashFr}`; + .join('-')}-${publicKeysHash.toString()}`; let artifact; let instance; @@ -105,21 +108,22 @@ class TXEDispatcher { this.logger.debug(`Loading compiled artifact ${artifactPath}`); artifact = loadContractArtifact(JSON.parse(await readFile(artifactPath, 'utf-8'))); this.logger.debug( - `Deploy ${artifact.name} with initializer ${initializer}(${decodedArgs}) and public keys hash ${publicKeysHashFr}`, + `Deploy ${ + artifact.name + } with initializer ${initializer}(${decodedArgs}) and public keys hash ${publicKeysHash.toString()}`, ); instance = await getContractInstanceFromDeployParams(artifact, { constructorArgs: decodedArgs, skipArgsDecoding: true, salt: Fr.ONE, - // TODO: Modify this to allow for passing public keys. - publicKeys: PublicKeys.default(), + publicKeys, constructorArtifact: initializer ? initializer : undefined, deployer: AztecAddress.ZERO, }); TXEArtifactsCache.set(cacheKey, { artifact, instance }); } - inputs.splice(0, 2, artifact, instance); + inputs.splice(0, 2, artifact, instance, toSingle(secret)); } async #processAddAccountInputs({ inputs }: TXEForeignCallInput) { diff --git a/yarn-project/txe/src/txe_service/txe_service.ts b/yarn-project/txe/src/txe_service/txe_service.ts index 5f88c20c7bd..76211e383a4 100644 --- a/yarn-project/txe/src/txe_service/txe_service.ts +++ b/yarn-project/txe/src/txe_service/txe_service.ts @@ -88,12 +88,16 @@ export class TXEService { return toForeignCallResult(keys.publicKeys.toFields().map(toSingle)); } - async deploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress) { + async deploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: ForeignCallSingle) { // Emit deployment nullifier (this.typedOracle as TXE).addSiloedNullifiersFromPublic([ await siloNullifier(AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS), instance.address.toField()), ]); + if (!fromSingle(secret).equals(Fr.ZERO)) { + await this.createAccount(secret); + } + this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`); await (this.typedOracle as TXE).addContractInstance(instance); await (this.typedOracle as TXE).addContractArtifact(instance.contractClassId, artifact);