Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
LABS
Guides

How to Prepare for EVM Opcode Changes

A technical guide for developers to audit, test, and upgrade smart contracts in response to EVM hard forks. Covers impact analysis, testing strategies, and deployment best practices.
Chainscore © 2026
introduction
DEVELOPER GUIDE

How to Prepare for EVM Opcode Changes

A practical guide for smart contract developers on assessing and mitigating the impact of upcoming Ethereum Virtual Machine (EVM) opcode modifications.

The Ethereum Virtual Machine (EVM) is not static. Core protocol upgrades, like the Shanghai, Cancun, and upcoming Pectra hard forks, frequently introduce, deprecate, or modify low-level opcodes. These changes can have subtle but significant effects on smart contract behavior, gas costs, and security. For developers, proactively preparing for these changes is essential to maintain contract reliability, optimize performance, and avoid unexpected failures post-upgrade. This guide outlines a systematic approach to audit, test, and adapt your codebase.

Your first step is to conduct a comprehensive audit of your codebase for vulnerable patterns. Focus on inline assembly (assembly { ... }) and low-level calls (e.g., delegatecall, staticcall), as these directly interact with opcodes. Use static analysis tools like Slither or Mythril to flag usage of opcodes slated for change. For instance, the EIP-1153 introduction of transient storage opcodes (TLOAD/TSTORE) or the EIP-7623 adjustment to calldata gas costs requires you to review contracts performing complex calldata operations. Manually inspect any custom Yul code or compiler-generated bytecode for dependencies on specific gas costs or opcode semantics.

Once potential impact areas are identified, rigorous testing is non-negotiable. Set up a local development environment using a client like Geth or Nethermind configured for the upcoming fork. Tools like Hardhat or Foundry allow you to fork the mainnet at a future block height simulating the new rules. Write targeted tests that execute the vulnerable code paths you identified. For example, if a change affects the SELFDESTRUCT opcode (as per EIP-6780), create tests that trigger contract self-destruction and verify the new behavior and state changes. Compare gas usage reports before and after the opcode change to anticipate cost increases for your users.

For critical protocol upgrades, consider implementing versioning or upgradeability patterns. Using a proxy pattern like the Transparent Proxy or UUPS allows you to deploy a new logic contract that is compatible with the post-upgrade EVM. However, this is only suitable for contracts designed with upgradeability in mind. For immutable contracts, you may need to deploy a new, migrated version and create a user migration path. Always document the specific EVM fork and opcode set your contract is validated against in your code comments and documentation, such as // Compatible with EVM version: Shanghai.

Finally, integrate continuous monitoring into your development workflow. Subscribe to Ethereum Improvement Proposal (EIP) repositories and core developer calls to stay informed about proposed changes long before they are scheduled. Automate checks in your CI/CD pipeline using tools that can parse the latest compiler (solc) release notes for EVM target changes. By treating the EVM as a moving target and embedding preparedness into your development lifecycle, you ensure your smart contracts remain secure, efficient, and functional through every network upgrade.

prerequisites
PREREQUISITES

How to Prepare for EVM Opcode Changes

A guide for developers to understand and adapt to upcoming changes in the Ethereum Virtual Machine's instruction set.

The Ethereum Virtual Machine (EVM) is the deterministic state machine that executes all smart contract code on Ethereum and compatible Layer 2 networks. Its instruction set, comprised of opcodes like PUSH, SLOAD, and CALL, defines the fundamental operations available to developers. Periodically, Ethereum Improvement Proposals (EIPs) introduce changes to these opcodes to enhance security, efficiency, or introduce new functionality. Staying ahead of these changes is critical for maintaining the security and performance of your deployed contracts and development tooling.

To effectively prepare, you must first understand the EIP lifecycle. Proposals like EIP-2929 (increasing gas costs for state-accessing opcodes) or EIP-1153 (introducing transient storage opcodes TLOAD/TSTORE) begin as drafts, move to review, and are finally scheduled for inclusion in a specific network upgrade (e.g., Shanghai, Cancun). Monitor resources like the Ethereum Magicians forum, the official EIPs repository, and client team announcements (Geth, Nethermind, Erigon) to track proposals that will impact your stack.

Your development and testing environment must be version-locked and upgradeable. Use specific versions of compilers (solc), testing frameworks (Hardhat, Foundry), and local nodes (Anvil, Hardhat Network). For example, when PUSH0 (EIP-3855) was introduced, Solidity v0.8.20 began utilizing it for more efficient bytecode. To test, you need a local EVM instance that supports the Cancun fork rules. Foundry allows you to specify the fork with --evm-version cancun, while Hardhat can be configured via the hardhat.config.js network settings.

