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 10, 2024
1 parent 2e13938 commit 34df1bd
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use dep::types::{
KernelCircuitPublicInputs,
merkle_tree::MembershipWitness,
partial_state_reference::PartialStateReference,
utils::arrays::array_merge,
utils::arrays::{array_merge, dedupe_array},
};

pub struct PublicBaseRollupInputs {
Expand Down Expand Up @@ -85,7 +85,7 @@ impl PublicBaseRollupInputs {
note_encrypted_log_preimages_length,
encrypted_log_preimages_length,
unencrypted_log_preimages_length,
public_data_writes: from_public.accumulated_data.public_data_writes,
public_data_writes: dedupe_array(from_public.accumulated_data.public_data_writes),
gas_used: Gas::empty(), // gas_used is not used in rollup circuits.
};

Expand Down
14 changes: 7 additions & 7 deletions yarn-project/protocol-contracts/src/protocol_contract_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ export const ProtocolContractAddress: Record<ProtocolContractName, AztecAddress>
};

export const ProtocolContractLeaf = {
AuthRegistry: Fr.fromString('0x0931f3bf89563f3898ae9650851083cd560ad800c2e3c561c3853eec4dd7ea8b'),
ContractInstanceDeployer: Fr.fromString('0x266ea4c9917455daa905c1dd1a10753714c6d0369b6f2fe23feeca6de556d164'),
ContractClassRegisterer: Fr.fromString('0x1ccb7a219f72a851089e956d527997b01068d5a28c9ae96b35ebeb45f068af23'),
MultiCallEntrypoint: Fr.fromString('0x1d060217817cf472a579638db722903fd1bbc4c3bdb0ecefa5694c0d4eed851a'),
FeeJuice: Fr.fromString('0x1dab5b687d0c04d2f17a1c8623dea23e7416700891ba1c6e0e86ef678f4727cb'),
Router: Fr.fromString('0x00827d5a8aedb9627d9e5de04735600a4dbb817d4a2f51281aab991699f5de99'),
AuthRegistry: Fr.fromString('0x295f52c40413b660d817ceea60d07154322a035d28d18927b2ca84e8ec3b2115'),
ContractInstanceDeployer: Fr.fromString('0x01314b6c482a9d8f5418cd0d43c17a1c5899ae7c2e1d2f82817baaf3f3b45bd9'),
ContractClassRegisterer: Fr.fromString('0x1d591819cccc4031cc18a7865321c54f6344ae42a205782874d1f72648df2034'),
MultiCallEntrypoint: Fr.fromString('0x20a2e7e882045d27b3aa9e36188b8e45483b3c11652d4a46406699e5eb4efa9b'),
FeeJuice: Fr.fromString('0x14c62d13cca830462ea77bb787878cca3fb8fbb44ffe4d1662c5ffdf98889d5b'),
Router: Fr.fromString('0x05fa1b40b9addbd853af7577676ad31b8b4472eb15c0ac30e784b65b66c40172'),
};

export const protocolContractTreeRoot = Fr.fromString(
'0x0f174f6837842b1004a9a41dd736800c12c5dc19f206aed35551b07f8ca6edfb',
'0x071b3ac4cc5d42228920bcbba6674d93eb77694a085ed413806fdfcf8a50b0b0',
);
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 {
AztecAddress,
type Gas,
type PublicCallRequest,
SerializableContractInstance,
computePublicBytecodeCommitment,
} from '@aztec/circuits.js';
Expand Down Expand Up @@ -242,7 +241,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 @@ -286,28 +285,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 @@ -320,46 +314,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 @@ -486,17 +486,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 34df1bd

Please sign in to comment.