-
Notifications
You must be signed in to change notification settings - Fork 323
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
chore(avm-simulator): refactor of AVM Simulator to more closely match YP #4407
Conversation
Benchmark resultsMetrics with a significant change:
Detailed resultsAll benchmarks are run on txs on the This benchmark source data is available in JSON format on S3 here. Values are compared against data from master at commit L2 block published to L1Each column represents the number of txs on an L2 block published to L1.
L2 chain processingEach column represents the number of blocks on the L2 chain where each block has 16 txs.
Circuits statsStats on running time and I/O sizes collected for every circuit run across all benchmarks.
Tree insertion statsThe duration to insert a fixed batch of leaves into each tree type.
MiscellaneousTransaction sizes based on how many contracts are deployed in the tx.
Transaction processing duration by data writes.
|
*/ | ||
export class AvmContext { | ||
/** Contains constant variables provided by the kernel */ | ||
private executionEnvironment: AvmExecutionEnvironment; | ||
public environment: AvmExecutionEnvironment = initExecutionEnvironment(); |
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.
I think you don't want initExecutionEnvironment
here since you have it in the constructor.
import { AvmMachineState, InitialAvmMachineState } from './avm_machine_state.js'; | ||
import { AvmContractCallResults } from './avm_message_call_result.js'; | ||
import { AvmExecutionError, InvalidProgramCounterError, NoBytecodeForContractError } from './errors.js'; | ||
import { initExecutionEnvironment, initInitialMachineState } from './fixtures/index.js'; |
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.
It seems wrong to include test fixture code in non-test code. Do you really need these inits?
this.executionEnvironment.address, | ||
selector, | ||
); | ||
setInstructions(instructions: Instruction[]) { |
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 feels strange. Consider having an execute()
that calls another (public) execute(Instruction[])
instead.
const newExecutionEnvironment = parentEnvironment.deriveEnvironmentForNestedCall(address, calldata); | ||
const forkedState = parentWorldState.fork(); | ||
const nestedContext = new AvmContext(forkedState, newExecutionEnvironment, initialMachineState); | ||
await nestedContext.fetchAndDecodeBytecode(); |
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.
Why do you want to do the fetching and decoding here (turning this into async) if execute already does it? It feels more natural to have it in execute and then you can even avoid storing the instructions in the class, you just use them on the spot.
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.
I like having execute
take AvmContext
, however I think what makes the most sense is for AvmContext
to not handle calls etc and only be a structure (forking/etc is ok). I'll try to come up with a proposal but in any case we can talk about this :)
|
||
const avmContext = AvmContext.prepExternalCallContext( | ||
const nestedContext = await AvmContext.createNestedContractCallContext( |
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.
Observe that if you add Call and StaticCall to the instruction set, this use of AvmContext still creates the dependency loop. Also note that this could just be a non-static method and it would make a lot of sense.
With those changes, then you can import AvmContext as type only, and then the loop "disappears".
Replaced by #4424 |
No description provided.