Plato Data Intelligence.
Vertical Search & Ai.

Unpacking the PUSH0 Instruction in Solidity 0.8.20 – Investor Bites

Date:

SNEAK PEEK

  • PUSH0 instruction in Solidity 0.8.20 significantly improves gas efficiency.
  • PUSH0 instruction reduces both runtime and deployment gas costs.
  • The new feature may not be compatible with EVM-equivalent sidechains.

In recent news, the Ethereum community has been excited about the announcement that Solidity version 0.8.20 will now support the ‘PUSH0’ instruction. This highly anticipated update is to revolutionize Ethereum blockchain interactions by minimizing financial resources, notably gas efficiency.

In simple terms, PUSH0 is an instruction that pushes a value of zero onto the stack during contract execution. It is a vital addition to the Ethereum Virtual Machine (EVM) instruction set, specifically introduced to increase gas efficiency.

A recent comparison of Solidity versions 0.8.19 and 0.8.20 demonstrated that a code that utilized the PUSH0 instruction used two gas units less than its counterpart. Though the amount might seem trivial, the impact magnifies when you scale this to the size of complex real-world smart contracts.

Investigating the Gas-Saving Mechanism

To identify the source of the savings, the transaction (txn) was meticulously examined using the Remix debugger, with each instruction being scrutinized in detail. The analysis revealed two instances where zero value needed to be pushed onto the stack.

The first instance was when loading the function to execute. The EVM needed to load the function selector from the transaction calldata to perform this, requiring a CALLDATALOAD call with a zero offset.

The second instance of PUSH1 00, an instruction that pushes the byte value of 0 onto the stack, was used during calldata validation. It is unclear why the compiler added the value of zero to the stack and duplicated it since it gets popped off later on.

However, when the code was compiled with Solidity 0.8.20, both calls were replaced with PUSH0, saving two gas units at runtime. The use of PUSH0 also has implications for deployment gas costs, which are reduced when the total contract bytecode size is reduced. 

Since PUSH0 requires only one byte of data, each replacement decreases the deployment gas costs. Contrary, Sidechains or rollups that are EVM-equivalent may not yet support PUSH0. Compiling with Solidity 0.8.20 and deploying on these chains may result in non-functioning code.

spot_img

Latest Intelligence

spot_img

Chat with us

Hi there! How can I help you?