Conduct a gas and behavioral analysis of your existing contracts. Opcode changes often modify gas costs, which can break assumptions in gas-sensitive code like loops or batch operations. Use tools like eth-gas-reporter or Foundry's forge snapshot --diff to profile gas usage before and after simulating the new EVM rules. Furthermore, some changes alter opcode semantics; for instance, EIP-6780 restricted the SELFDESTRUCT opcode's functionality. Audit your contracts for reliance on deprecated behaviors.

Finally, integrate continuous testing against development forks of upcoming networks. Services like Tenderly Forks or Alchemy's Supernode allow you to spin up a chain state with specific fork rules applied. Automate your test suite to run against these forks, ensuring your contracts, front-end gas estimates, and off-chain services (indexers, bots) behave correctly. Proactive preparation transforms a potential network upgrade crisis into a routine deployment check.

key-concepts-text
DEVELOPER GUIDE

How to Prepare for EVM Opcode Changes

EVM upgrades introduce new opcodes and deprecate old ones, requiring proactive changes to smart contracts and development tooling. This guide outlines a systematic approach for developers to ensure compatibility.

EVM opcode changes, such as those introduced in the Shanghai (EIP-3855: PUSH0) or London (EIP-2929: gas cost increases) hard forks, directly impact contract execution and gas economics. To prepare, developers must first audit their dependency chain. This includes reviewing not only your own contracts but also imported libraries (like OpenZeppelin), oracles, and any delegate-called logic. Use tools like solc with the correct EVM version flag (--evm-version) to compile and identify opcodes that may have altered gas costs or are no longer valid on the target network.

Integrate upgrade testing into your CI/CD pipeline. Forge and Hardhat allow you to fork a blockchain at a specific block number. Simulate your contract's core functions on a forked network after the upgrade block to test for behavioral changes and gas usage spikes. For example, after EIP-2929, SLOAD and CALL opcodes became more expensive for first-time access, which could break assumptions in gas-efficient patterns. Proactively testing these scenarios prevents post-upgrade failures and unexpected gas costs for users.

