diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 6aea2ba9550..8c7f0e3a476 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -1,8 +1,6 @@ import { ContractData, ContractDataSource, - EncodedContractFunction, - ExtendedContractData, GetUnencryptedLogsResponse, L1ToL2Message, L1ToL2MessageSource, @@ -27,7 +25,7 @@ import { DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { RunningPromise } from '@aztec/foundation/running-promise'; import { RollupAbi } from '@aztec/l1-artifacts'; import { ClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer'; -import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts'; +import { ContractClassPublic, ContractInstanceWithAddress, PublicFunction } from '@aztec/types/contracts'; import { Chain, HttpTransport, PublicClient, createPublicClient, getAddress, getContract, http } from 'viem'; @@ -425,37 +423,6 @@ export class Archiver implements ArchiveSource { return this.store.getSettledTxReceipt(txHash); } - /** - * Get the extended contract data for this contract. - * @param contractAddress - The contract data address. - * @returns The extended contract data or undefined if not found. - */ - public async getExtendedContractData(contractAddress: AztecAddress): Promise { - return ( - (await this.store.getExtendedContractData(contractAddress)) ?? this.makeExtendedContractDataFor(contractAddress) - ); - } - - /** - * Temporary method for creating a fake extended contract data out of classes and instances registered in the node. - * Used as a fallback if the extended contract data is not found. - * TODO(palla/purge-old-contract-deploy): Use proper classes - */ - private async makeExtendedContractDataFor(address: AztecAddress): Promise { - const instance = await this.store.getContractInstance(address); - if (!instance) { - return undefined; - } - - const contractClass = await this.store.getContractClass(instance.contractClassId); - if (!contractClass) { - this.log.warn(`Class ${instance.contractClassId.toString()} for address ${address.toString()} not found`); - return undefined; - } - - return ExtendedContractData.fromClassAndInstance(contractClass, instance); - } - /** * Lookup the contract data for this contract. * Contains contract address & the ethereum portal address. @@ -481,16 +448,23 @@ export class Archiver implements ArchiveSource { /** * Gets the public function data for a contract. - * @param contractAddress - The contract address containing the function to fetch. + * @param address - The contract address containing the function to fetch. * @param selector - The function selector of the function to fetch. * @returns The public function data (if found). */ public async getPublicFunction( - contractAddress: AztecAddress, + address: AztecAddress, selector: FunctionSelector, - ): Promise { - const contractData = await this.getExtendedContractData(contractAddress); - return contractData?.getPublicFunction(selector); + ): Promise { + const instance = await this.getContract(address); + if (!instance) { + throw new Error(`Contract ${address.toString()} not found`); + } + const contractClass = await this.getContractClass(instance.contractClassId); + if (!contractClass) { + throw new Error(`Contract class ${instance.contractClassId.toString()} for ${address.toString()} not found`); + } + return contractClass.publicFunctions.find(f => f.selector.equals(selector)); } /** diff --git a/yarn-project/archiver/src/archiver/archiver_store.ts b/yarn-project/archiver/src/archiver/archiver_store.ts index 23310be7e03..356c785248f 100644 --- a/yarn-project/archiver/src/archiver/archiver_store.ts +++ b/yarn-project/archiver/src/archiver/archiver_store.ts @@ -1,6 +1,5 @@ import { Body, - ExtendedContractData, GetUnencryptedLogsResponse, L1ToL2Message, L2Block, @@ -164,21 +163,6 @@ export interface ArchiverDataStore { */ getUnencryptedLogs(filter: LogFilter): Promise; - /** - * Add new extended contract data from an L2 block to the store's list. - * @param data - List of contracts' data to be added. - * @param blockNum - Number of the L2 block the contract data was deployed in. - * @returns True if the operation is successful. - */ - addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise; - - /** - * Get the extended contract data for this contract. - * @param contractAddress - The contract data address. - * @returns The extended contract data or undefined if not found. - */ - getExtendedContractData(contractAddress: AztecAddress): Promise; - /** * Gets the number of the latest L2 block processed. * @returns The number of the latest L2 block processed. diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/contract_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/contract_store.ts deleted file mode 100644 index 8278d75bb13..00000000000 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/contract_store.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { ExtendedContractData } from '@aztec/circuit-types'; -import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { createDebugLogger } from '@aztec/foundation/log'; -import { AztecKVStore, AztecMap } from '@aztec/kv-store'; - -import { BlockStore } from './block_store.js'; - -/** - * LMDB implementation of the ArchiverDataStore interface. - */ -export class ContractStore { - #blockStore: BlockStore; - #extendedContractData: AztecMap; - #log = createDebugLogger('aztec:archiver:contract_store'); - - constructor(private db: AztecKVStore, blockStore: BlockStore) { - this.#extendedContractData = db.openMap('archiver_extended_contract_data'); - this.#blockStore = blockStore; - } - - /** - * Add new extended contract data from an L2 block to the store's list. - * @param data - List of contracts' data to be added. - * @param blockNum - Number of the L2 block the contract data was deployed in. - * @returns True if the operation is successful. - */ - addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise { - return this.#extendedContractData.swap(blockNum, (existingData = []) => { - existingData.push(...data.map(d => d.toBuffer())); - return existingData; - }); - } - - /** - * Get the extended contract data for this contract. - * @param contractAddress - The contract data address. - * @returns The extended contract data or undefined if not found. - */ - getExtendedContractData(contractAddress: AztecAddress): ExtendedContractData | undefined { - const [blockNumber, _] = this.#blockStore.getContractLocation(contractAddress) ?? []; - - if (typeof blockNumber !== 'number') { - return undefined; - } - - for (const contract of this.#extendedContractData.get(blockNumber) ?? []) { - const extendedContractData = ExtendedContractData.fromBuffer(contract); - if (extendedContractData.contractData.contractAddress.equals(contractAddress)) { - return extendedContractData; - } - } - - return undefined; - } -} 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 50a5e8c207b..94e4217ba69 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 @@ -1,6 +1,5 @@ import { Body, - ExtendedContractData, GetUnencryptedLogsResponse, L1ToL2Message, L2Block, @@ -23,7 +22,6 @@ import { BlockBodyStore } from './block_body_store.js'; import { BlockStore } from './block_store.js'; import { ContractClassStore } from './contract_class_store.js'; import { ContractInstanceStore } from './contract_instance_store.js'; -import { ContractStore } from './contract_store.js'; import { LogStore } from './log_store.js'; import { MessageStore } from './message_store.js'; @@ -34,7 +32,6 @@ export class KVArchiverDataStore implements ArchiverDataStore { #blockStore: BlockStore; #blockBodyStore: BlockBodyStore; #logStore: LogStore; - #contractStore: ContractStore; #messageStore: MessageStore; #contractClassStore: ContractClassStore; #contractInstanceStore: ContractInstanceStore; @@ -45,7 +42,6 @@ export class KVArchiverDataStore implements ArchiverDataStore { this.#blockBodyStore = new BlockBodyStore(db); this.#blockStore = new BlockStore(db, this.#blockBodyStore); this.#logStore = new LogStore(db, this.#blockStore, logsMaxPageSize); - this.#contractStore = new ContractStore(db, this.#blockStore); this.#messageStore = new MessageStore(db); this.#contractClassStore = new ContractClassStore(db); this.#contractInstanceStore = new ContractInstanceStore(db); @@ -252,25 +248,6 @@ export class KVArchiverDataStore implements ArchiverDataStore { } } - /** - * Add new extended contract data from an L2 block to the store's list. - * @param data - List of contracts' data to be added. - * @param blockNum - Number of the L2 block the contract data was deployed in. - * @returns True if the operation is successful. - */ - addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise { - return this.#contractStore.addExtendedContractData(data, blockNum); - } - - /** - * Get the extended contract data for this contract. - * @param contractAddress - The contract data address. - * @returns The extended contract data or undefined if not found. - */ - getExtendedContractData(contractAddress: AztecAddress): Promise { - return Promise.resolve(this.#contractStore.getExtendedContractData(contractAddress)); - } - /** * Gets the number of the latest L2 block processed. * @returns The number of the latest L2 block processed. 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 d6c4387fda5..1c9a1d4d10c 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 @@ -1,6 +1,5 @@ import { Body, - ExtendedContractData, ExtendedUnencryptedL2Log, GetUnencryptedLogsResponse, L1ToL2Message, @@ -55,16 +54,6 @@ export class MemoryArchiverStore implements ArchiverDataStore { */ private unencryptedLogsPerBlock: L2BlockL2Logs[] = []; - /** - * A sparse array containing all the extended contract data that have been fetched so far. - */ - private extendedContractDataByBlock: (ExtendedContractData[] | undefined)[] = []; - - /** - * A mapping of contract address to extended contract data. - */ - private extendedContractData: Map = new Map(); - // TODO(#4492): Nuke the other message stores private newL1ToL2Messages = new NewL1ToL2MessageStore(); @@ -249,28 +238,6 @@ export class MemoryArchiverStore implements ArchiverDataStore { return Promise.resolve(true); } - /** - * Store new extended contract data from an L2 block to the store's list. - * @param data - List of contracts' data to be added. - * @param blockNum - Number of the L2 block the contract data was deployed in. - * @returns True if the operation is successful (always in this implementation). - */ - public addExtendedContractData(data: ExtendedContractData[], blockNum: number): Promise { - // Add to the contracts mapping - for (const contractData of data) { - const key = contractData.contractData.contractAddress.toString(); - this.extendedContractData.set(key, contractData); - } - - // Add the index per block - if (this.extendedContractDataByBlock[blockNum]?.length) { - this.extendedContractDataByBlock[blockNum]?.push(...data); - } else { - this.extendedContractDataByBlock[blockNum] = [...data]; - } - return Promise.resolve(true); - } - /** * Gets up to `limit` amount of L2 blocks starting from `from`. * @param from - Number of the first block to return (inclusive). @@ -456,17 +423,6 @@ export class MemoryArchiverStore implements ArchiverDataStore { }); } - /** - * Get the extended contract data for this contract. - * TODO(palla/purge-old-contract-deploy): Delete me? - * @param contractAddress - The contract data address. - * @returns The extended contract data or undefined if not found. - */ - getExtendedContractData(contractAddress: AztecAddress): Promise { - const result = this.extendedContractData.get(contractAddress.toString()); - return Promise.resolve(result); - } - /** * Gets the number of the latest L2 block processed. * @returns The number of the latest L2 block processed. diff --git a/yarn-project/archiver/src/rpc/archiver_client.ts b/yarn-project/archiver/src/rpc/archiver_client.ts index cec9f21801f..4a26eaba7f8 100644 --- a/yarn-project/archiver/src/rpc/archiver_client.ts +++ b/yarn-project/archiver/src/rpc/archiver_client.ts @@ -1,7 +1,5 @@ import { ContractData, - EncodedContractFunction, - ExtendedContractData, ExtendedUnencryptedL2Log, L1ToL2Message, L2Block, @@ -19,9 +17,7 @@ export const createArchiverClient = (url: string, fetch = makeFetch([1, 2, 3], t url, { ContractData, - EncodedContractFunction, EthAddress, - ExtendedContractData, ExtendedUnencryptedL2Log, Fr, L1ToL2Message, diff --git a/yarn-project/archiver/src/rpc/archiver_server.ts b/yarn-project/archiver/src/rpc/archiver_server.ts index 600a4316503..0407410f3c6 100644 --- a/yarn-project/archiver/src/rpc/archiver_server.ts +++ b/yarn-project/archiver/src/rpc/archiver_server.ts @@ -1,7 +1,5 @@ import { ContractData, - EncodedContractFunction, - ExtendedContractData, ExtendedUnencryptedL2Log, L1ToL2Message, L2Block, @@ -25,9 +23,7 @@ export function createArchiverRpcServer(archiverService: Archiver): JsonRpcServe archiverService, { ContractData, - EncodedContractFunction, EthAddress, - ExtendedContractData, ExtendedUnencryptedL2Log, Fr, L1ToL2Message, diff --git a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts index 845d61b2916..00817cb95d1 100644 --- a/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts +++ b/yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts @@ -1,7 +1,6 @@ import { AztecNode, ContractData, - ExtendedContractData, ExtendedUnencryptedL2Log, L1ToL2MessageAndIndex, L2Block, @@ -31,7 +30,6 @@ export function createAztecNodeRpcServer(node: AztecNode) { { AztecAddress, EthAddress, - ExtendedContractData, ExtendedUnencryptedL2Log, ContractData, Fr, diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 956bc5582bf..38c36dbe382 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -3,7 +3,6 @@ import { AztecNode, ContractData, ContractDataSource, - ExtendedContractData, GetUnencryptedLogsResponse, L1ToL2MessageAndIndex, L1ToL2MessageSource, @@ -232,15 +231,6 @@ export class AztecNodeService implements AztecNode { return Promise.resolve(this.chainId); } - /** - * Get the extended contract data for this contract. - * @param contractAddress - The contract data address. - * @returns The extended contract data or undefined if not found. - */ - async getExtendedContractData(contractAddress: AztecAddress): Promise { - return await this.contractDataSource.getExtendedContractData(contractAddress); - } - /** * Lookup the contract data for this contract. * Contains the ethereum portal address . diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index 6639de3401e..f3deb9c6666 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -1,4 +1,4 @@ -import { ExtendedContractData, Tx, TxExecutionRequest, TxHash, TxReceipt } from '@aztec/circuit-types'; +import { Tx, TxExecutionRequest, TxHash, TxReceipt } from '@aztec/circuit-types'; import { AztecAddress, CompleteAddress, EthAddress } from '@aztec/circuits.js'; import { L1ContractAddresses } from '@aztec/ethereum'; import { ABIParameterVisibility, ContractArtifact, FunctionType } from '@aztec/foundation/abi'; @@ -12,7 +12,6 @@ import { Contract } from './contract.js'; describe('Contract Class', () => { let wallet: MockProxy; - let resolvedExtendedContractData: ExtendedContractData; let contractAddress: AztecAddress; let account: CompleteAddress; let contractInstance: ContractInstanceWithAddress; @@ -104,14 +103,12 @@ describe('Contract Class', () => { }; beforeEach(() => { - resolvedExtendedContractData = ExtendedContractData.random(); - contractAddress = resolvedExtendedContractData.contractData.contractAddress; + contractAddress = AztecAddress.random(); account = CompleteAddress.random(); contractInstance = { address: contractAddress } as ContractInstanceWithAddress; wallet = mock(); wallet.createTxExecutionRequest.mockResolvedValue(mockTxRequest); - wallet.getExtendedContractData.mockResolvedValue(resolvedExtendedContractData); wallet.getContractInstance.mockResolvedValue(contractInstance); wallet.sendTx.mockResolvedValue(mockTxHash); wallet.viewTx.mockResolvedValue(mockViewResultValue); diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index e42fa6f174e..872f764e925 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -85,7 +85,6 @@ export { CompleteAddress, ContractData, DeployedContract, - ExtendedContractData, ExtendedNote, FunctionCall, GrumpkinPrivateKey, diff --git a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts index 60396d9c803..2c49ba73370 100644 --- a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts +++ b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts @@ -1,7 +1,6 @@ import { AuthWitness, ContractData, - ExtendedContractData, ExtendedNote, ExtendedUnencryptedL2Log, L2Block, @@ -43,7 +42,6 @@ export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false) ContractData, FunctionSelector, EthAddress, - ExtendedContractData, ExtendedNote, ExtendedUnencryptedL2Log, Fr, diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 3f29c2adca0..6be38de7e6c 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -2,7 +2,6 @@ import { AuthWitness, ContractData, DeployedContract, - ExtendedContractData, ExtendedNote, FunctionCall, GetUnencryptedLogsResponse, @@ -103,9 +102,6 @@ export abstract class BaseWallet implements Wallet { viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress | undefined): Promise { return this.pxe.viewTx(functionName, args, to, from); } - getExtendedContractData(contractAddress: AztecAddress): Promise { - return this.pxe.getExtendedContractData(contractAddress); - } getContractData(contractAddress: AztecAddress): Promise { return this.pxe.getContractData(contractAddress); } @@ -133,4 +129,7 @@ export abstract class BaseWallet implements Wallet { isContractClassPubliclyRegistered(id: Fr): Promise { return this.pxe.isContractClassPubliclyRegistered(id); } + isContractPubliclyDeployed(address: AztecAddress): Promise { + return this.pxe.isContractPubliclyDeployed(address); + } } diff --git a/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts b/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts index 9771db9a032..c20bae84f83 100644 --- a/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts +++ b/yarn-project/circuit-types/src/aztec_node/rpc/aztec_node_client.ts @@ -5,7 +5,7 @@ import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { createJsonRpcClient, defaultFetch } from '@aztec/foundation/json-rpc/client'; -import { ContractData, ExtendedContractData } from '../../contract_data.js'; +import { ContractData } from '../../contract_data.js'; import { AztecNode } from '../../interfaces/aztec-node.js'; import { NullifierMembershipWitness } from '../../interfaces/nullifier_tree.js'; import { L1ToL2MessageAndIndex } from '../../l1_to_l2_message.js'; @@ -27,7 +27,6 @@ export function createAztecNodeClient(url: string, fetch = defaultFetch): AztecN { AztecAddress, EthAddress, - ExtendedContractData, ExtendedUnencryptedL2Log, ContractData, Fr, diff --git a/yarn-project/circuit-types/src/contract_dao.ts b/yarn-project/circuit-types/src/contract_dao.ts index bd7dfe8736b..b24b45e5515 100644 --- a/yarn-project/circuit-types/src/contract_dao.ts +++ b/yarn-project/circuit-types/src/contract_dao.ts @@ -5,14 +5,11 @@ import { EventAbi, FunctionDebugMetadata, FunctionSelector, - FunctionType, getFunctionDebugMetadata, } from '@aztec/foundation/abi'; import { BufferReader, prefixBufferWithLength } from '@aztec/foundation/serialize'; import { ContractInstanceWithAddress, SerializableContractInstance } from '@aztec/types/contracts'; -import { EncodedContractFunction } from './contract_data.js'; - /** * A contract Data Access Object (DAO). * Contains the contract's address, portal contract address, and an array of ContractFunctionDao objects. @@ -79,21 +76,3 @@ export class ContractDao implements ContractArtifact { return new ContractDao(contractArtifact, instance); } } - -/** - * Return public functions from the newly deployed contract to be injected into the tx object. - * @param newContract - The new contract - * @returns List of EncodedContractFunction. - */ -export function getNewContractPublicFunctions(newContract: ContractDao) { - return newContract.functions - .filter(c => c.functionType === FunctionType.OPEN) - .map( - fn => - new EncodedContractFunction( - FunctionSelector.fromNameAndParameters(fn.name, fn.parameters), - fn.isInternal ?? false, - Buffer.from(fn.bytecode, 'base64'), - ), - ); -} diff --git a/yarn-project/circuit-types/src/contract_data.test.ts b/yarn-project/circuit-types/src/contract_data.test.ts index de586d54fe0..38d01bf7f8e 100644 --- a/yarn-project/circuit-types/src/contract_data.test.ts +++ b/yarn-project/circuit-types/src/contract_data.test.ts @@ -1,27 +1,12 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; import { EthAddress } from '@aztec/foundation/eth-address'; -import { ContractData, ExtendedContractData } from './contract_data.js'; +import { ContractData } from './contract_data.js'; describe('ContractData', () => { const aztecAddress = AztecAddress.random(); const portalAddress = EthAddress.random(); - it('serializes / deserializes correctly', () => { - const extendedContractData = ExtendedContractData.random(); - const buf = extendedContractData.toBuffer(); - const serContractData = ExtendedContractData.fromBuffer(buf); - expect(extendedContractData.contractData.contractAddress.equals(serContractData.contractData.contractAddress)).toBe( - true, - ); - expect( - extendedContractData.contractData.portalContractAddress.equals( - serContractData.contractData.portalContractAddress, - ), - ).toBe(true); - expect(extendedContractData.bytecode?.equals(serContractData?.bytecode || Buffer.alloc(0))).toBe(true); - }); - it('serializes / deserializes correctly without bytecode', () => { const contractData = new ContractData(aztecAddress, portalAddress); const buf = contractData.toBuffer(); diff --git a/yarn-project/circuit-types/src/contract_data.ts b/yarn-project/circuit-types/src/contract_data.ts index fe1db7c04ae..67f170bd352 100644 --- a/yarn-project/circuit-types/src/contract_data.ts +++ b/yarn-project/circuit-types/src/contract_data.ts @@ -1,26 +1,13 @@ -import { FUNCTION_SELECTOR_NUM_BYTES, Fr, FunctionSelector, computeSaltedInitializationHash } from '@aztec/circuits.js'; +import { Fr, FunctionSelector } from '@aztec/circuits.js'; import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { randomBytes } from '@aztec/foundation/crypto'; import { EthAddress } from '@aztec/foundation/eth-address'; -import { - BufferReader, - numToInt32BE, - serializeArrayOfBufferableToVector, - serializeToBuffer, -} from '@aztec/foundation/serialize'; -import { ContractClass, ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts'; +import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; +import { ContractClassPublic, ContractInstanceWithAddress, PublicFunction } from '@aztec/types/contracts'; /** * Used for retrieval of contract data (A3 address, portal contract address, bytecode). */ export interface ContractDataSource { - /** - * Get the extended contract data for this contract. - * @param contractAddress - The contract data address. - * @returns The extended contract data or undefined if not found. - */ - getExtendedContractData(contractAddress: AztecAddress): Promise; - /** * Lookup the L2 contract base info for this contract. * NOTE: This works for all Aztec contracts and will only return contractAddress / portalAddress. @@ -35,7 +22,7 @@ export interface ContractDataSource { * @param selector - The function's selector. * @returns The function's data. */ - getPublicFunction(address: AztecAddress, selector: FunctionSelector): Promise; + getPublicFunction(address: AztecAddress, selector: FunctionSelector): Promise; /** * Gets the number of the latest L2 block processed by the implementation. @@ -59,202 +46,6 @@ export interface ContractDataSource { getContractClassIds(): Promise; } -/** - * Represents encoded contract function. - */ -export class EncodedContractFunction { - constructor( - /** - * The function selector. - */ - public selector: FunctionSelector, - /** - * Whether the function is internal. - */ - public isInternal: boolean, - /** - * The function bytecode. - */ - public bytecode: Buffer, - ) {} - - /** - * Serializes this instance into a buffer. - * @returns Encoded buffer. - */ - toBuffer(): Buffer { - const bytecodeBuf = Buffer.concat([numToInt32BE(this.bytecode.length), this.bytecode]); - return serializeToBuffer(this.selector, this.isInternal, bytecodeBuf); - } - - /** - * Deserializes a contract function object from an encoded buffer. - * @param buffer - The encoded buffer. - * @returns The deserialized contract function. - */ - static fromBuffer(buffer: Buffer | BufferReader): EncodedContractFunction { - const reader = BufferReader.asReader(buffer); - const fnSelector = FunctionSelector.fromBuffer(reader.readBytes(FUNCTION_SELECTOR_NUM_BYTES)); - const isInternal = reader.readBoolean(); - return new EncodedContractFunction(fnSelector, isInternal, reader.readBuffer()); - } - - /** - * Serializes this instance into a string. - * @returns Encoded string. - */ - toString(): string { - return this.toBuffer().toString('hex'); - } - - /** - * Deserializes a contract function object from an encoded string. - * @param data - The encoded string. - * @returns The deserialized contract function. - */ - static fromString(data: string): EncodedContractFunction { - return EncodedContractFunction.fromBuffer(Buffer.from(data, 'hex')); - } - - /** - * Creates a random contract function. - * @returns A random contract function. - */ - static random(): EncodedContractFunction { - return new EncodedContractFunction(FunctionSelector.fromBuffer(randomBytes(4)), false, randomBytes(64)); - } -} - -/** - * A contract data blob, containing L1 and L2 addresses, public functions' bytecode, partial address and public key. - * TODO(palla/purge-old-contract-deploy): Delete this class? - */ -export class ExtendedContractData { - /** The contract's encoded ACIR code. This should become Brillig code once implemented. */ - public bytecode: Buffer; - - constructor( - /** The base contract data: aztec & portal addresses. */ - public contractData: ContractData, - /** Artifacts of public functions. */ - public readonly publicFunctions: EncodedContractFunction[], - /** Contract class id */ - public readonly contractClassId: Fr, - /** Salted init hash. */ - public readonly saltedInitializationHash: Fr, - /** Public key hash of the contract. */ - public readonly publicKeyHash: Fr, - ) { - this.bytecode = serializeArrayOfBufferableToVector(publicFunctions.map(fn => fn.toBuffer())); - } - - /** - * Gets the public function data or undefined. - * @param selector - The function selector of the function to fetch. - * @returns The public function data (if found). - */ - public getPublicFunction(selector: FunctionSelector): EncodedContractFunction | undefined { - return this.publicFunctions.find(fn => fn.selector.equals(selector)); - } - - /** - * Serializes this instance into a buffer, using 20 bytes for the eth address. - * @returns Encoded buffer. - */ - public toBuffer(): Buffer { - const contractDataBuf = this.contractData.toBuffer(); - return serializeToBuffer( - contractDataBuf, - this.bytecode, - this.contractClassId, - this.saltedInitializationHash, - this.publicKeyHash, - ); - } - - /** - * Serializes this instance into a string. - * @returns Encoded string. - */ - public toString(): string { - return this.toBuffer().toString('hex'); - } - - /** True if this represents an empty instance. */ - public isEmpty(): boolean { - return ExtendedContractData.isEmpty(this); - } - - /** True if the passed instance is empty . */ - public static isEmpty(obj: ExtendedContractData): boolean { - return ( - obj.contractData.isEmpty() && - obj.publicFunctions.length === 0 && - obj.contractClassId.isZero() && - obj.publicKeyHash.isZero() && - obj.saltedInitializationHash.isZero() - ); - } - - /** - * Deserializes a contract data object from an encoded buffer, using 20 bytes for the eth address. - * @param buffer - Byte array resulting from calling toBuffer. - * @returns Deserialized instance. - */ - static fromBuffer(buffer: Buffer | BufferReader) { - const reader = BufferReader.asReader(buffer); - const contractData = reader.readObject(ContractData); - const publicFns = reader.readVector(EncodedContractFunction); - const contractClassId = reader.readObject(Fr); - const saltedInitializationHash = reader.readObject(Fr); - const publicKeyHash = reader.readObject(Fr); - return new ExtendedContractData(contractData, publicFns, contractClassId, saltedInitializationHash, publicKeyHash); - } - - /** - * Deserializes a contract data object from an encoded string, using 20 bytes for the eth address. - * @param str - String resulting from calling toString. - * @returns Deserialized instance. - */ - static fromString(str: string) { - return ExtendedContractData.fromBuffer(Buffer.from(str, 'hex')); - } - - /** - * Generate ContractData with random addresses. - * @param contractData - Optional contract data to use. - * @returns A random ExtendedContractData object. - */ - static random(contractData?: ContractData): ExtendedContractData { - return new ExtendedContractData( - contractData ?? ContractData.random(), - [EncodedContractFunction.random(), EncodedContractFunction.random()], - Fr.random(), - Fr.random(), - Fr.random(), - ); - } - - /** Generates empty extended contract data. */ - static empty(): ExtendedContractData { - return new ExtendedContractData(ContractData.empty(), [], Fr.ZERO, Fr.ZERO, Fr.ZERO); - } - - /** Temporary method for creating extended contract data out of classes and instances */ - static fromClassAndInstance( - contractClass: Pick, - instance: ContractInstanceWithAddress, - ) { - return new ExtendedContractData( - new ContractData(instance.address, instance.portalContractAddress), - contractClass.publicFunctions.map(f => new EncodedContractFunction(f.selector, f.isInternal, f.bytecode)), - instance.contractClassId, - computeSaltedInitializationHash(instance), - instance.publicKeysHash, - ); - } -} - /** * A contract data blob, containing L1 and L2 addresses. * TODO(palla/purge-old-contract-deploy): Delete me diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.ts index 0aee895dee8..3927c75f385 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.ts @@ -11,7 +11,7 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts'; -import { ContractData, ExtendedContractData } from '../contract_data.js'; +import { ContractData } from '../contract_data.js'; import { L1ToL2MessageAndIndex } from '../l1_to_l2_message.js'; import { L2Block } from '../l2_block.js'; import { GetUnencryptedLogsResponse, L2BlockL2Logs, LogFilter, LogType } from '../logs/index.js'; @@ -194,13 +194,6 @@ export interface AztecNode { */ getL1ContractAddresses(): Promise; - /** - * Get the extended contract data for this contract. - * @param contractAddress - The contract data address. - * @returns The extended contract data or undefined if not found. - */ - getExtendedContractData(contractAddress: AztecAddress): Promise; - /** * Lookup the contract data for this contract. * Contains the ethereum portal address . diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index 46915f8ce2e..456899bd95f 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -3,7 +3,7 @@ import { ContractClassWithId, ContractInstanceWithAddress } from '@aztec/types/c import { NodeInfo } from '@aztec/types/interfaces'; import { AuthWitness } from '../auth_witness.js'; -import { ContractData, ExtendedContractData } from '../contract_data.js'; +import { ContractData } from '../contract_data.js'; import { L2Block } from '../l2_block.js'; import { GetUnencryptedLogsResponse, LogFilter } from '../logs/index.js'; import { ExtendedNote } from '../notes/index.js'; @@ -209,15 +209,6 @@ export interface PXE { */ viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress): Promise; - /** - * Gets the extended contract data for this contract. Extended contract data includes the address, - * portal contract address on L1, public functions, partial address, and encryption public key. - * - * @param contractAddress - The contract's address. - * @returns The extended contract data if found. - */ - getExtendedContractData(contractAddress: AztecAddress): Promise; - /** * Gets the portal contract address on L1 for the given contract. * @@ -297,5 +288,12 @@ export interface PXE { * @param id - Identifier of the class. */ isContractClassPubliclyRegistered(id: Fr): Promise; + + /** + * Queries the node to check whether the contract instance with the given address has been publicly deployed, + * regardless of whether this PXE knows about the contract or not. + * TODO(@spalladino): Same notes as above. + */ + isContractPubliclyDeployed(address: AztecAddress): Promise; } // docs:end:pxe-interface diff --git a/yarn-project/cli/src/cmds/get_contract_data.ts b/yarn-project/cli/src/cmds/get_contract_data.ts index 80f1e7afb2a..a102e0ba2a9 100644 --- a/yarn-project/cli/src/cmds/get_contract_data.ts +++ b/yarn-project/cli/src/cmds/get_contract_data.ts @@ -1,5 +1,4 @@ import { AztecAddress } from '@aztec/aztec.js'; -import { ContractData } from '@aztec/circuit-types'; import { DebugLogger, LogFn } from '@aztec/foundation/log'; import { createCompatibleClient } from '../client.js'; @@ -12,25 +11,22 @@ export async function getContractData( log: LogFn, ) { const client = await createCompatibleClient(rpcUrl, debugLogger); - const contractDataWithOrWithoutBytecode = includeBytecode - ? await client.getExtendedContractData(contractAddress) - : await client.getContractData(contractAddress); + const instance = await client.getContractInstance(contractAddress); + const contractClass = includeBytecode && instance && (await client.getContractClass(instance?.contractClassId)); - if (!contractDataWithOrWithoutBytecode) { - log(`No contract data found at ${contractAddress}`); + if (!instance) { + log(`No contract found at ${contractAddress}`); return; } - let contractData: ContractData; - if ('contractData' in contractDataWithOrWithoutBytecode) { - contractData = contractDataWithOrWithoutBytecode.contractData; - } else { - contractData = contractDataWithOrWithoutBytecode; - } - log(`\nContract Data: \nAddress: ${contractData.contractAddress.toString()}`); - log(`Portal: ${contractData.portalContractAddress.toString()}`); - if ('bytecode' in contractDataWithOrWithoutBytecode) { - log(`Bytecode: ${contractDataWithOrWithoutBytecode.bytecode}`); + log(`\nContract Data:`); + Object.entries(instance).forEach(([key, value]) => { + const capitalized = key.charAt(0).toUpperCase() + key.slice(1); + log(`${capitalized}: ${value.toString()}`); + }); + + if (contractClass) { + log(`Bytecode: 0x${contractClass.packedBytecode.toString('hex')}`); } log('\n'); } diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts index c3e6a6678df..87524d30443 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts @@ -115,10 +115,9 @@ describe('e2e_deploy_contract', () => { const receipt = await deployer.deploy().send({ portalContract }).wait(); const address = receipt.contract.address; - expect((await pxe.getContractData(address))?.portalContractAddress.toString()).toEqual(portalContract.toString()); - expect((await pxe.getExtendedContractData(address))?.contractData.portalContractAddress.toString()).toEqual( - portalContract.toString(), - ); + const expectedPortal = portalContract.toString(); + expect((await pxe.getContractData(address))?.portalContractAddress.toString()).toEqual(expectedPortal); + expect((await pxe.getContractInstance(address))?.portalContractAddress.toString()).toEqual(expectedPortal); }, 60_000); it('should not deploy a contract which failed the public part of the execution', async () => { @@ -142,13 +141,12 @@ describe('e2e_deploy_contract', () => { const [goodTxReceipt, badTxReceipt] = await Promise.all([goodTx.getReceipt(), badTx.getReceipt()]); + // Both the good and bad transactions are included expect(goodTxReceipt.blockNumber).toEqual(expect.any(Number)); - // the bad transaction is included expect(badTxReceipt.blockNumber).toEqual(expect.any(Number)); - await expect(pxe.getContractData(badDeploy.getInstance().address)).resolves.toBeUndefined(); - // but did not deploy - await expect(pxe.getExtendedContractData(badDeploy.getInstance().address)).resolves.toBeUndefined(); + // But the bad tx did not deploy + await expect(pxe.isContractClassPubliclyRegistered(badDeploy.getInstance().address)).resolves.toBeFalsy(); } finally { sequencer?.updateSequencerConfig({ minTxsPerBlock: 1 }); } diff --git a/yarn-project/end-to-end/src/shared/cli.ts b/yarn-project/end-to-end/src/shared/cli.ts index 234c3e21e96..48db6369067 100644 --- a/yarn-project/end-to-end/src/shared/cli.ts +++ b/yarn-project/end-to-end/src/shared/cli.ts @@ -174,7 +174,7 @@ export const cliTestSuite = ( // clear logs clearLogs(); await run(`get-contract-data ${loggedAddress}`); - const contractDataAddress = findInLogs(/Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + const contractDataAddress = findInLogs(/^\s?Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; expect(contractDataAddress).toEqual(deployedContract?.contractAddress.toString()); debug("Check owner's balance"); diff --git a/yarn-project/pxe/src/pxe_http/pxe_http_server.ts b/yarn-project/pxe/src/pxe_http/pxe_http_server.ts index 8aa21824401..094d1813c1d 100644 --- a/yarn-project/pxe/src/pxe_http/pxe_http_server.ts +++ b/yarn-project/pxe/src/pxe_http/pxe_http_server.ts @@ -2,7 +2,6 @@ import { AuthWitness, CompleteAddress, ContractData, - ExtendedContractData, ExtendedNote, ExtendedUnencryptedL2Log, L2Block, @@ -37,7 +36,6 @@ export function createPXERpcServer(pxeService: PXE): JsonRpcServer { AztecAddress, TxExecutionRequest, ContractData, - ExtendedContractData, ExtendedUnencryptedL2Log, FunctionSelector, TxHash, diff --git a/yarn-project/pxe/src/pxe_service/pxe_service.ts b/yarn-project/pxe/src/pxe_service/pxe_service.ts index fd65873b1b6..f9bdb5c9bf2 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -4,7 +4,6 @@ import { ContractDao, ContractData, DeployedContract, - ExtendedContractData, ExtendedNote, FunctionCall, GetUnencryptedLogsResponse, @@ -440,10 +439,6 @@ export class PXEService implements PXE { return await this.node.getBlockNumber(); } - public async getExtendedContractData(contractAddress: AztecAddress): Promise { - return await this.node.getExtendedContractData(contractAddress); - } - public async getContractData(contractAddress: AztecAddress): Promise { return await this.node.getContractData(contractAddress); } @@ -746,4 +741,8 @@ export class PXEService implements PXE { public async isContractClassPubliclyRegistered(id: Fr): Promise { return !!(await this.node.getContractClass(id)); } + + public async isContractPubliclyDeployed(address: AztecAddress): Promise { + return !!(await this.node.getContract(address)); + } } diff --git a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts index 0c75a143be9..2b6cb8c9665 100644 --- a/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts +++ b/yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts @@ -119,7 +119,7 @@ export const pxeTestSuite = (testName: string, pxeSetup: () => Promise) => ); }); - // Note: Not testing `getExtendedContractData`, `getContractData` and `getUnencryptedLogs` here as these + // Note: Not testing `getContractData` and `getUnencryptedLogs` here as these // functions only call AztecNode and these methods are frequently used by the e2e tests. it('successfully gets a block number', async () => { diff --git a/yarn-project/sequencer-client/src/simulator/public_executor.ts b/yarn-project/sequencer-client/src/simulator/public_executor.ts index c8fba7173c2..d915a74b158 100644 --- a/yarn-project/sequencer-client/src/simulator/public_executor.ts +++ b/yarn-project/sequencer-client/src/simulator/public_executor.ts @@ -1,6 +1,5 @@ import { ContractDataSource, - ExtendedContractData, L1ToL2MessageSource, MerkleTreeId, NullifierMembershipWitness, @@ -31,7 +30,6 @@ import { MerkleTreeOperations } from '@aztec/world-state'; * Progressively records contracts in transaction as they are processed in a block. */ export class ContractsDataSourcePublicDB implements PublicContractsDB { - private cache = new Map(); private instanceCache = new Map(); private classCache = new Map(); @@ -80,41 +78,25 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB { return this.instanceCache.get(address.toString()) ?? (await this.db.getContract(address)); } - async getBytecode(address: AztecAddress, selector: FunctionSelector): Promise { - const contract = await this.#getContract(address); - return contract?.getPublicFunction(selector)?.bytecode; - } - - async getPortalContractAddress(address: AztecAddress): Promise { - const contract = await this.#getContract(address); - return contract?.contractData.portalContractAddress; - } - - async #getContract(address: AztecAddress): Promise { - return ( - this.cache.get(address.toString()) ?? - (await this.#makeExtendedContractDataFor(address)) ?? - (await this.db.getExtendedContractData(address)) - ); + public async getContractClass(contractClassId: Fr): Promise { + return this.classCache.get(contractClassId.toString()) ?? (await this.db.getContractClass(contractClassId)); } - async #makeExtendedContractDataFor(address: AztecAddress): Promise { - const instance = this.instanceCache.get(address.toString()); + async getBytecode(address: AztecAddress, selector: FunctionSelector): Promise { + const instance = await this.getContractInstance(address); if (!instance) { - return undefined; + throw new Error(`Contract ${address.toString()} not found`); } - - const contractClass = - this.classCache.get(instance.contractClassId.toString()) ?? - (await this.db.getContractClass(instance.contractClassId)); + const contractClass = await this.getContractClass(instance.contractClassId); if (!contractClass) { - this.log.warn( - `Contract class ${instance.contractClassId.toString()} for address ${address.toString()} not found`, - ); - return undefined; + throw new Error(`Contract class ${instance.contractClassId.toString()} for ${address.toString()} not found`); } + return contractClass.publicFunctions.find(f => f.selector.equals(selector))?.bytecode; + } - return ExtendedContractData.fromClassAndInstance(contractClass, instance); + async getPortalContractAddress(address: AztecAddress): Promise { + const contract = await this.getContractInstance(address); + return contract?.portalContractAddress; } } diff --git a/yellow-paper/docs/transactions/tx-object.md b/yellow-paper/docs/transactions/tx-object.md index c269239cad0..399005262f1 100644 --- a/yellow-paper/docs/transactions/tx-object.md +++ b/yellow-paper/docs/transactions/tx-object.md @@ -30,7 +30,6 @@ The fields of a transaction object are the following: | encryptedLogs | Buffer[][] | Encrypted logs emitted per function in this transaction. Position `i` contains the encrypted logs emitted by the `i`-th function execution. | | unencryptedLogs | Buffer[][] | Equivalent to the above but for unencrypted logs. | | enqueuedPublicFunctionCalls | PublicCallRequest[] | List of public function calls to run during public execution. | -| newContracts | ExtendedContractData[] | List of new contracts to be deployed as part of this transaction. | ### Private kernel public inputs final