Skip to content

Commit

Permalink
chore: stop calling public kernel tail
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanks12 committed Nov 12, 2024
1 parent e305f48 commit 31bd1f9
Show file tree
Hide file tree
Showing 6 changed files with 436 additions and 92 deletions.
132 changes: 80 additions & 52 deletions yarn-project/simulator/src/avm/journal/journal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
type AztecAddress,
type Gas,
type PublicCallRequest,
SerializableContractInstance,
computePublicBytecodeCommitment,
} from '@aztec/circuits.js';
Expand Down Expand Up @@ -246,7 +245,7 @@ export class AvmPersistableStateManager {
/**
* Accept nested world state modifications
*/
public acceptForkedState(forkedState: AvmPersistableStateManager) {
public mergeForkedState(forkedState: AvmPersistableStateManager) {
this.publicStorage.acceptAndMerge(forkedState.publicStorage);
this.nullifiers.acceptAndMerge(forkedState.nullifiers);
}
Expand Down Expand Up @@ -290,28 +289,23 @@ export class AvmPersistableStateManager {
return undefined;
}
}
/**
* Accept the nested call's state and trace the nested call
*/
public async processNestedCall(

public async traceNestedCall(
forkedState: AvmPersistableStateManager,
nestedEnvironment: AvmExecutionEnvironment,
startGasLeft: Gas,
endGasLeft: Gas,
bytecode: Buffer,
avmCallResults: AvmContractCallResult,
) {
if (!avmCallResults.reverted) {
this.acceptForkedState(forkedState);
}
const functionName = await getPublicFunctionDebugName(
this.worldStateDB,
nestedEnvironment.address,
nestedEnvironment.functionSelector,
nestedEnvironment.calldata,
);

this.log.verbose(`[AVM] Calling nested function ${functionName}`);
this.log.verbose(`[AVM] Tracing nested external contract call ${functionName}`);

this.trace.traceNestedCall(
forkedState.trace,
Expand All @@ -324,46 +318,80 @@ export class AvmPersistableStateManager {
);
}

public async mergeStateForEnqueuedCall(
forkedState: AvmPersistableStateManager,
/** The call request from private that enqueued this call. */
publicCallRequest: PublicCallRequest,
/** The call's calldata */
calldata: Fr[],
/** Did the call revert? */
reverted: boolean,
) {
if (!reverted) {
this.acceptForkedState(forkedState);
}
const functionName = await getPublicFunctionDebugName(
this.worldStateDB,
publicCallRequest.contractAddress,
publicCallRequest.functionSelector,
calldata,
);

this.log.verbose(`[AVM] Encountered enqueued public call starting with function ${functionName}`);

this.trace.traceEnqueuedCall(forkedState.trace, publicCallRequest, calldata, reverted);
}

public mergeStateForPhase(
/** The forked state manager used by app logic */
forkedState: AvmPersistableStateManager,
/** The call requests for each enqueued call in app logic. */
publicCallRequests: PublicCallRequest[],
/** The calldatas for each enqueued call in app logic */
calldatas: Fr[][],
/** Did the any enqueued call in app logic revert? */
reverted: boolean,
) {
if (!reverted) {
this.acceptForkedState(forkedState);
}

this.log.verbose(`[AVM] Encountered app logic phase`);

this.trace.traceExecutionPhase(forkedState.trace, publicCallRequests, calldatas, reverted);
}
///**
// * Accept the nested call's state and trace the nested call
// */
//public async processNestedCall(
// forkedState: AvmPersistableStateManager,
// nestedEnvironment: AvmExecutionEnvironment,
// startGasLeft: Gas,
// endGasLeft: Gas,
// bytecode: Buffer,
// avmCallResults: AvmContractCallResult,
//) {
// if (!avmCallResults.reverted) {
// this.mergeForkedState(forkedState);
// }
// const functionName = await getPublicFunctionDebugName(
// this.worldStateDB,
// nestedEnvironment.address,
// nestedEnvironment.functionSelector,
// nestedEnvironment.calldata,
// );

// this.log.verbose(`[AVM] Calling nested function ${functionName}`);

// this.trace.traceNestedCall(
// forkedState.trace,
// nestedEnvironment,
// startGasLeft,
// endGasLeft,
// bytecode,
// avmCallResults,
// functionName,
// );
//}

//public async mergeStateForEnqueuedCall(
// forkedState: AvmPersistableStateManager,
// /** The call request from private that enqueued this call. */
// publicCallRequest: PublicCallRequest,
// /** The call's calldata */
// calldata: Fr[],
// /** Did the call revert? */
// reverted: boolean,
//) {
// if (!reverted) {
// this.mergeForkedState(forkedState);
// }
// const functionName = await getPublicFunctionDebugName(
// this.worldStateDB,
// publicCallRequest.contractAddress,
// publicCallRequest.functionSelector,
// calldata,
// );

// this.log.verbose(`[AVM] Encountered enqueued public call starting with function ${functionName}`);

// this.trace.traceEnqueuedCall(forkedState.trace, publicCallRequest, calldata, reverted);
//}

//public mergeStateForPhase(
// /** The forked state manager used by app logic */
// forkedState: AvmPersistableStateManager,
// /** The call requests for each enqueued call in app logic. */
// publicCallRequests: PublicCallRequest[],
// /** The calldatas for each enqueued call in app logic */
// calldatas: Fr[][],
// /** Did the any enqueued call in app logic revert? */
// reverted: boolean,
//) {
// if (!reverted) {
// this.mergeForkedState(forkedState);
// }

// this.log.verbose(`[AVM] Encountered app logic phase`);

// this.trace.traceExecutionPhase(forkedState.trace, publicCallRequests, calldatas, reverted);
//}
}
5 changes: 4 additions & 1 deletion yarn-project/simulator/src/avm/opcodes/external_calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ abstract class ExternalCall extends Instruction {
context.machineState.refundGas(gasLeftToGas(nestedContext.machineState));

// Accept the nested call's state and trace the nested call
await context.persistableState.processNestedCall(
if (success) {
context.persistableState.mergeForkedState(nestedContext.persistableState);
}
await context.persistableState.traceNestedCall(
/*nestedState=*/ nestedContext.persistableState,
/*nestedEnvironment=*/ nestedContext.environment,
/*startGasLeft=*/ Gas.from(allocatedGas),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,17 +491,16 @@ describe('Enqueued-call Side Effect Trace', () => {
// parent absorbs child's side effects
const parentSideEffects = trace.getSideEffects();
const childSideEffects = nestedTrace.getSideEffects();
// TODO(dbanks12): confirm that all hints were merged from child
if (callResults.reverted) {
expect(parentSideEffects.publicDataReads).toEqual(childSideEffects.publicDataReads);
expect(parentSideEffects.publicDataWrites).toEqual(childSideEffects.publicDataWrites);
expect(parentSideEffects.noteHashReadRequests).toEqual(childSideEffects.noteHashReadRequests);
expect(parentSideEffects.publicDataReads).toEqual([]);
expect(parentSideEffects.publicDataWrites).toEqual([]);
expect(parentSideEffects.noteHashReadRequests).toEqual([]);
expect(parentSideEffects.noteHashes).toEqual([]);
expect(parentSideEffects.nullifierReadRequests).toEqual(childSideEffects.nullifierReadRequests);
expect(parentSideEffects.nullifierNonExistentReadRequests).toEqual(
childSideEffects.nullifierNonExistentReadRequests,
);
expect(parentSideEffects.nullifiers).toEqual(childSideEffects.nullifiers);
expect(parentSideEffects.l1ToL2MsgReadRequests).toEqual(childSideEffects.l1ToL2MsgReadRequests);
expect(parentSideEffects.nullifierReadRequests).toEqual([]);
expect(parentSideEffects.nullifierNonExistentReadRequests).toEqual([]);
expect(parentSideEffects.nullifiers).toEqual([]);
expect(parentSideEffects.l1ToL2MsgReadRequests).toEqual([]);
expect(parentSideEffects.l2ToL1Msgs).toEqual([]);
expect(parentSideEffects.unencryptedLogs).toEqual([]);
expect(parentSideEffects.unencryptedLogsHashes).toEqual([]);
Expand Down
Loading

0 comments on commit 31bd1f9

Please sign in to comment.