import { Fr } from '@aztec/foundation/curves/bn254'; import type { AztecAddress } from '@aztec/stdlib/aztec-address'; import type { PublicStateDBInterface } from '../db_interfaces.js'; type PublicStorageReadResult = { value: Fr; cached: boolean; }; /** * A class to manage public storage reads and writes during a contract call's AVM simulation. * Maintains a storage write cache, and ensures that reads fall back to the correct source. * When a contract call completes, its storage cache can be merged into its parent's. */ export declare class PublicStorage { /** Reference to node storage. Checked on parent cache-miss. */ private readonly hostPublicStorage; /** Parent's storage. Checked on this' cache-miss. */ private readonly parent?; /** Cached storage writes. */ private readonly cache; constructor( /** Reference to node storage. Checked on parent cache-miss. */ hostPublicStorage: PublicStateDBInterface, /** Parent's storage. Checked on this' cache-miss. */ parent?: PublicStorage | undefined); /** * Create a new public storage manager forked from this one */ fork(): PublicStorage; /** * Read a storage value from this' cache or parent's (recursively). * DOES NOT CHECK HOST STORAGE! * * @param contractAddress - the address of the contract whose storage is being read from * @param slot - the slot in the contract's storage being read from * @returns value: the latest value written according to this cache or the parent's. undefined on cache miss. */ readHereOrParent(contractAddress: AztecAddress, slot: Fr): Fr | undefined; /** * Read a value from storage. * 1. Check cache. * 2. Check parent cache. * 3. Fall back to the host state. * 4. Not found! Value has never been written to before. Flag it as non-existent and return value zero. * * @param contractAddress - the address of the contract whose storage is being read from * @param slot - the slot in the contract's storage being read from * @returns exists: whether the slot has EVER been written to before, value: the latest value written to slot, or 0 if never written to before */ read(contractAddress: AztecAddress, slot: Fr): Promise; /** * Stage a storage write. * * @param contractAddress - the address of the contract whose storage is being written to * @param slot - the slot in the contract's storage being written to * @param value - the value being written to the slot */ write(contractAddress: AztecAddress, slot: Fr, value: Fr): void; /** * Merges another PublicStorage's cache (pending writes) into this one. * * @param incomingPublicStorage - the incoming public storage to merge into this instance's */ acceptAndMerge(incomingPublicStorage: PublicStorage): void; } export {}; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljX3N0b3JhZ2UuZC50cyIsInNvdXJjZVJvb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