Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/aztec/smart_contracts/functions/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ When an unconstrained function is called, it prompts the ACIR simulator to
1. generate the execution environment
2. execute the function within this environment

To generate the environment, the simulator gets the blockheader from the [PXE database](../../concepts/pxe/index.md#database) and passes it along with the contract address to `ViewDataOracle`. This creates a context that simulates the state of the blockchain at a specific block, allowing the unconstrained function to access and interact with blockchain data as it would appear in that block, but without affecting the actual blockchain state.
To generate the environment, the simulator gets the blockheader from the [PXE database](../../concepts/pxe/index.md#database) and passes it along with the contract address to `UnconstrainedExecutionOracle`. This creates a context that simulates the state of the blockchain at a specific block, allowing the unconstrained function to access and interact with blockchain data as it would appear in that block, but without affecting the actual blockchain state.

Once the execution environment is created, `execute_unconstrained_function` is invoked:

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ export class AztecNodeService implements AztecNode, Traceable {
* @param blockNumber - The block number at which to get the data or 'latest'.
* @returns Storage value at the given contract slot.
*/
public async getPublicStorageAt(contract: AztecAddress, slot: Fr, blockNumber: L2BlockNumber): Promise<Fr> {
public async getPublicStorageAt(blockNumber: L2BlockNumber, contract: AztecAddress, slot: Fr): Promise<Fr> {
const committedDb = await this.#getWorldState(blockNumber);
const leafSlot = await computePublicDataTreeLeafSlot(contract, slot);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import {
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
import type { ContractClass, ContractInstance } from '@aztec/stdlib/contract';

import type { ContractArtifactDatabase } from '../database/contracts/contract_artifact_db.js';
import type { ContractInstanceDatabase } from '../database/contracts/contract_instance_db.js';
import type { ContractArtifactDatabase } from '../database/interfaces/contract_artifact_db.js';
import type { ContractInstanceDatabase } from '../database/interfaces/contract_instance_db.js';
import { PrivateFunctionsTree } from './private_functions_tree.js';

/**
* ContractDataOracle serves as a data manager and retriever for Aztec.nr contracts.
* ContractDataProvider serves as a data manager and retriever for Aztec.nr contracts.
* It provides methods to obtain contract addresses, function ABI, bytecode, and membership witnesses
* from a given contract address and function selector. The class maintains a cache of ContractTree instances
* to efficiently serve the requested data. It interacts with the ContractDatabase and AztecNode to fetch
* the required information and facilitate cryptographic proof generation.
*/
export class ContractDataOracle {
export class ContractDataProvider {
/** Map from contract class id to private function tree. */
private contractClasses: Map<string, PrivateFunctionsTree> = new Map();

Expand Down
2 changes: 2 additions & 0 deletions yarn-project/pxe/src/contract_data_provider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { ContractDataProvider } from './contract_data_provider.js';
export { PrivateFunctionsTree } from './private_functions_tree.js';
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/database/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './pxe_database.js';
export * from './kv_pxe_database.js';
export * from './interfaces/index.js';
3 changes: 3 additions & 0 deletions yarn-project/pxe/src/database/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type { ContractArtifactDatabase } from './contract_artifact_db.js';
export type { ContractInstanceDatabase } from './contract_instance_db.js';
export type { PxeDatabase } from './pxe_database.js';
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import type { IndexedTaggingSecret } from '@aztec/stdlib/logs';
import type { NotesFilter } from '@aztec/stdlib/note';
import type { BlockHeader } from '@aztec/stdlib/tx';

import type { ContractArtifactDatabase } from './contracts/contract_artifact_db.js';
import type { ContractInstanceDatabase } from './contracts/contract_instance_db.js';
import type { NoteDao } from './note_dao.js';
import type { NoteDao } from '../note_dao.js';
import type { ContractArtifactDatabase } from './contract_artifact_db.js';
import type { ContractInstanceDatabase } from './contract_instance_db.js';

/**
* A database interface that provides methods for retrieving, adding, and removing transactional data related to Aztec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { makeHeader, randomTxHash } from '@aztec/stdlib/testing';

import times from 'lodash.times';

import { NoteDao } from './note_dao.js';
import { NoteDao } from '../note_dao.js';
import type { PxeDatabase } from './pxe_database.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/database/kv_pxe_database.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';

import { describePxeDatabase } from './interfaces/pxe_database_test_suite.js';
import { KVPxeDatabase } from './kv_pxe_database.js';
import { describePxeDatabase } from './pxe_database_test_suite.js';

describe('KVPxeDatabase', () => {
let database: KVPxeDatabase;
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/database/kv_pxe_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import { NoteStatus, type NotesFilter } from '@aztec/stdlib/note';
import { MerkleTreeId } from '@aztec/stdlib/trees';
import { BlockHeader } from '@aztec/stdlib/tx';

import type { PxeDatabase } from './interfaces/pxe_database.js';
import { NoteDao } from './note_dao.js';
import type { PxeDatabase } from './pxe_database.js';

/**
* A PXE database backed by LMDB.
Expand Down
132 changes: 0 additions & 132 deletions yarn-project/pxe/src/database/outgoing_note_dao.ts

This file was deleted.

5 changes: 2 additions & 3 deletions yarn-project/pxe/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ export * from './config/index.js';
export * from './utils/create_pxe_service.js';

export * from './database/index.js';
export { ContractDataOracle } from './contract_data_oracle/index.js';
export { PrivateFunctionsTree } from './contract_data_oracle/private_functions_tree.js';
export { SimulatorOracle } from './simulator_oracle/index.js';
export { PXEDataProvider } from './pxe_data_provider/index.js';
export * from './contract_data_provider/index.js';
14 changes: 7 additions & 7 deletions yarn-project/pxe/src/kernel_oracle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SharedMutableValues, SharedMutableValuesWithHash } from '@aztec/stdlib/
import type { NullifierMembershipWitness } from '@aztec/stdlib/trees';
import type { VerificationKeyAsFields } from '@aztec/stdlib/vks';

import type { ContractDataOracle } from '../contract_data_oracle/index.js';
import type { ContractDataProvider } from '../contract_data_provider/index.js';
import type { ProvingDataOracle } from './../kernel_prover/proving_data_oracle.js';

// TODO: Block number should not be "latest".
Expand All @@ -27,28 +27,28 @@ import type { ProvingDataOracle } from './../kernel_prover/proving_data_oracle.j
*/
export class KernelOracle implements ProvingDataOracle {
constructor(
private contractDataOracle: ContractDataOracle,
private contractDataProvider: ContractDataProvider,
private keyStore: KeyStore,
private node: AztecNode,
private blockNumber: L2BlockNumber = 'latest',
private log = createLogger('pxe:kernel_oracle'),
) {}

public async getContractAddressPreimage(address: AztecAddress) {
const instance = await this.contractDataOracle.getContractInstance(address);
const instance = await this.contractDataProvider.getContractInstance(address);
return {
saltedInitializationHash: await computeSaltedInitializationHash(instance),
...instance,
};
}

public async getContractClassIdPreimage(contractClassId: Fr) {
const contractClass = await this.contractDataOracle.getContractClass(contractClassId);
const contractClass = await this.contractDataProvider.getContractClass(contractClassId);
return computeContractClassIdPreimage(contractClass);
}

public async getFunctionMembershipWitness(contractClassId: Fr, selector: FunctionSelector) {
return await this.contractDataOracle.getFunctionMembershipWitness(contractClassId, selector);
return await this.contractDataProvider.getFunctionMembershipWitness(contractClassId, selector);
}

public getVkMembershipWitness(vk: VerificationKeyAsFields) {
Expand Down Expand Up @@ -82,7 +82,7 @@ export class KernelOracle implements ProvingDataOracle {
}

public getDebugFunctionName(contractAddress: AztecAddress, selector: FunctionSelector): Promise<string> {
return this.contractDataOracle.getDebugFunctionName(contractAddress, selector);
return this.contractDataProvider.getDebugFunctionName(contractAddress, selector);
}

public async getUpdatedClassIdHints(contractAddress: AztecAddress): Promise<UpdatedClassIdHints> {
Expand All @@ -101,7 +101,7 @@ export class KernelOracle implements ProvingDataOracle {
}

const readStorage = (storageSlot: Fr) =>
this.node.getPublicStorageAt(ProtocolContractAddress.ContractInstanceDeployer, storageSlot, this.blockNumber);
this.node.getPublicStorageAt(this.blockNumber, ProtocolContractAddress.ContractInstanceDeployer, storageSlot);
const sharedMutableValues = await SharedMutableValues.readFromTree(sharedMutableSlot, readStorage);

return new UpdatedClassIdHints(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ContractNotFoundError } from '@aztec/simulator/client';
import type { L1NotePayload } from '@aztec/stdlib/logs';
import { Note } from '@aztec/stdlib/note';

import type { PxeDatabase } from '../database/pxe_database.js';
import type { PxeDatabase } from '../database/interfaces/pxe_database.js';

/**
* Merges privately and publicly delivered note values.
Expand Down
Loading
Loading