diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index c116f738515..00d0f84eaea 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -765,8 +765,8 @@ export class Archiver implements ArchiveSource, Traceable { return; } - registerContractFunctionNames(address: AztecAddress, names: Record): Promise { - return this.store.registerContractFunctionName(address, names); + registerContractFunctionSignatures(address: AztecAddress, signatures: string[]): Promise { + return this.store.registerContractFunctionSignatures(address, signatures); } getContractFunctionName(address: AztecAddress, selector: FunctionSelector): Promise { @@ -1073,8 +1073,8 @@ class ArchiverStoreHelper getContractClassIds(): Promise { return this.store.getContractClassIds(); } - registerContractFunctionName(address: AztecAddress, names: Record): Promise { - return this.store.registerContractFunctionName(address, names); + registerContractFunctionSignatures(address: AztecAddress, signatures: string[]): Promise { + return this.store.registerContractFunctionSignatures(address, signatures); } getContractFunctionName(address: AztecAddress, selector: FunctionSelector): Promise { return this.store.getContractFunctionName(address, selector); diff --git a/yarn-project/archiver/src/archiver/archiver_store.ts b/yarn-project/archiver/src/archiver/archiver_store.ts index d2056cba085..a68798c2d34 100644 --- a/yarn-project/archiver/src/archiver/archiver_store.ts +++ b/yarn-project/archiver/src/archiver/archiver_store.ts @@ -264,7 +264,7 @@ export interface ArchiverDataStore { // TODO: These function names are in memory only as they are for development/debugging. They require the full contract // artifact supplied to the node out of band. This should be reviewed and potentially removed as part of // the node api cleanup process. - registerContractFunctionName(address: AztecAddress, names: Record): Promise; + registerContractFunctionSignatures(address: AztecAddress, signatures: string[]): Promise; getContractFunctionName(address: AztecAddress, selector: FunctionSelector): Promise; /** diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts index ac12a3ba185..85b670c5483 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.ts @@ -17,7 +17,7 @@ import { type PrivateLog, type UnconstrainedFunctionWithMembershipProof, } from '@aztec/circuits.js'; -import { type FunctionSelector } from '@aztec/foundation/abi'; +import { FunctionSelector } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { createLogger } from '@aztec/foundation/log'; import { type AztecKVStore } from '@aztec/kv-store'; @@ -62,9 +62,14 @@ export class KVArchiverDataStore implements ArchiverDataStore { return Promise.resolve(this.functionNames.get(selector.toString())); } - registerContractFunctionName(_address: AztecAddress, names: Record): Promise { - for (const [selector, name] of Object.entries(names)) { - this.functionNames.set(selector, name); + registerContractFunctionSignatures(_address: AztecAddress, signatures: string[]): Promise { + for (const sig of signatures) { + try { + const selector = FunctionSelector.fromSignature(sig); + this.functionNames.set(selector.toString(), sig.slice(0, sig.indexOf('('))); + } catch { + this.#log.warn(`Failed to parse signature: ${sig}. Ignoring`); + } } return Promise.resolve(); diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts index fab9073e458..5706083aab5 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts @@ -28,7 +28,7 @@ import { type PrivateLog, type UnconstrainedFunctionWithMembershipProof, } from '@aztec/circuits.js'; -import { type FunctionSelector } from '@aztec/foundation/abi'; +import { FunctionSelector } from '@aztec/foundation/abi'; import { type AztecAddress } from '@aztec/foundation/aztec-address'; import { createLogger } from '@aztec/foundation/log'; @@ -734,9 +734,14 @@ export class MemoryArchiverStore implements ArchiverDataStore { return Promise.resolve(this.functionNames.get(selector.toString())); } - public registerContractFunctionName(_address: AztecAddress, names: Record): Promise { - for (const [selector, name] of Object.entries(names)) { - this.functionNames.set(selector, name); + public registerContractFunctionSignatures(_address: AztecAddress, signatures: string[]): Promise { + for (const sig of signatures) { + try { + const selector = FunctionSelector.fromSignature(sig); + this.functionNames.set(selector.toString(), sig.slice(0, sig.indexOf('('))); + } catch { + this.#log.warn(`Failed to parse signature: ${sig}. Ignoring`); + } } return Promise.resolve(); diff --git a/yarn-project/archiver/src/factory.ts b/yarn-project/archiver/src/factory.ts index 018cbec57f9..fee2c5325ad 100644 --- a/yarn-project/archiver/src/factory.ts +++ b/yarn-project/archiver/src/factory.ts @@ -4,7 +4,7 @@ import { computePublicBytecodeCommitment, getContractClassFromArtifact, } from '@aztec/circuits.js'; -import { FunctionSelector, FunctionType } from '@aztec/foundation/abi'; +import { FunctionType, decodeFunctionSignature } from '@aztec/foundation/abi'; import { createLogger } from '@aztec/foundation/log'; import { type Maybe } from '@aztec/foundation/types'; import { type DataStoreConfig } from '@aztec/kv-store/config'; @@ -47,14 +47,11 @@ async function registerProtocolContracts(store: KVArchiverDataStore) { unconstrainedFunctions: [], }; - const functionNames: Record = {}; - for (const fn of contract.artifact.functions) { - if (fn.functionType === FunctionType.PUBLIC) { - functionNames[FunctionSelector.fromNameAndParameters(fn.name, fn.parameters).toString()] = fn.name; - } - } + const publicFunctionSignatures = contract.artifact.functions + .filter(fn => fn.functionType === FunctionType.PUBLIC) + .map(fn => decodeFunctionSignature(fn.name, fn.parameters)); - await store.registerContractFunctionName(contract.address, functionNames); + await store.registerContractFunctionSignatures(contract.address, publicFunctionSignatures); const bytecodeCommitment = computePublicBytecodeCommitment(contractClassPublic.packedBytecode); await store.addContractClasses([contractClassPublic], [bytecodeCommitment], blockNumber); await store.addContractInstances([contract.instance], blockNumber); diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 59ba35913fe..6d5177b601b 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -900,8 +900,8 @@ export class AztecNodeService implements AztecNode, Traceable { return this.contractDataSource.addContractClass(contractClass); } - public registerContractFunctionNames(_address: AztecAddress, names: Record): Promise { - return this.contractDataSource.registerContractFunctionNames(_address, names); + public registerContractFunctionSignatures(_address: AztecAddress, signatures: string[]): Promise { + return this.contractDataSource.registerContractFunctionSignatures(_address, signatures); } public flushTxs(): Promise { diff --git a/yarn-project/circuit-types/src/interfaces/archiver.test.ts b/yarn-project/circuit-types/src/interfaces/archiver.test.ts index 4824b95365a..6fb11778391 100644 --- a/yarn-project/circuit-types/src/interfaces/archiver.test.ts +++ b/yarn-project/circuit-types/src/interfaces/archiver.test.ts @@ -222,10 +222,8 @@ describe('ArchiverApiSchema', () => { expect(result).toBe(1n); }); - it('registerContractFunctionNames', async () => { - await context.client.registerContractFunctionNames(AztecAddress.random(), { - [FunctionSelector.random().toString()]: 'test_fn', - }); + it('registerContractFunctionSignatures', async () => { + await context.client.registerContractFunctionSignatures(AztecAddress.random(), ['test()']); }); it('getContract', async () => { @@ -374,9 +372,9 @@ class MockArchiver implements ArchiverApi { expect(address).toBeInstanceOf(AztecAddress); return Promise.resolve(this.artifact); } - registerContractFunctionNames(address: AztecAddress, names: Record): Promise { + registerContractFunctionSignatures(address: AztecAddress, signatures: string[]): Promise { expect(address).toBeInstanceOf(AztecAddress); - expect(names).toEqual(expect.any(Object)); + expect(Array.isArray(signatures)).toBe(true); return Promise.resolve(); } getL1ToL2Messages(blockNumber: bigint): Promise { diff --git a/yarn-project/circuit-types/src/interfaces/archiver.ts b/yarn-project/circuit-types/src/interfaces/archiver.ts index 302df9b5732..fe67917ee68 100644 --- a/yarn-project/circuit-types/src/interfaces/archiver.ts +++ b/yarn-project/circuit-types/src/interfaces/archiver.ts @@ -68,10 +68,7 @@ export const ArchiverApiSchema: ApiSchemaFor = { getBytecodeCommitment: z.function().args(schemas.Fr).returns(schemas.Fr), getContract: z.function().args(schemas.AztecAddress).returns(ContractInstanceWithAddressSchema.optional()), getContractClassIds: z.function().args().returns(z.array(schemas.Fr)), - registerContractFunctionNames: z - .function() - .args(schemas.AztecAddress, z.record(z.string(), z.string())) - .returns(z.void()), + registerContractFunctionSignatures: z.function().args(schemas.AztecAddress, z.array(z.string())).returns(z.void()), getL1ToL2Messages: z.function().args(schemas.BigInt).returns(z.array(schemas.Fr)), getL1ToL2MessageIndex: z.function().args(schemas.Fr).returns(schemas.BigInt.optional()), // TODO(#10007): Remove this method diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.test.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.test.ts index 53fee1105c6..4db6f2923cd 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.test.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.test.ts @@ -19,7 +19,7 @@ import { getContractClassFromArtifact, } from '@aztec/circuits.js'; import { type L1ContractAddresses, L1ContractsNames } from '@aztec/ethereum'; -import { type ContractArtifact, FunctionSelector } from '@aztec/foundation/abi'; +import { type ContractArtifact } from '@aztec/foundation/abi'; import { memoize } from '@aztec/foundation/decorators'; import { type JsonRpcTestContext, createJsonRpcTestSetup } from '@aztec/foundation/json-rpc/test'; import { fileURLToPath } from '@aztec/foundation/url'; @@ -223,10 +223,8 @@ describe('AztecNodeApiSchema', () => { expect(response).toEqual(Object.fromEntries(ProtocolContractsNames.map(name => [name, expect.any(AztecAddress)]))); }); - it('registerContractFunctionNames', async () => { - await context.client.registerContractFunctionNames(AztecAddress.random(), { - [FunctionSelector.random().toString()]: 'test_fn', - }); + it('registerContractFunctionSignatures', async () => { + await context.client.registerContractFunctionSignatures(AztecAddress.random(), ['test()']); }); it('getPrivateLogs', async () => { @@ -506,7 +504,7 @@ class MockAztecNode implements AztecNode { ) as ProtocolContractAddresses, ); } - registerContractFunctionNames(_address: AztecAddress, _names: Record): Promise { + registerContractFunctionSignatures(_address: AztecAddress, _signatures: string[]): Promise { return Promise.resolve(); } getPrivateLogs(_from: number, _limit: number): Promise { diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.ts index f4b052b87fd..65d25082463 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.ts @@ -286,7 +286,7 @@ export interface AztecNode * @param aztecAddress * @param artifact */ - registerContractFunctionNames(address: AztecAddress, names: Record): Promise; + registerContractFunctionSignatures(address: AztecAddress, functionSignatures: string[]): Promise; /** * Retrieves all private logs from up to `limit` blocks, starting from the block number `from`. @@ -533,10 +533,7 @@ export const AztecNodeApiSchema: ApiSchemaFor = { getProtocolContractAddresses: z.function().returns(ProtocolContractAddressesSchema), - registerContractFunctionNames: z - .function() - .args(schemas.AztecAddress, z.record(z.string(), z.string())) - .returns(z.void()), + registerContractFunctionSignatures: z.function().args(schemas.AztecAddress, z.array(z.string())).returns(z.void()), getPrivateLogs: z.function().args(z.number(), z.number()).returns(z.array(PrivateLog.schema)), diff --git a/yarn-project/circuits.js/src/contract/interfaces/contract_data_source.ts b/yarn-project/circuits.js/src/contract/interfaces/contract_data_source.ts index 388a828b9cb..433e7ddd958 100644 --- a/yarn-project/circuits.js/src/contract/interfaces/contract_data_source.ts +++ b/yarn-project/circuits.js/src/contract/interfaces/contract_data_source.ts @@ -48,5 +48,5 @@ export interface ContractDataSource { /** Returns a function's name */ getContractFunctionName(address: AztecAddress, selector: FunctionSelector): Promise; /** Registers a function names. Useful for debugging. */ - registerContractFunctionNames(address: AztecAddress, names: Record): Promise; + registerContractFunctionSignatures(address: AztecAddress, signatures: string[]): Promise; } diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index ec8c0226d61..3307899021e 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -53,6 +53,7 @@ import { EventSelector, FunctionSelector, FunctionType, + decodeFunctionSignature, encodeArguments, } from '@aztec/foundation/abi'; import { Fr, type Point } from '@aztec/foundation/fields'; @@ -241,14 +242,10 @@ export class PXEService implements PXE { await this.db.addContractArtifact(contractClassId, artifact); - const functionNames: Record = {}; - for (const fn of artifact.functions) { - if (fn.functionType === FunctionType.PUBLIC) { - functionNames[FunctionSelector.fromNameAndParameters(fn.name, fn.parameters).toString()] = fn.name; - } - } - - await this.node.registerContractFunctionNames(instance.address, functionNames); + const publicFunctionSignatures = artifact.functions + .filter(fn => fn.functionType === FunctionType.PUBLIC) + .map(fn => decodeFunctionSignature(fn.name, fn.parameters)); + await this.node.registerContractFunctionSignatures(instance.address, publicFunctionSignatures); // TODO(#10007): Node should get public contract class from the registration event, not from PXE registration await this.node.addContractClass({ ...contractClass, privateFunctions: [], unconstrainedFunctions: [] }); diff --git a/yarn-project/simulator/src/public/fixtures/index.ts b/yarn-project/simulator/src/public/fixtures/index.ts index 36c126c0ef3..a3a02f05faa 100644 --- a/yarn-project/simulator/src/public/fixtures/index.ts +++ b/yarn-project/simulator/src/public/fixtures/index.ts @@ -219,7 +219,7 @@ export class MockedAvmTestContractDataSource implements ContractDataSource { return Promise.resolve(this.fnName); } - registerContractFunctionNames(_address: AztecAddress, _names: Record): Promise { + registerContractFunctionSignatures(_address: AztecAddress, _signatures: string[]): Promise { return Promise.resolve(); } } diff --git a/yarn-project/txe/src/node/txe_node.ts b/yarn-project/txe/src/node/txe_node.ts index c798e9a9ae0..edb6039f9bf 100644 --- a/yarn-project/txe/src/node/txe_node.ts +++ b/yarn-project/txe/src/node/txe_node.ts @@ -450,7 +450,7 @@ export class TXENode implements AztecNode { * @param aztecAddress * @param artifact */ - registerContractFunctionNames(_address: AztecAddress, _names: Record): Promise { + registerContractFunctionSignatures(_address: AztecAddress, _signatures: string[]): Promise { throw new Error('TXE Node method addContractArtifact not implemented'); } diff --git a/yarn-project/txe/src/util/txe_public_contract_data_source.ts b/yarn-project/txe/src/util/txe_public_contract_data_source.ts index 7d15b9d8d48..7d36fd880e7 100644 --- a/yarn-project/txe/src/util/txe_public_contract_data_source.ts +++ b/yarn-project/txe/src/util/txe_public_contract_data_source.ts @@ -85,7 +85,7 @@ export class TXEPublicContractDataSource implements ContractDataSource { return Promise.resolve(func?.name); } - registerContractFunctionNames(_address: AztecAddress, _names: Record): Promise { + registerContractFunctionSignatures(_address: AztecAddress, _signatures: []): Promise { return Promise.resolve(); }