Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: API inconsistency fix #3190

Merged
merged 1 commit into from
Nov 2, 2023
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
8 changes: 4 additions & 4 deletions yarn-project/acir-simulator/src/client/view_data_oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ export class ViewDataOracle extends TypedOracle {
}

const values = [];
for (let i = 0; i < Number(numberOfElements); i++) {
const storageSlot = startStorageSlot.value + BigInt(i);
for (let i = 0n; i < numberOfElements; i++) {
const storageSlot = new Fr(startStorageSlot.value + i);
const value = await this.aztecNode.getPublicStorageAt(this.contractAddress, storageSlot);
if (value === undefined) {
throw new Error(`Oracle storage read undefined: slot=${storageSlot.toString(16)}`);
throw new Error(`Oracle storage read undefined: slot=${storageSlot.toString()}`);
}

this.log(`Oracle storage read: slot=${storageSlot.toString(16)} value=${value}`);
this.log(`Oracle storage read: slot=${storageSlot.toString()} value=${value}`);
values.push(value);
}
return values;
Expand Down
11 changes: 7 additions & 4 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,18 @@ export class AztecNodeService implements AztecNode {
}

/**
* Gets the storage value at the given contract slot.
* Gets the storage value at the given contract storage slot.
*
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
* Aztec's version of `eth_getStorageAt`.
*
* @param contract - Address of the contract to query.
* @param slot - Slot to query.
* @returns Storage value at the given contract slot (or undefined if not found).
* Note: Aztec's version of `eth_getStorageAt`.
*/
public async getPublicStorageAt(contract: AztecAddress, slot: bigint): Promise<Fr | undefined> {
public async getPublicStorageAt(contract: AztecAddress, slot: Fr): Promise<Fr | undefined> {
const committedDb = await this.#getWorldState();
const leafIndex = computePublicDataTreeIndex(await CircuitsWasm.get(), contract, new Fr(slot));
const leafIndex = computePublicDataTreeIndex(await CircuitsWasm.get(), contract, slot);
const value = await committedDb.getLeafValue(MerkleTreeId.PUBLIC_DATA_TREE, leafIndex.value);
return value ? Fr.fromBuffer(value) : undefined;
}
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ export class PXEService implements PXE {
return (await this.db.getContracts()).map(c => c.completeAddress.address);
}

public async getPublicStorageAt(contract: AztecAddress, storageSlot: Fr) {
public async getPublicStorageAt(contract: AztecAddress, slot: Fr) {
if ((await this.getContractData(contract)) === undefined) {
throw new Error(`Contract ${contract.toString()} is not deployed`);
}
return await this.node.getPublicStorageAt(contract, storageSlot.value);
return await this.node.getPublicStorageAt(contract, slot);
}

public async getNotes(filter: NoteFilter): Promise<ExtendedNote[]> {
Expand Down
8 changes: 6 additions & 2 deletions yarn-project/types/src/interfaces/aztec-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,16 @@ export interface AztecNode extends StateInfoProvider {
getPendingTxByHash(txHash: TxHash): Promise<Tx | undefined>;

/**
* Gets the storage value at the given contract slot. Our version of eth_getStorageAt.
* Gets the storage value at the given contract storage slot.
*
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
* Aztec's version of `eth_getStorageAt`.
*
* @param contract - Address of the contract to query.
* @param slot - Slot to query.
* @returns Storage value at the given contract slot (or undefined if not found).
*/
getPublicStorageAt(contract: AztecAddress, slot: bigint): Promise<Fr | undefined>;
getPublicStorageAt(contract: AztecAddress, slot: Fr): Promise<Fr | undefined>;

/**
* Returns the current committed roots for the data trees.
Expand Down
13 changes: 8 additions & 5 deletions yarn-project/types/src/interfaces/pxe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,17 @@ export interface PXE {
getTx(txHash: TxHash): Promise<L2Tx | undefined>;

/**
* Retrieves the public storage data at a specified contract address and storage slot.
* Gets the storage value at the given contract storage slot.
*
* @param contract - The AztecAddress of the target contract.
* @param storageSlot - The Fr representing the storage slot to be fetched.
* @returns A buffer containing the public storage data at the storage slot.
* @remarks The storage slot here refers to the slot as it is defined in Noir not the index in the merkle tree.
* Aztec's version of `eth_getStorageAt`.
*
* @param contract - Address of the contract to query.
* @param slot - Slot to query.
* @returns Storage value at the given contract slot (or undefined if not found).
* @throws If the contract is not deployed.
*/
getPublicStorageAt(contract: AztecAddress, storageSlot: Fr): Promise<Fr | undefined>;
getPublicStorageAt(contract: AztecAddress, slot: Fr): Promise<Fr | undefined>;

/**
* Gets notes of accounts registered in this PXE based on the provided filter.
Expand Down