diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 8c7f0e3a476d..a1e4b4d017f4 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -1,6 +1,4 @@ import { - ContractData, - ContractDataSource, GetUnencryptedLogsResponse, L1ToL2Message, L1ToL2MessageSource, @@ -25,7 +23,12 @@ 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, PublicFunction } from '@aztec/types/contracts'; +import { + ContractClassPublic, + ContractDataSource, + ContractInstanceWithAddress, + PublicFunction, +} from '@aztec/types/contracts'; import { Chain, HttpTransport, PublicClient, createPublicClient, getAddress, getContract, http } from 'viem'; @@ -423,29 +426,6 @@ export class Archiver implements ArchiveSource { return this.store.getSettledTxReceipt(txHash); } - /** - * Lookup the contract data for this contract. - * Contains contract address & the ethereum portal address. - * @param contractAddress - The contract data address. - * @returns ContractData with the portal address (if we didn't throw an error). - */ - public getContractData(contractAddress: AztecAddress): Promise { - return this.makeContractDataFor(contractAddress); - } - - /** - * Temporary method for creating a fake contract data out of classes and instances registered in the node. - * Used as a fallback if the extended contract data is not found. - */ - private async makeContractDataFor(address: AztecAddress): Promise { - const instance = await this.store.getContractInstance(address); - if (!instance) { - return undefined; - } - - return new ContractData(address, instance.portalContractAddress); - } - /** * Gets the public function data for a contract. * @param address - The contract address containing the function to fetch. diff --git a/yarn-project/archiver/src/rpc/archiver_client.ts b/yarn-project/archiver/src/rpc/archiver_client.ts index 4a26eaba7f83..0fc7edba5cf2 100644 --- a/yarn-project/archiver/src/rpc/archiver_client.ts +++ b/yarn-project/archiver/src/rpc/archiver_client.ts @@ -1,5 +1,4 @@ import { - ContractData, ExtendedUnencryptedL2Log, L1ToL2Message, L2Block, @@ -16,7 +15,6 @@ export const createArchiverClient = (url: string, fetch = makeFetch([1, 2, 3], t createJsonRpcClient( url, { - ContractData, EthAddress, ExtendedUnencryptedL2Log, Fr, diff --git a/yarn-project/archiver/src/rpc/archiver_server.ts b/yarn-project/archiver/src/rpc/archiver_server.ts index 0407410f3c69..672da4d2f6a7 100644 --- a/yarn-project/archiver/src/rpc/archiver_server.ts +++ b/yarn-project/archiver/src/rpc/archiver_server.ts @@ -1,5 +1,4 @@ import { - ContractData, ExtendedUnencryptedL2Log, L1ToL2Message, L2Block, @@ -22,7 +21,6 @@ export function createArchiverRpcServer(archiverService: Archiver): JsonRpcServe return new JsonRpcServer( archiverService, { - ContractData, EthAddress, ExtendedUnencryptedL2Log, Fr, 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 00817cb95d16..9c3c698b77dc 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,6 +1,5 @@ import { AztecNode, - ContractData, ExtendedUnencryptedL2Log, L1ToL2MessageAndIndex, L2Block, @@ -31,7 +30,6 @@ export function createAztecNodeRpcServer(node: AztecNode) { AztecAddress, EthAddress, ExtendedUnencryptedL2Log, - ContractData, Fr, FunctionSelector, Header, diff --git a/yarn-project/aztec-node/src/aztec-node/server.ts b/yarn-project/aztec-node/src/aztec-node/server.ts index 38c36dbe3821..2a5f1823d5ba 100644 --- a/yarn-project/aztec-node/src/aztec-node/server.ts +++ b/yarn-project/aztec-node/src/aztec-node/server.ts @@ -1,8 +1,6 @@ import { ArchiveSource, Archiver, KVArchiverDataStore, createArchiverClient } from '@aztec/archiver'; import { AztecNode, - ContractData, - ContractDataSource, GetUnencryptedLogsResponse, L1ToL2MessageAndIndex, L1ToL2MessageSource, @@ -54,7 +52,7 @@ import { getGlobalVariableBuilder, partitionReverts, } from '@aztec/sequencer-client'; -import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts'; +import { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/types/contracts'; import { MerkleTrees, ServerWorldStateSynchronizer, @@ -231,16 +229,6 @@ export class AztecNodeService implements AztecNode { return Promise.resolve(this.chainId); } - /** - * Lookup the contract data for this contract. - * Contains the ethereum portal address . - * @param contractAddress - The contract data address. - * @returns The contract's address & portal address. - */ - public async getContractData(contractAddress: AztecAddress): Promise { - return await this.contractDataSource.getContractData(contractAddress); - } - public getContractClass(id: Fr): Promise { return this.contractDataSource.getContractClass(id); } diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 872f764e925b..5ba67b2a28fc 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -41,7 +41,6 @@ export { AztecAddressLike, FunctionSelectorLike, WrappedFieldLike, - isContractDeployed, EthCheatCodes, computeAuthWitMessageHash, computeInnerAuthWitHash, @@ -83,7 +82,6 @@ export { AztecNode, Body, CompleteAddress, - ContractData, DeployedContract, ExtendedNote, FunctionCall, 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 2c49ba733707..c0e740d4d1eb 100644 --- a/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts +++ b/yarn-project/aztec.js/src/rpc_clients/pxe_client.ts @@ -1,6 +1,5 @@ import { AuthWitness, - ContractData, ExtendedNote, ExtendedUnencryptedL2Log, L2Block, @@ -39,7 +38,6 @@ export const createPXEClient = (url: string, fetch = makeFetch([1, 2, 3], false) AuthWitness, AztecAddress, CompleteAddress, - ContractData, FunctionSelector, EthAddress, ExtendedNote, diff --git a/yarn-project/aztec.js/src/utils/index.ts b/yarn-project/aztec.js/src/utils/index.ts index 9c612306fda0..1a0a8236744d 100644 --- a/yarn-project/aztec.js/src/utils/index.ts +++ b/yarn-project/aztec.js/src/utils/index.ts @@ -1,6 +1,5 @@ export * from './pub_key.js'; export * from './l1_contracts.js'; -export * from './l2_contracts.js'; export * from './abi_types.js'; export * from './cheat_codes.js'; export * from './authwit.js'; diff --git a/yarn-project/aztec.js/src/utils/l2_contracts.ts b/yarn-project/aztec.js/src/utils/l2_contracts.ts deleted file mode 100644 index a694049be803..000000000000 --- a/yarn-project/aztec.js/src/utils/l2_contracts.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { PXE } from '@aztec/circuit-types'; -import { AztecAddress } from '@aztec/foundation/aztec-address'; - -/** - * Checks whether a give contract is deployed on the network. - * @param pxe - The PXE to use to obtain the information. - * @param contractAddress - The address of the contract to check. - * @returns A flag indicating whether the contract is deployed. - */ -export async function isContractDeployed(pxe: PXE, contractAddress: AztecAddress): Promise { - return !!(await pxe.getContractData(contractAddress)) || !!(await pxe.getContractInstance(contractAddress)); -} diff --git a/yarn-project/aztec.js/src/wallet/base_wallet.ts b/yarn-project/aztec.js/src/wallet/base_wallet.ts index 6be38de7e6cb..f1cfa590f920 100644 --- a/yarn-project/aztec.js/src/wallet/base_wallet.ts +++ b/yarn-project/aztec.js/src/wallet/base_wallet.ts @@ -1,6 +1,5 @@ import { AuthWitness, - ContractData, DeployedContract, ExtendedNote, FunctionCall, @@ -102,9 +101,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); } - getContractData(contractAddress: AztecAddress): Promise { - return this.pxe.getContractData(contractAddress); - } getUnencryptedLogs(filter: LogFilter): Promise { return this.pxe.getUnencryptedLogs(filter); } 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 c20bae84f832..e6a3bde29a99 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,6 @@ import { EthAddress } from '@aztec/foundation/eth-address'; import { Fr } from '@aztec/foundation/fields'; import { createJsonRpcClient, defaultFetch } from '@aztec/foundation/json-rpc/client'; -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'; @@ -28,7 +27,6 @@ export function createAztecNodeClient(url: string, fetch = defaultFetch): AztecN AztecAddress, EthAddress, ExtendedUnencryptedL2Log, - ContractData, Fr, EventSelector, FunctionSelector, diff --git a/yarn-project/circuit-types/src/contract_data.test.ts b/yarn-project/circuit-types/src/contract_data.test.ts deleted file mode 100644 index 38d01bf7f8eb..000000000000 --- a/yarn-project/circuit-types/src/contract_data.test.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { EthAddress } from '@aztec/foundation/eth-address'; - -import { ContractData } from './contract_data.js'; - -describe('ContractData', () => { - const aztecAddress = AztecAddress.random(); - const portalAddress = EthAddress.random(); - - it('serializes / deserializes correctly without bytecode', () => { - const contractData = new ContractData(aztecAddress, portalAddress); - const buf = contractData.toBuffer(); - const serContractData = ContractData.fromBuffer(buf); - expect(contractData.contractAddress.equals(serContractData.contractAddress)).toBe(true); - expect(contractData.portalContractAddress.equals(serContractData.portalContractAddress)).toBe(true); - }); -}); diff --git a/yarn-project/circuit-types/src/contract_data.ts b/yarn-project/circuit-types/src/contract_data.ts deleted file mode 100644 index 67f170bd3527..000000000000 --- a/yarn-project/circuit-types/src/contract_data.ts +++ /dev/null @@ -1,119 +0,0 @@ -import { Fr, FunctionSelector } from '@aztec/circuits.js'; -import { AztecAddress } from '@aztec/foundation/aztec-address'; -import { EthAddress } from '@aztec/foundation/eth-address'; -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 { - /** - * Lookup the L2 contract base info for this contract. - * NOTE: This works for all Aztec contracts and will only return contractAddress / portalAddress. - * @param contractAddress - The contract data address. - * @returns The aztec & ethereum portal address (if found). - */ - getContractData(contractAddress: AztecAddress): Promise; - - /** - * Returns a contract's encoded public function, given its function selector. - * @param address - The contract aztec address. - * @param selector - The function's selector. - * @returns The function's data. - */ - getPublicFunction(address: AztecAddress, selector: FunctionSelector): Promise; - - /** - * Gets the number of the latest L2 block processed by the implementation. - * @returns The number of the latest L2 block processed by the implementation. - */ - getBlockNumber(): Promise; - - /** - * Returns the contract class for a given contract class id, or undefined if not found. - * @param id - Contract class id. - */ - getContractClass(id: Fr): Promise; - - /** - * Returns a publicly deployed contract instance given its address. - * @param address - Address of the deployed contract. - */ - getContract(address: AztecAddress): Promise; - - /** Returns the list of all class ids known. */ - getContractClassIds(): Promise; -} - -/** - * A contract data blob, containing L1 and L2 addresses. - * TODO(palla/purge-old-contract-deploy): Delete me - */ -export class ContractData { - constructor( - /** - * The L2 address of the contract, as a field element (32 bytes). - */ - public contractAddress: AztecAddress, - /** - * The L1 address of the contract, (20 bytes). - */ - public portalContractAddress: EthAddress, - ) {} - - /** - * Serializes this instance into a buffer, using 20 bytes for the eth address. - * @returns Encoded buffer. - */ - public toBuffer(): Buffer { - return serializeToBuffer(this.contractAddress, this.portalContractAddress); - } - - /** - * Serializes this instance into a string, using 20 bytes for the eth address. - * @returns Encoded string. - */ - public toString(): string { - return this.toBuffer().toString('hex'); - } - - /** True if all data is zero. */ - public isEmpty(): boolean { - return this.contractAddress.isZero() && this.portalContractAddress.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 aztecAddr = AztecAddress.fromBuffer(reader); - const ethAddr = new EthAddress(reader.readBytes(EthAddress.SIZE_IN_BYTES)); - return new ContractData(aztecAddr, ethAddr); - } - - /** - * 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 ContractData.fromBuffer(Buffer.from(str, 'hex')); - } - - /** - * Generate ContractData with random addresses. - * @returns ContractData. - */ - static random(): ContractData { - return new ContractData(AztecAddress.random(), EthAddress.random()); - } - - /** Generates an empty ContractData. */ - static empty(): ContractData { - return new ContractData(AztecAddress.ZERO, EthAddress.ZERO); - } -} diff --git a/yarn-project/circuit-types/src/index.ts b/yarn-project/circuit-types/src/index.ts index e1b118788739..5928dc19c185 100644 --- a/yarn-project/circuit-types/src/index.ts +++ b/yarn-project/circuit-types/src/index.ts @@ -1,4 +1,3 @@ -export * from './contract_data.js'; export * from './function_call.js'; export * from './keys/index.js'; export * from './notes/index.js'; diff --git a/yarn-project/circuit-types/src/interfaces/aztec-node.ts b/yarn-project/circuit-types/src/interfaces/aztec-node.ts index 3927c75f385f..f1ccd6ff13dd 100644 --- a/yarn-project/circuit-types/src/interfaces/aztec-node.ts +++ b/yarn-project/circuit-types/src/interfaces/aztec-node.ts @@ -11,7 +11,6 @@ import { AztecAddress } from '@aztec/foundation/aztec-address'; import { Fr } from '@aztec/foundation/fields'; import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts'; -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,14 +193,6 @@ export interface AztecNode { */ getL1ContractAddresses(): Promise; - /** - * Lookup the contract data for this contract. - * Contains the ethereum portal address . - * @param contractAddress - The contract data address. - * @returns The contract's address & portal address. - */ - getContractData(contractAddress: AztecAddress): Promise; - /** * Gets up to `limit` amount of logs starting from `from`. * @param from - Number of the L2 block to which corresponds the first logs to be returned. diff --git a/yarn-project/circuit-types/src/interfaces/pxe.ts b/yarn-project/circuit-types/src/interfaces/pxe.ts index 456899bd95fe..38b7b36e9180 100644 --- a/yarn-project/circuit-types/src/interfaces/pxe.ts +++ b/yarn-project/circuit-types/src/interfaces/pxe.ts @@ -3,7 +3,6 @@ import { ContractClassWithId, ContractInstanceWithAddress } from '@aztec/types/c import { NodeInfo } from '@aztec/types/interfaces'; import { AuthWitness } from '../auth_witness.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,14 +208,6 @@ export interface PXE { */ viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress): Promise; - /** - * Gets the portal contract address on L1 for the given contract. - * - * @param contractAddress - The contract's address. - * @returns The contract's portal address if found. - */ - getContractData(contractAddress: AztecAddress): Promise; - /** * Gets unencrypted logs based on the provided filter. * @param filter - The filter to apply to the logs. diff --git a/yarn-project/cli/src/cmds/check_deploy.ts b/yarn-project/cli/src/cmds/check_deploy.ts index 90408309ff41..c9777522e10e 100644 --- a/yarn-project/cli/src/cmds/check_deploy.ts +++ b/yarn-project/cli/src/cmds/check_deploy.ts @@ -1,13 +1,18 @@ -import { AztecAddress, isContractDeployed } from '@aztec/aztec.js'; +import { AztecAddress } from '@aztec/aztec.js'; import { DebugLogger, LogFn } from '@aztec/foundation/log'; import { createCompatibleClient } from '../client.js'; export async function checkDeploy(rpcUrl: string, contractAddress: AztecAddress, debugLogger: DebugLogger, log: LogFn) { const client = await createCompatibleClient(rpcUrl, debugLogger); - const isDeployed = await isContractDeployed(client, contractAddress); - if (isDeployed) { - log(`\nContract found at ${contractAddress.toString()}\n`); + const isPrivatelyDeployed = await client.getContractInstance(contractAddress); + const isPubliclyDeployed = await client.isContractPubliclyDeployed(contractAddress); + if (isPubliclyDeployed && isPrivatelyDeployed) { + log(`\nContract is publicly deployed at ${contractAddress.toString()}\n`); + } else if (isPrivatelyDeployed) { + log(`\nContract is registered in the local pxe at ${contractAddress.toString()} but not publicly deployed\n`); + } else if (isPubliclyDeployed) { + log(`\nContract is publicly deployed at ${contractAddress.toString()} but not registered in the local pxe\n`); } else { log(`\nNo contract found at ${contractAddress.toString()}\n`); } diff --git a/yarn-project/end-to-end/src/e2e_block_building.test.ts b/yarn-project/end-to-end/src/e2e_block_building.test.ts index f26b8cb17267..3885495eddfb 100644 --- a/yarn-project/end-to-end/src/e2e_block_building.test.ts +++ b/yarn-project/end-to-end/src/e2e_block_building.test.ts @@ -1,4 +1,5 @@ import { + AztecAddress, AztecNode, BatchCall, ContractDeployer, @@ -10,7 +11,6 @@ import { TxReceipt, TxStatus, Wallet, - isContractDeployed, } from '@aztec/aztec.js'; import { times } from '@aztec/foundation/collection'; import { pedersenHash } from '@aztec/foundation/crypto'; @@ -73,7 +73,8 @@ describe('e2e_block_building', () => { expect(receipts.map(r => r.blockNumber)).toEqual(times(TX_COUNT, () => receipts[0].blockNumber)); // Assert all contracts got deployed - const areDeployed = await Promise.all(receipts.map(r => isContractDeployed(pxe, r.contract.address))); + const isContractDeployed = async (address: AztecAddress) => !!(await pxe.getContractInstance(address)); + const areDeployed = await Promise.all(receipts.map(r => isContractDeployed(r.contract.address))); expect(areDeployed).toEqual(times(TX_COUNT, () => true)); }, 60_000); 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 87524d30443e..835be3a99378 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 @@ -16,7 +16,6 @@ import { Wallet, getContractClassFromArtifact, getContractInstanceFromDeployParams, - isContractDeployed, } from '@aztec/aztec.js'; import { broadcastPrivateFunction, @@ -65,8 +64,8 @@ describe('e2e_deploy_contract', () => { const deployer = new ContractDeployer(TestContractArtifact, wallet, publicKey); const receipt = await deployer.deploy().send({ contractAddressSalt: salt }).wait({ wallet }); expect(receipt.contract.address).toEqual(deploymentData.address); - expect(await isContractDeployed(pxe, deploymentData.address)).toBe(true); - expect(await isContractDeployed(pxe, AztecAddress.random())).toBe(false); + expect(await pxe.getContractInstance(deploymentData.address)).toBeDefined(); + expect(await pxe.isContractPubliclyDeployed(deploymentData.address)).toBeDefined(); }, 60_000); /** @@ -116,7 +115,6 @@ describe('e2e_deploy_contract', () => { const address = receipt.contract.address; const expectedPortal = portalContract.toString(); - expect((await pxe.getContractData(address))?.portalContractAddress.toString()).toEqual(expectedPortal); expect((await pxe.getContractInstance(address))?.portalContractAddress.toString()).toEqual(expectedPortal); }, 60_000); diff --git a/yarn-project/end-to-end/src/e2e_persistence.test.ts b/yarn-project/end-to-end/src/e2e_persistence.test.ts index 8ddeda7d039c..8f00ac3d9fff 100644 --- a/yarn-project/end-to-end/src/e2e_persistence.test.ts +++ b/yarn-project/end-to-end/src/e2e_persistence.test.ts @@ -191,7 +191,7 @@ describe('Aztec persistence', () => { }); it('the node has the contract', async () => { - await expect(context.aztecNode.getContractData(contractAddress)).resolves.toBeDefined(); + await expect(context.aztecNode.getContract(contractAddress)).resolves.toBeDefined(); }); it('pxe does not know of the deployed contract', async () => { diff --git a/yarn-project/end-to-end/src/shared/cli.ts b/yarn-project/end-to-end/src/shared/cli.ts index 48db63690672..3f6228c8c4c6 100644 --- a/yarn-project/end-to-end/src/shared/cli.ts +++ b/yarn-project/end-to-end/src/shared/cli.ts @@ -143,13 +143,13 @@ export const cliTestSuite = ( expect(loggedAddress).toBeDefined(); contractAddress = AztecAddress.fromString(loggedAddress!); - const deployedContract = await pxe.getContractData(contractAddress); - expect(deployedContract?.contractAddress).toEqual(contractAddress); + const deployedContract = await pxe.getContractInstance(contractAddress); + expect(deployedContract?.address).toEqual(contractAddress); debug('Check contract can be found in returned address'); await run(`check-deploy -ca ${loggedAddress}`); - const checkResult = findInLogs(/Contract\sfound\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(checkResult).toEqual(deployedContract?.contractAddress.toString()); + const checkResult = findInLogs(/Contract.+\sat\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; + expect(checkResult).toEqual(deployedContract?.address.toString()); const secret = Fr.random(); const secretHash = computeMessageSecretHash(secret); @@ -171,11 +171,10 @@ export const cliTestSuite = ( `send redeem_shield --args ${ownerAddress} ${INITIAL_BALANCE} ${secret} --contract-artifact TokenContractArtifact --contract-address ${contractAddress.toString()} --private-key ${privKey}`, ); - // clear logs clearLogs(); await run(`get-contract-data ${loggedAddress}`); const contractDataAddress = findInLogs(/^\s?Address:\s+(?
0x[a-fA-F0-9]+)/)?.groups?.address; - expect(contractDataAddress).toEqual(deployedContract?.contractAddress.toString()); + expect(contractDataAddress).toEqual(deployedContract?.address.toString()); debug("Check owner's balance"); await run( 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 094d1813c1d9..7fe3bb8a591d 100644 --- a/yarn-project/pxe/src/pxe_http/pxe_http_server.ts +++ b/yarn-project/pxe/src/pxe_http/pxe_http_server.ts @@ -1,7 +1,6 @@ import { AuthWitness, CompleteAddress, - ContractData, ExtendedNote, ExtendedUnencryptedL2Log, L2Block, @@ -35,7 +34,6 @@ export function createPXERpcServer(pxeService: PXE): JsonRpcServer { CompleteAddress, AztecAddress, TxExecutionRequest, - ContractData, 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 ea516e7002f2..6b947bd2cd13 100644 --- a/yarn-project/pxe/src/pxe_service/pxe_service.ts +++ b/yarn-project/pxe/src/pxe_service/pxe_service.ts @@ -1,7 +1,6 @@ import { AuthWitness, AztecNode, - ContractData, DeployedContract, ExtendedNote, FunctionCall, @@ -234,7 +233,7 @@ export class PXEService implements PXE { } public async getPublicStorageAt(contract: AztecAddress, slot: Fr) { - if ((await this.getContractData(contract)) === undefined) { + if (!(await this.getContractInstance(contract))) { throw new Error(`Contract ${contract.toString()} is not deployed`); } return await this.node.getPublicStorageAt(contract, slot); @@ -427,10 +426,6 @@ export class PXEService implements PXE { return await this.node.getBlockNumber(); } - public async getContractData(contractAddress: AztecAddress): Promise { - return await this.node.getContractData(contractAddress); - } - /** * Gets unencrypted logs based on the provided filter. * @param filter - The filter to apply to the logs. diff --git a/yarn-project/sequencer-client/src/client/sequencer-client.ts b/yarn-project/sequencer-client/src/client/sequencer-client.ts index f41ed5ac7fba..2afed68da5d0 100644 --- a/yarn-project/sequencer-client/src/client/sequencer-client.ts +++ b/yarn-project/sequencer-client/src/client/sequencer-client.ts @@ -1,6 +1,7 @@ -import { ContractDataSource, L1ToL2MessageSource, L2BlockSource } from '@aztec/circuit-types'; +import { L1ToL2MessageSource, L2BlockSource } from '@aztec/circuit-types'; import { createDebugLogger } from '@aztec/foundation/log'; import { P2P } from '@aztec/p2p'; +import { ContractDataSource } from '@aztec/types/contracts'; import { WorldStateSynchronizer } from '@aztec/world-state'; import * as fs from 'fs/promises'; diff --git a/yarn-project/sequencer-client/src/sequencer/public_processor.ts b/yarn-project/sequencer-client/src/sequencer/public_processor.ts index 8c479cfac47b..1c620bd27873 100644 --- a/yarn-project/sequencer-client/src/sequencer/public_processor.ts +++ b/yarn-project/sequencer-client/src/sequencer/public_processor.ts @@ -1,9 +1,10 @@ -import { ContractDataSource, L1ToL2MessageSource, SimulationError, Tx } from '@aztec/circuit-types'; +import { L1ToL2MessageSource, SimulationError, Tx } from '@aztec/circuit-types'; import { TxSequencerProcessingStats } from '@aztec/circuit-types/stats'; import { GlobalVariables, Header } from '@aztec/circuits.js'; import { createDebugLogger } from '@aztec/foundation/log'; import { Timer } from '@aztec/foundation/timer'; import { PublicExecutor, PublicStateDB } from '@aztec/simulator'; +import { ContractDataSource } from '@aztec/types/contracts'; import { MerkleTreeOperations } from '@aztec/world-state'; import { EmptyPublicProver } from '../prover/empty.js'; diff --git a/yarn-project/sequencer-client/src/simulator/public_executor.ts b/yarn-project/sequencer-client/src/simulator/public_executor.ts index d915a74b1583..c93c6d7e6c83 100644 --- a/yarn-project/sequencer-client/src/simulator/public_executor.ts +++ b/yarn-project/sequencer-client/src/simulator/public_executor.ts @@ -1,5 +1,4 @@ import { - ContractDataSource, L1ToL2MessageSource, MerkleTreeId, NullifierMembershipWitness, @@ -22,7 +21,7 @@ import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash'; import { createDebugLogger } from '@aztec/foundation/log'; import { ClassRegistererAddress } from '@aztec/protocol-contracts/class-registerer'; import { CommitmentsDB, MessageLoadOracleInputs, PublicContractsDB, PublicStateDB } from '@aztec/simulator'; -import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts'; +import { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/types/contracts'; import { MerkleTreeOperations } from '@aztec/world-state'; /** diff --git a/yarn-project/types/src/contracts/contract_data_source.ts b/yarn-project/types/src/contracts/contract_data_source.ts new file mode 100644 index 000000000000..c9d438cd24e2 --- /dev/null +++ b/yarn-project/types/src/contracts/contract_data_source.ts @@ -0,0 +1,39 @@ +import { FunctionSelector } from '@aztec/foundation/abi'; +import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { Fr } from '@aztec/foundation/fields'; + +import { ContractClassPublic, PublicFunction } from './contract_class.js'; +import { ContractInstanceWithAddress } from './contract_instance.js'; + +export interface ContractDataSource { + /** + * Returns a contract's encoded public function, given its function selector. + * @param address - The contract aztec address. + * @param selector - The function's selector. + * @returns The function's data. + */ + getPublicFunction(address: AztecAddress, selector: FunctionSelector): Promise; + + /** + * Gets the number of the latest L2 block processed by the implementation. + * @returns The number of the latest L2 block processed by the implementation. + */ + getBlockNumber(): Promise; + + /** + * Returns the contract class for a given contract class id, or undefined if not found. + * @param id - Contract class id. + */ + getContractClass(id: Fr): Promise; + + /** + * Returns a publicly deployed contract instance given its address. + * @param address - Address of the deployed contract. + */ + getContract(address: AztecAddress): Promise; + + /** + * Returns the list of all class ids known. + */ + getContractClassIds(): Promise; +} diff --git a/yarn-project/types/src/contracts/index.ts b/yarn-project/types/src/contracts/index.ts index b90e91afc35d..5c2df019b418 100644 --- a/yarn-project/types/src/contracts/index.ts +++ b/yarn-project/types/src/contracts/index.ts @@ -1,2 +1,3 @@ export * from './contract_class.js'; export * from './contract_instance.js'; +export * from './contract_data_source.js';