Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Jul 26, 2024
1 parent 684c3b9 commit db4e8b5
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ sequenceDiagram
LifeCycle->>LifeCycle: note.header = NoteHeader { contract_address, <br> storage_slot: derived_slot, nonce: 0, note_hash_counter }
LifeCycle->>Utils: compute_slotted_note_hash(note)
Utils->>TokenNote: note.compute_note_hiding_point()
TokenNote->>Utils: note_hash = H(amount, to, randomness)
Utils->>NoteHash: compute_inner_hash(derived_slot, note_hash)
TokenNote->>Utils: note_hiding_point = H(amount, to, randomness)
Utils->>NoteHash: compute_slotted_note_hash(derived_slot, note_hiding_point)
NoteHash->>LifeCycle: slotted_note_hash = H(derived_slot, note_hash)
LifeCycle->>Context: push_note_hash(slotted_note_hash)
end
Expand Down
11 changes: 5 additions & 6 deletions yarn-project/aztec.js/src/utils/cheat_codes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { type Note, type PXE } from '@aztec/circuit-types';
import { type AztecAddress, type EthAddress, Fr } from '@aztec/circuits.js';
import { deriveStorageSlotInMap } from '@aztec/circuits.js/hash';
import { toBigIntBE, toHex } from '@aztec/foundation/bigint-buffer';
import { keccak256, pedersenHash } from '@aztec/foundation/crypto';
import { keccak256 } from '@aztec/foundation/crypto';
import { createDebugLogger } from '@aztec/foundation/log';

import fs from 'fs';
Expand Down Expand Up @@ -239,14 +240,12 @@ export class AztecCheatCodes {

/**
* Computes the slot value for a given map and key.
* @param baseSlot - The base slot of the map (specified in Aztec.nr contract)
* @param mapSlot - The slot of the map (specified in Aztec.nr contract)
* @param key - The key to lookup in the map
* @returns The storage slot of the value in the map
*/
public computeSlotInMap(baseSlot: Fr | bigint, key: Fr | bigint | AztecAddress): Fr {
// Based on `at` function in
// aztec3-packages/aztec-nr/aztec/src/state_vars/map.nr
return pedersenHash([new Fr(baseSlot), new Fr(key)]);
public computeSlotInMap(mapSlot: Fr | bigint, key: Fr | bigint | AztecAddress): Fr {
return deriveStorageSlotInMap(mapSlot, new Fr(key));
}

/**
Expand Down
1 change: 1 addition & 0 deletions yarn-project/circuits.js/src/hash/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './hash.js';
export * from './map_slot.js';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
import { Fr } from '@aztec/foundation/fields';
import { updateInlineTestData } from '@aztec/foundation/testing';

import { deriveStorageSlotInMap } from './map_slot.js';
import { deriveStorageSlotInMap } from './index.js';

describe('Map slot', () => {
it('derived map slot matches Noir', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO(benesjan): update cheatcodes to use this
import { pedersenHash } from '@aztec/foundation/crypto';
import { type Fr } from '@aztec/foundation/fields';

Expand All @@ -7,10 +6,9 @@ import { type Fr } from '@aztec/foundation/fields';
* @param mapSlot - The slot of the map within state.
* @param key - The key of the map.
* @returns The slot in the contract storage where the value is stored.
* TODO(#7551): Test that it matches Noir.
*/
export function deriveStorageSlotInMap(
mapSlot: Fr,
mapSlot: Fr | bigint,
key: {
/** Serialize to a field. */
toField: () => Fr;
Expand Down
1 change: 0 additions & 1 deletion yarn-project/circuits.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export * from './contract/index.js';
export * from './hints/index.js';
export * from './interfaces/index.js';
export * from './keys/index.js';
export * from './storage_slots/index.js';
export * from './structs/index.js';
export * from './types/index.js';
export * from './utils/index.js';
Expand Down
1 change: 0 additions & 1 deletion yarn-project/circuits.js/src/storage_slots/index.ts

This file was deleted.

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 @@ -289,11 +289,11 @@ export class PXEService implements PXE {
return this.db.getContractsAddresses();
}

public async getPublicStorageAt(contract: AztecAddress, contractStorageIndex: Fr) {
public async getPublicStorageAt(contract: AztecAddress, slot: Fr) {
if (!(await this.getContractInstance(contract))) {
throw new Error(`Contract ${contract.toString()} is not deployed`);
}
return await this.node.getPublicStorageAt(contract, contractStorageIndex, 'latest');
return await this.node.getPublicStorageAt(contract, slot, 'latest');
}

public async getIncomingNotes(filter: IncomingNotesFilter): Promise<ExtendedNote[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
computeAppNullifierSecretKey,
computeOvskApp,
deriveKeys,
deriveStorageSlotInMap,
getContractInstanceFromDeployParams,
getNonEmptyItems,
} from '@aztec/circuits.js';
Expand All @@ -39,6 +38,7 @@ import {
computeSecretHash,
computeSlottedNoteHash,
computeVarArgsHash,
deriveStorageSlotInMap,
} from '@aztec/circuits.js/hash';
import { makeHeader } from '@aztec/circuits.js/testing';
import {
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/simulator/src/public/fee_payment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GAS_TOKEN_ADDRESS, deriveStorageSlotInMap } from '@aztec/circuits.js';
import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
import { GAS_TOKEN_ADDRESS } from '@aztec/circuits.js';
import { computePublicDataTreeLeafSlot, deriveStorageSlotInMap } from '@aztec/circuits.js/hash';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { Fr } from '@aztec/foundation/fields';
import { GasTokenArtifact } from '@aztec/protocol-contracts/gas-token';
Expand Down

0 comments on commit db4e8b5

Please sign in to comment.