How the AppLayer ecosystem manages the blockchain state alongside an EVM.
The VM itself is owned and instantiated by the State class, which reflects a crucial design decision: centralizing virtual machine resource management like this ensures that each contract execution context is cleanly managed and isolated. Whenever a new transaction or contract call needs to be executed, regardless of its nature (be it an EVM/C++ contract execution or a simple native transfer), the State class is responsible for instantiating a new ContractHost object with the relevant parameters required for execution:
Once an instance of ContractHost is created, it offers methods like execute() to run the contract, simulate() for simulating the transaction (useful for gas estimation), and ethCallView() for making calls to other contracts within a non-state-changing context.
ContractHost also extends the functionalities of evmc::Host by overriding several key functions that interface directly with the Ethereum Virtual Machine, which are obligatory for the VM to interact with the State:
These methods manage everything from account validation to logging, providing access to the state and storage, and handling calls between contracts. The ContractHost class encapsulates these functions, ensuring that each contract execution is isolated and secure.