Skip to content

Commit

Permalink
chore: remove old public storage access ordering hack (#7063)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanks12 authored Jun 17, 2024
1 parent 5ff5ffb commit bf6b8b8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 76 deletions.
69 changes: 0 additions & 69 deletions yarn-project/simulator/src/public/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import {
type NoteHash,
type Nullifier,
type PublicCallRequest,
PublicDataRead,
PublicDataUpdateRequest,
type ReadRequest,
} from '@aztec/circuits.js';
import { computePublicDataTreeLeafSlot, computePublicDataTreeValue } from '@aztec/circuits.js/hash';

import { type Gas } from '../avm/avm_gas.js';

Expand Down Expand Up @@ -98,72 +95,6 @@ export function isPublicExecutionResult(
return 'execution' in input && input.execution !== undefined;
}

/**
* Collect all public storage reads across all nested executions
* and convert them to PublicDataReads (to match kernel output).
* @param execResult - The topmost execution result.
* @returns All public data reads (in execution order).
*/
export function collectPublicDataReads(execResult: PublicExecutionResult): PublicDataRead[] {
// HACK(#1622): part of temporary hack - may be able to remove this function after public state ordering is fixed
const thisExecPublicDataReads = execResult.contractStorageReads.map(read =>
contractStorageReadToPublicDataRead(read),
);
const unsorted = [
...thisExecPublicDataReads,
...[...execResult.nestedExecutions].flatMap(result => collectPublicDataReads(result)),
];
return unsorted.sort((a, b) => a.sideEffectCounter! - b.sideEffectCounter!);
}

/**
* Collect all public storage update requests across all nested executions
* and convert them to PublicDataUpdateRequests (to match kernel output).
* @param execResult - The topmost execution result.
* @returns All public data reads (in execution order).
*/
export function collectPublicDataUpdateRequests(execResult: PublicExecutionResult): PublicDataUpdateRequest[] {
// HACK(#1622): part of temporary hack - may be able to remove this function after public state ordering is fixed
const thisExecPublicDataUpdateRequests = execResult.contractStorageUpdateRequests.map(update =>
contractStorageUpdateRequestToPublicDataUpdateRequest(update),
);
const unsorted = [
...thisExecPublicDataUpdateRequests,
...[...execResult.nestedExecutions].flatMap(result => collectPublicDataUpdateRequests(result)),
];
return unsorted.sort((a, b) => a.sideEffectCounter! - b.sideEffectCounter!);
}

/**
* Convert a Contract Storage Read to a Public Data Read.
* @param read - the contract storage read to convert
* @param contractAddress - the contract address of the read
* @returns The public data read.
*/
function contractStorageReadToPublicDataRead(read: ContractStorageRead): PublicDataRead {
return new PublicDataRead(
computePublicDataTreeLeafSlot(read.contractAddress!, read.storageSlot),
computePublicDataTreeValue(read.currentValue),
read.sideEffectCounter!,
);
}

/**
* Convert a Contract Storage Update Request to a Public Data Update Request.
* @param update - the contract storage update request to convert
* @param contractAddress - the contract address of the data update request.
* @returns The public data update request.
*/
function contractStorageUpdateRequestToPublicDataUpdateRequest(
update: ContractStorageUpdateRequest,
): PublicDataUpdateRequest {
return new PublicDataUpdateRequest(
computePublicDataTreeLeafSlot(update.contractAddress!, update.storageSlot),
computePublicDataTreeValue(update.newValue),
update.sideEffectCounter!,
);
}

/**
* Checks whether the child execution result is valid for a static call (no state modifications).
* @param executionResult - The execution result of a public function
Expand Down
8 changes: 1 addition & 7 deletions yarn-project/simulator/src/public/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
export * from './abstract_phase_manager.js';
export * from './db_interfaces.js';
export {
collectPublicDataReads,
collectPublicDataUpdateRequests,
isPublicExecutionResult,
type PublicExecution,
type PublicExecutionResult,
} from './execution.js';
export { isPublicExecutionResult, type PublicExecution, type PublicExecutionResult } from './execution.js';
export { PublicExecutor } from './executor.js';
export * from './fee_payment.js';
export { HintsBuilder } from './hints_builder.js';
Expand Down

0 comments on commit bf6b8b8

Please sign in to comment.