I would like to understand how the Ethereum Node is loading the contract bytecode in the EVM and then write everything that it needs, back to the blockchain.
This is how I understand it.
The contract get compiled into bytecode. It's deployed on the chain. When a user call that contract address to run a function. The node loads the contract in the EVM as bytecode. Run the request made by the user. It all happens in the EVM. So how, after execution on the node. does the node Write back the new data on the blockchain?
For example my contract have an empty array.
One of the function to call will add an entry in the array.
The new array contain 1 entry and need to go back on the chain. Does the node pull the data from EVM to recompile and rewrite it? I doubt it works like that since the EVM serve the purpose of running a code in the virtual environment.
My best guess would be that the EVM is actually program to run the bytecode and then rewrite the new content on the blockchain.
Now as per why this question?
I'm trying to repeat the process with the JVM or the V8 engine VM in NodeJS.
Instead of using solidity, I compile Javascript into Bytecode. So this would be my smart-contract like. And it's working. I can load a Javascript in the VM and call the functions and get response back.
Now all this code remains in the VM. And this is where I'm not sure what I would do next.
In my example where a call add an entry in an array. I want to write that new array back to the blockchain and I'm not sure about the approach. Does the Ethereum node make the bridge between EVM and the Blockchain? Or does the node use the EVM and only interact with the EVM that in turns interact with the blockchain?