Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Coinbase CEO bullish on stablecoin bill’s senate fate despite political headwinds

    May 15, 2025

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 2025

    SUI retraces after rally, eyes growth with 21Shares deal

    May 15, 2025
    Facebook X (Twitter) Instagram
    Ai Crypto TimesAi Crypto Times
    • Altcoins
      • Bitcoin
      • Coinbase
      • Litecoin
    • Blockchain
    • Crypto
    • Ethereum
    • Lithosphere News Releases
    X (Twitter) Instagram YouTube LinkedIn
    Ai Crypto TimesAi Crypto Times
    Home » Go Ethereum’s JIT-EVM | Ethereum Foundation Blog

    Go Ethereum’s JIT-EVM | Ethereum Foundation Blog

    Michael JohnsonBy Michael JohnsonMay 1, 2025No Comments5 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    The Ethereum Virtual machine is kind of different than most other Virtual Machines out there. In my previous post I already explained how it’s used and described some of its characteristics.

    The Ethereum Virtual Machine (EVM) is a simple but powerful, Turing complete 256bit Virtual Machine that allows anyone to execute arbitrary EVM Byte Code.

    The go-ethereum project contains two implementations of the EVM. A simple and straightforward byte-code VM and a more sophisticated JIT-VM. In this post I’m going to explain some of the differences between the two implementations and describe some of the characteristics of the JIT EVM and why it can be so much faster than the byte-code EVM.

    Go-ethereum’s Byte Code Virtual Machine

    The EVM’s internals are pretty simple; it has a single run loop which will attempt to execute the instruction at the current Program Counter (PC in short). Within this loop the Gas is calculated for each instruction, memory is expanded if necessary and executes the instruction if the preamble succeeds. This will continue on until the VM either finishes gracefully or returns with an error by throwing an exception (e.g. out-of-gas).

    for op = contract[pc] {

        if !sufficientGas(op) {

            return error("insufficient gas for op:", or)

        }
    
        switch op {

        case ...:

            /* execute */

        case RETURN:

            return memory[stack[-1], stack[-2]]

        }

        pc++

    }
    

    At the end of the execution loop the program-counter gets increment to run the next instruction and continues to do so until it has finished.

    The EVM has another way to change the program-counter through something called jump-instructions (JUMP & JUMPI). Instead of letting the program-counter increment (pc++) the EVM can also jump to arbitrary positions in the contract code. The EVM knows two jump instructions, a normal jump that reads as “jump to position X” and a conditional jump that read as “jump to position X if condition Y is true”. When either such a jump occurs it must always land on a jump-destination. If the program lands on an instruction other than a jump destination the program fails — in other words, for a jump to be valid it must always be followed by a jump-destination instruction if the condition yielded true.

    Prior to running any Ethereum program the EVM iterates over the code and finds all possible jump-destinations, it then puts them in a map that can be referenced by the program-counter to find them. Each and every time the EVM encounters a jump-instructions the jump validity is checked.

    As you can see the executing code is relatively easy and simply interpreted by the byte-code VM, we may conclude even that through its sheer simplicity it’s actually pretty dumb.

    Welcome JIT VM

    The JIT-EVM takes a different approach to running EVM byte-code and is by definition initially slower than the byte-code VM. Before the VM can run any code it must first compile the byte-code in to components that can be understood by the JIT VM.

    The initialisation- and execution procedure is done in 3-steps:

    1. We check whether there’s a JIT program ready to be run using the hash of the code — H(C) is used as an identifier to identify the program;
    2. if a program was found we run the program and return the result;
    3. if no program was found we run the byte-code and we compile a JIT program in the background.

    Initially I tried to check whether the JIT program had finished compiling and move the execution over to the JIT — this all happened during runtime in the same loop using Go’s atomic package — unfortunately it turned out to be slower than letting the byte-code VM run and use the JIT program for every sequential call after the compilation of the program had finished.

    By compiling the byte-code in to logical pieces the JIT has the ability to analyse the code more precisely and optimise where and whenever necessary.

    For example an incredible simple optimisation that I did was compiling several push operation in to a single instruction. Let’s take the CALL instruction; call requires 7 push instructions — i.e. gas, address, value, input-offset, input-size, return-offset and return-size — prior to executing it, and what I did instead of looping through these 7 instructions, executing them one by one, I’ve optimised this away by taking the 7 instructions and append the 7 values in to a single slice. Now, whenever the start of the 7 push instructions is executed, it instead executes the one optimised instruction by immediately appending the static slice to the VM stack. Now of course this only works for static values (i.e. push 0x10), but these are present in the code quite a lot.

    I’ve also optimised the static jump instructions. Static jumps are jumps who always jump to the same position (i.e. push 0x1, jump) and never change under any circumstance. By determining which jumps are static we can pre-check whether a jump is valid and lies within the bounds of the contract and if so we create a new instructions that replaces both the push and jumpinstruction and is flagged as valid. This prevents the VM from having to do two instructions and it prevents it from having to check whether the jump is valid and doing an expensive hash-map lookup for valid jump position.

    Next steps

    Full stack and memory analysis would also fit nicely in this model where large chunks of code could fit in to single instructions. Further I’d like to add symbolic-execution and turn the JIT in to a proper JIT-VM. I think this would be a logical next step once programs get large enough to take advantage of these optimisations.

    Conclusion

    Our JIT-VM is a whole lot smarter than the byte-code VM, but is far from being completely done (if ever). There are many more clever tricks we could add with this structure, but simply aren’t realistic for the moment. The runtime is within the bounds of being “reasonable” speedy. May the need arise to further optimise the VM we have the tools to do so.

    Further code-reading


    Cross posted from – https://medium.com/@jeff.ethereum/go-ethereums-jit-evm-27ef88277520#.1ed9lj7dz



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Michael Johnson

    Related Posts

    Bitwise CIO bats for diversified crypto investment, compares Bitcoin to Google

    May 14, 2025

    V1.0 Announcing the Trillion Dollar Security Initiative

    May 14, 2025

    Ethereum (ETH) sees major uptick as Pectra upgrade goes live

    May 8, 2025
    Leave A Reply Cancel Reply

    Don't Miss

    Coinbase CEO bullish on stablecoin bill’s senate fate despite political headwinds

    Coinbase May 15, 2025

    Coinbase CEO is “optimistic” about Senate passing stablecoin legislation soon, despite recent setbacks. A key…

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 2025

    SUI retraces after rally, eyes growth with 21Shares deal

    May 15, 2025

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 2025
    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo
    Our Picks

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 2025

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 2025

    Colle AI Expands XRP Cryptocurrency Use to Power NFT Interoperability

    May 15, 2025

    Atua AI Elevates Bitcoin Infrastructure to Enhance AI Workflow Security

    May 15, 2025

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    Demo
    • Popular
    • Recent
    • Top Reviews

    5 Simple Tips to Take Care of Larger Air Balloons

    January 4, 2020

    Chinese Business Leaders Call for International Cooperation

    January 4, 2020

    5 Ways Your Passport Can Ruin Your Cool Holiday Trip

    January 5, 2020

    Coinbase CEO bullish on stablecoin bill’s senate fate despite political headwinds

    May 15, 2025

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 2025

    SUI retraces after rally, eyes growth with 21Shares deal

    May 15, 2025
    9.3

    Facilisis tincidunt justo eget urna leo dapibus at

    December 19, 2020
    8.9

    Review: Denmark Proposes Corona Pass Mandate for Workers

    January 9, 2020
    8.9

    Laoreet Sed: Suscipit nec dapibus at elit

    December 19, 2020
    Latest Galleries
    [latest_gallery cat="all" number="5" type="slider"]
    Latest Reviews
    8.5

    Review: How Research Could Help with Spinal Cord Injuries

    March 14, 2021
    8.9

    Review: How AI in Soccer could Predict Injuries?

    January 15, 2021
    8.9

    Review: Can Wisconsin Clinch the Big Ten West this Weekend

    January 15, 2021
    Demo
    Top Posts

    Atua AI Extends Bitcoin-Backed Infrastructure for Intelligent Enterprise Operations

    April 23, 202513 Views

    AGII Launches AI-Powered Web3 App To Advance Real-Time Decentralized Infrastructure

    April 26, 20251 Views

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 20250 Views

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 20250 Views
    Don't Miss

    Coinbase CEO bullish on stablecoin bill’s senate fate despite political headwinds

    Coinbase May 15, 2025

    Coinbase CEO is “optimistic” about Senate passing stablecoin legislation soon, despite recent setbacks. A key…

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 2025

    SUI retraces after rally, eyes growth with 21Shares deal

    May 15, 2025

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 2025
    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    Demo
    Top Posts

    Atua AI Extends Bitcoin-Backed Infrastructure for Intelligent Enterprise Operations

    April 23, 202513 Views

    AGII Launches AI-Powered Web3 App To Advance Real-Time Decentralized Infrastructure

    April 26, 20251 Views

    Coinbase CEO bullish on stablecoin bill’s senate fate despite political headwinds

    May 15, 20250 Views

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 20250 Views
    Don't Miss

    Coinbase CEO bullish on stablecoin bill’s senate fate despite political headwinds

    Coinbase May 15, 2025

    Coinbase CEO is “optimistic” about Senate passing stablecoin legislation soon, despite recent setbacks. A key…

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 2025

    SUI retraces after rally, eyes growth with 21Shares deal

    May 15, 2025

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 2025
    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    X (Twitter) Instagram YouTube LinkedIn
    Our Picks

    Coinbase CEO bullish on stablecoin bill’s senate fate despite political headwinds

    May 15, 2025

    AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience

    May 15, 2025

    SUI retraces after rally, eyes growth with 21Shares deal

    May 15, 2025
    Recent Posts
    • Coinbase CEO bullish on stablecoin bill’s senate fate despite political headwinds
    • AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience
    • SUI retraces after rally, eyes growth with 21Shares deal
    • AGII Deploys Smart Detection Models for On-Chain Infrastructure Resilience
    • Colle AI Expands XRP Cryptocurrency Use to Power NFT Interoperability
    © 2025 - 2026

    Type above and press Enter to search. Press Esc to cancel.