Skip to content
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

feat: EVM emulator #825

Draft
wants to merge 75 commits into
base: dev
Choose a base branch
from
Draft

feat: EVM emulator #825

wants to merge 75 commits into from

Conversation

0xVolosnikov
Copy link

The main changes are:

  • New EvmGasManager.sol and EvmInterpreter.yul contracts were added.
  • A yarn sc preprocess:interpreter command to preprocess the interpreter from its three template files (EvmInterpreterFunctions.template.yul, EvmInterpereterLoop.template.yul and EvmInterpreter.template.yul)
  • The CodeOracle was updated to handle decommitments of EVM contracts (i.e. the case where the version byte of the code hash is 2).
  • The execute method of the DefaultAccount now checks the second byte to see if the constructor is being called and dispatches it to the createEVM method on the deployer if so.
  • The ContractDeployer has a few more methods required for equivalence:
    • setDeployedCode, used by the interpreter to publish evm bytecodes and store code hashes
    • createEVMInternal and internal functions it calls, used by the interpreter for CREATE opcodes
  • ContractDeployer also now maintains an evmCodeHash mapping of EVM code hashes.
  • AccountCodeStorage now checks for EVM contracts on getCodeHash and queries the mapping above if so.
  • The check done by the bootloader on regular transactions (type 0) that the reserved1 byte should be zero was removed, as it now corresponds to evm contracts.

Moved from: #821

jrchatruc and others added 30 commits August 7, 2024 17:00
IAvecilla and others added 28 commits August 29, 2024 12:22
* Revert fetch deployed code len optimization

* Calculate hashes:fix
* Optimize EvmGasManager

* Fix typo

* Simplify consumeEvmFrame

* Update hashes
* Remove invalid todos adding overflow checks

* Remove old memory check

* Add preprocessed evm interpreter

* Remove unnecesary memory checks

* Update hash for evm interpreter
* Revert consumeEvmFrame EvmGasManager optimization

* Update hashes
* Cleanup EvmInterpreterFunctions

* Cleanup in logs

* Remove unneded changes

* Use rawMimicCall
@0xVolosnikov 0xVolosnikov mentioned this pull request Sep 27, 2024
3 tasks
Copy link

Coverage after merging integration-stable/evm-emulator into dev will be

87.26%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
contracts/bridge
   L1ERC20Bridge.sol81.82%80%75%83.87%62, 70, 70–71, 73–74
   L1SharedBridge.sol79.59%66.23%84.21%83.41%101–102, 109–110, 117–118, 125, 125–126, 133, 177, 190–191, 199–200, 212–213, 215–216, 227, 227, 227–231, 231–232, 234, 239–241, 241–242, 244–246, 246–247, 249, 261, 270, 270–271, 279–280, 290, 444–445, 447–448, 579–580, 596–597, 607–608, 623–624, 720–721, 962, 967
contracts/bridgehub
   Bridgehub.sol89.29%74.07%100%91.49%100–101, 112–113, 132–133, 155–156, 158–159, 332–333, 49, 63–64
contracts/common
   ReentrancyGuard.sol90%66.67%100%92.86%78–79
contracts/common/libraries
   L2ContractHelper.sol42.86%0%50%52.63%25–26, 31–32, 35–36, 50, 52, 52–53, 57, 57–58, 66
   SemVer.sol100%100%100%100%
   UncheckedMath.sol100%100%100%100%
   UnsafeBytes.sol100%100%100%100%
contracts/governance
   AccessControlRestriction.sol100%100%100%100%
   ChainAdmin.sol95.12%80%100%96.15%27–28
   Governance.sol91.67%94.74%95%89.86%45, 45–46, 49, 51–52, 54–55
   PermanentRestriction.sol87.32%78.57%100%87.23%142, 142–143, 146, 148, 148–149, 176–177
contracts/state-transition
   StateTransitionManager.sol59.48%35.71%50%65.42%101, 106–110, 116, 149–150, 152–153, 155–156, 158–159, 201, 203–204, 209, 211, 211–212, 215–217, 219–220, 255, 275, 289, 294, 299, 304, 309, 314, 319, 387, 387–388, 391, 456–457, 79, 92, 92–93
   TestnetVerifier.sol44.44%33.33%50%50%16, 16, 16, 32
   ValidatorTimelock.sol95.89%83.33%100%95.83%241, 82–83
   Verifier.sol89.88%35.71%96.30%90.93%1673–1674, 287–302, 305–308, 311–318, 321–328, 331–332, 335–336, 339, 384–385, 395–396, 406–407, 417–418, 428–429, 444–445, 454, 454–455, 904–905
contracts/state-transition/chain-deps
   DiamondInit.sol78%45.45%100%86.49%34–35, 37–38, 40–41, 43–44, 46–47, 72
   DiamondProxy.sol92.31%75%100%100%16, 27
contracts/state-transition/chain-deps/facets
   Admin.sol86.21%72.73%92.31%87.30%109, 109–110, 112–113, 178, 180, 83–84, 94–95
   Executor.sol82.09%63.41%84.38%87.95%137–138, 192, 197, 202, 207, 212, 217, 222, 227, 230–231, 235–236, 240–242, 244–245, 260–261, 280, 294–295, 361–362, 425, 447–449, 469, 48, 48–49, 519–520, 528–529, 549, 556–557, 57, 59, 59–60, 619, 62, 620, 63, 646–647, 696–697, 70, 700–701, 71, 74–75, 775
   Getters.sol92.38%100%90.70%93.33%147, 216, 77, 82
   Mailbox.sol100%100%100%100%
   ZkSyncHyperchainBase.sol92.86%85.71%100%92.86%55–56
contracts/state-transition/libraries
   Diamond.sol93.33%80.77%100%95.96%109–110, 113, 115, 117, 120, 198–199, 316
   LibMap.sol100%100%100%100%
   Merkle.sol100%100%100%100%
   PriorityQueue.sol100%100%100%100%
   TransactionValidator.sol94.44%88.24%100%96%66–67, 69–70
contracts/upgrades
   BaseZkSyncUpgrade.sol56.72%28%100%58.33%114, 114–115, 118, 121, 124–125, 136, 136, 136, 138, 141, 144–145, 156, 156–157, 160, 163, 166–167, 181–183, 201–203, 248–249, 251, 251–252, 268–269, 285–286, 288–289, 294–295, 295–296, 307–308, 314–315, 321–322, 329–330, 334–335, 344–345, 347–348, 80–81
   BaseZkSyncUpgradeGenesis.sol56.67%14.29%100%68.18%25, 25–26, 33–34, 40–41, 52–53, 62–63, 65–66
   DefaultUpgrade.sol100%100%100%100%
   GenesisUpgrade.sol100%100%100%100%
contracts/vendor
   AddressAliasHelper.sol85.71%75%100%85.71%60, 62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants