--- tags: Ethereum Protocol Fellowship --- # EPF update 3 TLDR 1. I reviewed [@Vid documents about rust implementation on aa-bundler](https://hackmd.io/@Vid201/aa-bundler-rust) and put some comments. 2. Reviewed [EIP-4337](https://eips.ethereum.org/EIPS/eip-4337) deep again with Vid docs. 3. start to review the [nethermind IL-evm pr](https://github.com/NethermindEth/nethermind/pull/3888) 4. Trying to understand [EVM opcodes](https://www.evm.codes) and [MSIL opcodes](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes?source=recommendations&view=net-7.0) and build relations. Plan Next Week: 1. Figure out pattern compile EVM-opcodes to IL-opcodes 2. Wrote the benchmark for current IL-Evm 3. Discuss with @Vid on my coding task in AA-bundler ## Details ### Details for IL-EVM This week, I start to get myself totally into the IL-EVM pr. I got a good prgress on the c# and dotnet because Microsoft keeps a very good document. I can find almost everything I don't know in their documents. However on the contrary, [MSIL](https://en.wikipedia.org/wiki/MSIL) is a giant beast I need to fight with. I read some basic [doc](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes?source=recommendations&view=net-7.0) from microsoft. The doc contains an [example](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes?source=recommendations&view=net-7.0#examples) how to use IL-generator to define a type and the method of the type. The example seems easy to understand. I tried to tweak around the example. It worked fine. Then I went back to the IL-EVM pr. Currently the most important thing I need to know is 1. How does EVM in nethermind work right now? 2. How is IL-EVM going to fit in nethermind original EVM codes? 3. How to compile evm op-codes to MSIL-op-codes? #### 1. How does evm in nethermind work right now? 1. [TransactionProcessor.cs::`Execute`](https://github.com/NethermindEth/nethermind/blob/1fb723dfb2483d098f8f1a8eb7ae4bef85f3c157/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs#L141) is the main entrypoint of transaction execution. The processor would do a lot of sanity check(like Eip-1559 check, account check, balance check and etc). 2. And it would get the EVM bytescode in [CodeInfo initialize](https://github.com/NethermindEth/nethermind/blob/9bcdf5066dbe10b781cabab1ce6929a6d8b575f2/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs#L344-L346)(This is an important step which is the injection of MSIL compilation). 3. Then EVM would [execute the bytescode against the EVM state](https://github.com/NethermindEth/nethermind/blob/9bcdf5066dbe10b781cabab1ce6929a6d8b575f2/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs#L369). 4. EVM [execute the bytescode](https://github.com/NethermindEth/nethermind/blob/9bcdf5066dbe10b781cabab1ce6929a6d8b575f2/src/Nethermind/Nethermind.Evm/VirtualMachine.cs#L747-L2974) 5. return exception(outOfGas and etc.) or success at the end #### 2. How is IL-EVM going to fit in nethermind original EVM codes? It looks like the [VirtualMachine.cs](https://github.com/NethermindEth/nethermind/blob/1fb723dfb2483d098f8f1a8eb7ae4bef85f3c157/src/Nethermind/Nethermind.Evm/VirtualMachine.cs) made a lot of changes in the IL-EVM pr. But actually, most of the codes are just reformatting the codes. The key codes are just two places. 1. Adding a new [BuildILForNext](https://github.com/NethermindEth/nethermind/blob/1fb723dfb2483d098f8f1a8eb7ae4bef85f3c157/src/Nethermind/Nethermind.Evm/VirtualMachine.cs#L408-L410) flag and the EVM would compile EVN opcodes into IL opcodes when it is `true`. 2. Execute IL-op codes when the [CodeInfo.Data](https://github.com/NethermindEth/nethermind/blob/1fb723dfb2483d098f8f1a8eb7ae4bef85f3c157/src/Nethermind/Nethermind.Evm/VirtualMachine.cs#L665-L670) is ILDelegate. #### 3. How to compile EVM op-codes to MSIL-op-codes? Well, I haven't got a very good answer for this. This is what I am going to do next. Currently, I read [PC Opcode to IL-opcodes from the pr](https://github.com/NethermindEth/nethermind/blob/1fb723dfb2483d098f8f1a8eb7ae4bef85f3c157/src/Nethermind/Nethermind.Evm/IL/ILVirtualMachineBuilder.cs#L122-L137) but I could not really understand why. I am trying that using tools like [ildasm](https://learn.microsoft.com/en-us/dotnet/framework/tools/ildasm-exe-il-disassembler) against some simple codes with GUI [ILSpy](https://github.com/icsharpcode/ILSpy) and try to understand IL-opcodes better. I am also looking for articles like [understand-evm-bytecode-part-1](https://blog.trustlook.com/understand-evm-bytecode-part-1/) could walk me through some easy IL-opcodes. Next week, I would also try to write the benchmark codes for the pr to compare IL-Evm with pure Evm though the pr auther got some benchmark examples. ### Details for Rust AA-Bundler Time spent on this is relatively less. I reviewed @Vid documents about the Rust AA-Bundler. I gave some comments and questions. Vid gave good explaination. Next week, I would try to take some part of the codes to make some pull requests. ## Reading list * [A good post explain POS in eth](https://twitter.com/SalomonCrypto/status/1578540161628971008?s=19) * Microsoft [Common Language Runtime](https://learn.microsoft.com/en-us/dotnet/standard/clr) * [MSIL explains](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes?source=recommendations&view=net-7.0) * [understand-evm-bytecode-part-1](https://blog.trustlook.com/understand-evm-bytecode-part-1/) * [getting-deep-into-evm-how-ethereum-works-backstage](https://medium.com/swlh/getting-deep-into-evm-how-ethereum-works-backstage-ab6ad9c0d0bf) * [managed-execution-process](https://learn.microsoft.com/en-us/dotnet/standard/managed-execution-process)