Monitor and update your development tooling. Your compiler version, testing frameworks, debuggers, and gas estimators must be compatible with the new EVM rules. For instance, the introduction of the PUSH0 opcode (EIP-3855) required Solidity compiler version 0.8.20 or later for generation. Similarly, ensure your gas profiling tools (e.g., Hardhat's gas-reporter) use updated opcode tables to provide accurate estimates. Relying on outdated tooling can lead to deploying contracts with suboptimal bytecode or incorrect gas predictions.

For critical protocol deployments, consider implementing upgradeable proxies or emergency pause mechanisms controlled by a multisig or DAO. This provides a safety net if an unforeseen opcode interaction causes a vulnerability or malfunction post-upgrade. However, upgradeability adds complexity; always weigh the trade-offs against the benefits of immutable, trust-minimized contracts. The best preparation combines rigorous pre-fork testing with a clear, executable post-upgrade monitoring and response plan.

POST-LONDON & SHANGHAI UPGRADES

Recent EVM Opcode Changes and Impact

Key opcode behavior modifications, their primary purpose, and impact on contract gas costs and execution.

OpcodeChange IntroducedPurpose / EffectGas Cost Impact

BASEFEE (0x48)

London (EIP-1559)

Returns base fee of the block it executes in. Enables fee market logic.

+~5-10 gas (static)

SELFBALANCE (0x47)

Istanbul (EIP-1884)

Replaces BALANCE for the contract's own balance. More gas-efficient.

Reduced from 700 to 100 gas

CHAINID (0x46)

Istanbul (EIP-1344)

Returns current chain's EIP-155 unique ID. Critical for replay protection.

+~5 gas (static)

EXTCODEHASH (0x3F)

Istanbul (EIP-1052)

Returns keccak256 hash of a contract's bytecode. Optimizes state checks.

Reduced vs. full EXTCODECOPY

BALANCE, EXTCODESIZE, EXTCODECOPY

Istanbul (EIP-1884)

Gas cost increased due to state size growth. Mitigates denial-of-service risks.

Increased from 400 to 700 gas

SLOAD

Berlin (EIP-2929) & London

First access costs 2100 gas (cold), subsequent 100 gas (warm). Introduces access lists.

Variable: +100 to +1900 gas

CALL, CALLCODE, DELEGATECALL, STATICCALL, EXTCODESIZE, EXTCODECOPY, BALANCE, SELFDESTRUCT

Berlin (EIP-2929)

First access to an address costs 2600 gas (cold), subsequent 100 gas (warm).

Variable: +100 to +2500 gas

SELFDESTRUCT

Shanghai/Cancun (EIP-6780)

Opcode behavior restricted. Only works if called in same transaction as contract creation.

Gas refund removed (EIP-3529), behavior changed

step-1-impact-analysis
EVM UPGRADES

Step 1: Analyze Contract Impact

Before an Ethereum hard fork, developers must assess how new or modified EVM opcodes affect their smart contracts. This analysis is critical for preventing unexpected behavior, gas cost increases, or security vulnerabilities post-upgrade.

The first step is to identify all contracts in your protocol that could be impacted. Focus on contracts performing low-level operations using assembly {} blocks or the delegatecall pattern, as these directly interact with EVM instructions. Use tools like Ethers.js or Hardhat to compile a complete inventory. For widely used libraries (e.g., OpenZeppelin's Address or Arrays), check the provider's upgrade notes, but also verify your specific implementation. A contract calling SELFDESTRUCT or using precise gas calculations with GAS is a high-priority candidate for review.

Next, analyze the specific opcode changes. For example, the EIP-1153: Transient Storage opcodes (TLOAD/TSTORE) introduced new functionality, while EIP-2929 increased gas costs for certain state-access opcodes like SLOAD and CALL. Compare the pre- and post-fork gas tables from the official Ethereum EIP repository. Manually review your contract's assembly or use static analysis tools to flag opcode usage. A contract performing many SLOAD operations in a loop may see a significant gas cost increase, potentially breaking user transactions that were previously viable.

Finally, simulate and test the changes. Fork the mainnet state at the upcoming block height using a development environment like Hardhat or Foundry. Execute your contract's critical functions and benchmark gas consumption and output correctness against the pre-fork behavior. For Foundry, a test might look like:

solidity
function testGasPostUpgrade() public {
    vm.createSelectFork("mainnet", 20_000_000); // Fork after upgrade block
    uint256 gasBefore = gasleft();
    myContract.criticalFunction();
    uint256 gasUsed = gasBefore - gasleft();
    assertLt(gasUsed, MAX_EXPECTED_GAS);
}

Document any discrepancies and plan necessary mitigations, such as optimizing logic or deploying updated contracts.

step-2-testing-environment
PRACTICAL SETUP

Step 2: Set Up a Testing Environment

A robust testing environment is essential for safely evaluating the impact of EVM opcode changes on your smart contracts before deployment.

Begin by establishing a local development chain using tools like Hardhat or Foundry. These frameworks allow you to fork the mainnet state, enabling you to test your contracts against real-world data and interactions. For example, you can use anvil --fork-url https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY to create a local fork with Foundry. This setup is critical because opcode changes can have subtle, emergent effects that only appear in complex contract interactions or specific storage layouts.

Next, integrate a testing suite specifically designed to target the modified or deprecated opcodes. Write unit tests that execute the exact functions and code paths in your contracts that utilize these opcodes. For instance, if SELFDESTRUCT semantics are changing, create tests that invoke your contract's self-destruct mechanism and check the resulting state of the contract's storage and ETH balance. Use assertion libraries to verify that contract behavior remains correct and that any gas cost changes are within acceptable limits.

You should also set up a multi-client testnet. Deploy your contracts to a dedicated test network like Sepolia or Holesky that has already implemented the proposed EVM changes (often through a "shadow fork"). Testing across different Ethereum clients—such as Geth, Nethermind, and Besu—is crucial, as opcode implementations and gas calculations can vary. Monitor for any client-specific discrepancies in transaction execution or event logging that could affect your dApp's reliability.

Finally, implement continuous integration (CI) pipelines to automate this testing process. Configure your CI (e.g., GitHub Actions, GitLab CI) to run your full test suite against the forked mainnet and the upgraded testnets on every pull request. This ensures that any regression introduced by code changes or by the new opcode behavior is caught immediately. Include gas reporting in your CI output to track how opcode changes affect your contract's operational costs over time.

step-3-gas-analysis
PRACTICAL GUIDE

Step 3: Perform Gas Cost Analysis

Analyzing gas costs is essential to predict the impact of opcode repricing on your smart contracts. This step involves benchmarking and simulating transactions.

Begin by identifying the specific opcodes used in your contracts that are scheduled for a gas cost change. For example, the EIP-1884 repricing increased the cost of SLOAD, BALANCE, and EXTCODEHASH. Use tools like the Solidity compiler's --opcodes flag or EVM bytecode analyzers to generate a list. Focus on opcodes that appear in high-frequency loops or core contract logic, as these will see the most significant cost impact. This initial audit creates a targeted list for deeper analysis.

Next, benchmark current gas consumption using historical transaction data. Tools like Tenderly's Gas Profiler, Etherscan's transaction decoder, or custom scripts using eth_estimateGas can show you the gas cost breakdown of live contract interactions. Compare the gas used by opcodes like SSTORE or CALL against the total transaction cost. This establishes a baseline. For a forward-looking analysis, use a local testnet (like a Hardhat or Anvil node) configured with the proposed new gas schedule to simulate the same transactions and calculate the expected cost increase.

Finally, quantify the financial and operational impact. Calculate the percentage increase in gas costs for your contract's key functions. If a function's cost rises from 100,000 to 120,000 gas, that's a 20% increase. Consider how this affects: user transaction fees, contract economic models (e.g., protocol fees based on gas refunds), and block gas limit constraints for complex operations. Document these findings to inform the next step—optimizing your code. Proactive analysis prevents unexpected failures and cost overruns when the network upgrade goes live.

IMPLEMENTATION SCHEDULES

Upgrade Timelines by Network

Shanghai & Cancun Upgrades

The Ethereum mainnet follows a methodical, multi-client upgrade process. The Shanghai/Capella hard fork, which enabled staking withdrawals, was activated at epoch 194,048 on April 12, 2023. The subsequent Cancun/Deneb upgrade, introducing EIP-4844 (Proto-Danksharding) and other key opcode changes, was activated on March 13, 2024.

For mainnet, developers must monitor Ethereum Improvement Proposals (EIPs) in the AllCoreDevs calls and test changes on public testnets like Goerli, Sepolia, and Holesky before mainnet deployment. The typical timeline from final EIP inclusion to mainnet activation is 6-9 months. Always verify client release notes from Geth, Nethermind, Besu, and Erigon teams.

EVM UPGRADES

Frequently Asked Questions

Common developer questions about preparing for and adapting to changes in the Ethereum Virtual Machine (EVM) opcode set.

An EVM opcode is a low-level instruction that the Ethereum Virtual Machine executes, such as ADD for addition or SSTORE for writing to storage. Changes to this instruction set are proposed via Ethereum Improvement Proposals (EIPs) to introduce new functionality, improve security, or optimize gas costs. For example, EIP-3855 introduced the PUSH0 opcode to reduce contract code size, and EIP-4844 added data blob operations for scaling. These upgrades are deployed during scheduled network hard forks, requiring developers to update their tools and review their smart contract code for compatibility.

EVM UPGRADES

Common Mistakes to Avoid

EVM opcode changes, like those in Shanghai, Cancun, and Pectra, require proactive developer preparation. Failing to adapt can lead to broken contracts, unexpected gas costs, and security vulnerabilities. This guide addresses frequent pitfalls.

Your contract may revert because it relies on deprecated opcodes or their gas costs. For example, the Shanghai upgrade introduced PUSH0 (0x5f) and changed the behavior of SELFDESTRUCT. If your contract uses inline assembly that depends on the old gas schedule or a removed opcode, it will fail.

Common culprits:

  • Using SELFDESTRUCT for contract cleanup (now has restricted behavior).
  • Relying on precise gas calculations for CALL, BALANCE, or SLOAD which have been adjusted in past forks.
  • Hardcoded gas estimates in off-chain scripts that become inaccurate.

How to fix:

  1. Audit your contracts and libraries for deprecated opcodes using tools like Ethers.js's debug_traceTransaction or Hardhat's console.log in a testnet fork of the new EVM version.
  2. Replace SELFDESTRUCT with alternative patterns, like transferring funds to a designated address.
  3. Use gasleft() for dynamic gas checks instead of hardcoded values.
conclusion
STRATEGIC PREPARATION

Conclusion and Next Steps

Proactive planning for EVM opcode changes is essential for maintaining secure, efficient, and future-proof smart contracts.

Preparing for EVM opcode changes is not a one-time task but an ongoing discipline. The key steps involve continuous monitoring of EIP proposals on the Ethereum Magicians forum and the EIPs repository, rigorous testing against new client versions using tools like Hardhat or Foundry, and implementing upgradeable contract patterns for critical logic. For developers, this means integrating these checks into your CI/CD pipeline to catch regressions early.

Beyond immediate technical steps, consider the broader ecosystem impact. New opcodes like BLOBHASH (EIP-4844) or TLOAD/TSTORE (EIP-1153) can enable entirely new architectural patterns, such as cheaper data availability or transient storage for gas-efficient computations. Researching these changes allows you to optimize gas costs and design more sophisticated applications. Staying informed through developer calls for major clients like Geth, Nethermind, and Erigon is crucial for understanding implementation timelines and potential edge cases.

For next steps, begin by auditing your existing codebase. Use static analyzers like Slither to identify dependencies on gas prices or specific opcode behavior. Create a sandbox environment with the latest client beta releases to run your full test suite. Finally, engage with the community by participating in testing networks like a devnet or a pre-launch testnet for upcoming forks. This proactive approach transforms opcode changes from a deployment risk into an opportunity for innovation and optimization.