-
Notifications
You must be signed in to change notification settings - Fork 615
fix: Unrevert "feat: trace AVM side effects per enqueued call"" #9095
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
Merged
dbanks12
merged 2 commits into
master
from
revert-9058-revert-8918-db/previous-lengths-in-avm-trace
Oct 8, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
yarn-project/simulator/src/public/dual_side_effect_trace.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| import { type CombinedConstantData, type Gas, type VMCircuitPublicInputs } from '@aztec/circuits.js'; | ||
| import { type Fr } from '@aztec/foundation/fields'; | ||
| import { type ContractInstanceWithAddress } from '@aztec/types/contracts'; | ||
|
|
||
| import { assert } from 'console'; | ||
|
|
||
| import { type AvmContractCallResult } from '../avm/avm_contract_call_result.js'; | ||
| import { type AvmExecutionEnvironment } from '../avm/avm_execution_environment.js'; | ||
| import { type PublicEnqueuedCallSideEffectTrace } from './enqueued_call_side_effect_trace.js'; | ||
| import { type PublicExecutionResult } from './execution.js'; | ||
| import { type PublicSideEffectTrace } from './side_effect_trace.js'; | ||
| import { type PublicSideEffectTraceInterface } from './side_effect_trace_interface.js'; | ||
|
|
||
| export type TracedContractInstance = { exists: boolean } & ContractInstanceWithAddress; | ||
|
|
||
| export class DualSideEffectTrace implements PublicSideEffectTraceInterface { | ||
| constructor( | ||
| public readonly innerCallTrace: PublicSideEffectTrace, | ||
| public readonly enqueuedCallTrace: PublicEnqueuedCallSideEffectTrace, | ||
| ) {} | ||
|
|
||
| public fork() { | ||
| return new DualSideEffectTrace(this.innerCallTrace.fork(), this.enqueuedCallTrace.fork()); | ||
| } | ||
|
|
||
| public getCounter() { | ||
| assert(this.innerCallTrace.getCounter() == this.enqueuedCallTrace.getCounter()); | ||
| return this.innerCallTrace.getCounter(); | ||
| } | ||
|
|
||
| public tracePublicStorageRead(storageAddress: Fr, slot: Fr, value: Fr, exists: boolean, cached: boolean) { | ||
| this.innerCallTrace.tracePublicStorageRead(storageAddress, slot, value, exists, cached); | ||
| this.enqueuedCallTrace.tracePublicStorageRead(storageAddress, slot, value, exists, cached); | ||
| } | ||
|
|
||
| public tracePublicStorageWrite(storageAddress: Fr, slot: Fr, value: Fr) { | ||
| this.innerCallTrace.tracePublicStorageWrite(storageAddress, slot, value); | ||
| this.enqueuedCallTrace.tracePublicStorageWrite(storageAddress, slot, value); | ||
| } | ||
|
|
||
| // TODO(8287): _exists can be removed once we have the vm properly handling the equality check | ||
| public traceNoteHashCheck(_storageAddress: Fr, noteHash: Fr, leafIndex: Fr, exists: boolean) { | ||
| this.innerCallTrace.traceNoteHashCheck(_storageAddress, noteHash, leafIndex, exists); | ||
| this.enqueuedCallTrace.traceNoteHashCheck(_storageAddress, noteHash, leafIndex, exists); | ||
| } | ||
|
|
||
| public traceNewNoteHash(_storageAddress: Fr, noteHash: Fr) { | ||
| this.innerCallTrace.traceNewNoteHash(_storageAddress, noteHash); | ||
| this.enqueuedCallTrace.traceNewNoteHash(_storageAddress, noteHash); | ||
| } | ||
|
|
||
| public traceNullifierCheck(storageAddress: Fr, nullifier: Fr, leafIndex: Fr, exists: boolean, isPending: boolean) { | ||
| this.innerCallTrace.traceNullifierCheck(storageAddress, nullifier, leafIndex, exists, isPending); | ||
| this.enqueuedCallTrace.traceNullifierCheck(storageAddress, nullifier, leafIndex, exists, isPending); | ||
| } | ||
|
|
||
| public traceNewNullifier(storageAddress: Fr, nullifier: Fr) { | ||
| this.innerCallTrace.traceNewNullifier(storageAddress, nullifier); | ||
| this.enqueuedCallTrace.traceNewNullifier(storageAddress, nullifier); | ||
| } | ||
|
|
||
| public traceL1ToL2MessageCheck(contractAddress: Fr, msgHash: Fr, msgLeafIndex: Fr, exists: boolean) { | ||
| this.innerCallTrace.traceL1ToL2MessageCheck(contractAddress, msgHash, msgLeafIndex, exists); | ||
| this.enqueuedCallTrace.traceL1ToL2MessageCheck(contractAddress, msgHash, msgLeafIndex, exists); | ||
| } | ||
|
|
||
| public traceNewL2ToL1Message(contractAddress: Fr, recipient: Fr, content: Fr) { | ||
| this.innerCallTrace.traceNewL2ToL1Message(contractAddress, recipient, content); | ||
| this.enqueuedCallTrace.traceNewL2ToL1Message(contractAddress, recipient, content); | ||
| } | ||
|
|
||
| public traceUnencryptedLog(contractAddress: Fr, log: Fr[]) { | ||
| this.innerCallTrace.traceUnencryptedLog(contractAddress, log); | ||
| this.enqueuedCallTrace.traceUnencryptedLog(contractAddress, log); | ||
| } | ||
|
|
||
| public traceGetContractInstance(instance: TracedContractInstance) { | ||
| this.innerCallTrace.traceGetContractInstance(instance); | ||
| this.enqueuedCallTrace.traceGetContractInstance(instance); | ||
| } | ||
|
|
||
| /** | ||
| * Trace a nested call. | ||
| * Accept some results from a finished nested call's trace into this one. | ||
| */ | ||
| public traceNestedCall( | ||
| /** The trace of the nested call. */ | ||
| nestedCallTrace: this, | ||
| /** The execution environment of the nested call. */ | ||
| nestedEnvironment: AvmExecutionEnvironment, | ||
| /** How much gas was available for this public execution. */ | ||
| startGasLeft: Gas, | ||
| /** How much gas was left after this public execution. */ | ||
| endGasLeft: Gas, | ||
| /** Bytecode used for this execution. */ | ||
| bytecode: Buffer, | ||
| /** The call's results */ | ||
| avmCallResults: AvmContractCallResult, | ||
| /** Function name for logging */ | ||
| functionName: string = 'unknown', | ||
| ) { | ||
| this.innerCallTrace.traceNestedCall( | ||
| nestedCallTrace.innerCallTrace, | ||
| nestedEnvironment, | ||
| startGasLeft, | ||
| endGasLeft, | ||
| bytecode, | ||
| avmCallResults, | ||
| functionName, | ||
| ); | ||
| this.enqueuedCallTrace.traceNestedCall( | ||
| nestedCallTrace.enqueuedCallTrace, | ||
| nestedEnvironment, | ||
| startGasLeft, | ||
| endGasLeft, | ||
| bytecode, | ||
| avmCallResults, | ||
| functionName, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Convert this trace to a PublicExecutionResult for use externally to the simulator. | ||
| */ | ||
| public toPublicExecutionResult( | ||
| /** The execution environment of the nested call. */ | ||
| avmEnvironment: AvmExecutionEnvironment, | ||
| /** How much gas was available for this public execution. */ | ||
| startGasLeft: Gas, | ||
| /** How much gas was left after this public execution. */ | ||
| endGasLeft: Gas, | ||
| /** Bytecode used for this execution. */ | ||
| bytecode: Buffer, | ||
| /** The call's results */ | ||
| avmCallResults: AvmContractCallResult, | ||
| /** Function name for logging */ | ||
| functionName: string = 'unknown', | ||
| ): PublicExecutionResult { | ||
| return this.innerCallTrace.toPublicExecutionResult( | ||
| avmEnvironment, | ||
| startGasLeft, | ||
| endGasLeft, | ||
| bytecode, | ||
| avmCallResults, | ||
| functionName, | ||
| ); | ||
| } | ||
|
|
||
| public toVMCircuitPublicInputs( | ||
| /** Constants */ | ||
| constants: CombinedConstantData, | ||
| /** The execution environment of the nested call. */ | ||
| avmEnvironment: AvmExecutionEnvironment, | ||
| /** How much gas was available for this public execution. */ | ||
| startGasLeft: Gas, | ||
| /** How much gas was left after this public execution. */ | ||
| endGasLeft: Gas, | ||
| /** The call's results */ | ||
| avmCallResults: AvmContractCallResult, | ||
| ): VMCircuitPublicInputs { | ||
| return this.enqueuedCallTrace.toVMCircuitPublicInputs( | ||
| constants, | ||
| avmEnvironment, | ||
| startGasLeft, | ||
| endGasLeft, | ||
| avmCallResults, | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW could you check if this header is actually used? I recall Sean removed _some_ header in https://github.com//pull/8990
See this comment inline on Graphite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used in the public kernel. Leila is working on flattening our VM circuit public inputs struct so it doesn't reuse kernel structs that have fields in them unused by the VM. That being said, this header might be where the AVM gets its tree roots from?