Ethereum Merge From The Developer’s Perspective

Ethereum’s transition to PoS aka the merge is here. It’s been running smoothly for more than 3 days now. And it has already reduced Ethereum’s energy consumption by 99.99%.  As discussed in the last article, we know that the merge is all about replacing the PoW consensus layer with the PoS consensus layer, all while keeping the world state of ethereum as it is.

There are no changes when it comes to users using the dapps on ethereum. It will feel like nothing has changed and they are still riding the same car even though, the engine of the car has now been changed. However, those who make the engines and the components that work with the engine will have to cope with a few changes. Staking node operators, non-validating nodes, and dapp developers will have some things which are changed.

How the merge affects Dapp developers?

Block structure:

PoW-powered ethereum has a concept of a block. PoS-powered Ethereum will have “Execution Payloads”. Basically, execution payloads are the PoS blocks.

As shown in the above diagram, the block will have the above structure in the PoS chain. Data stored in a “block” of the PoW chain will be placed under “Execution Payload”.

Also, in the case of PoS chains, there won’t be chain reorganization and hence no omer blocks. So fields for these on PoW block became useless. We could have removed them altogether. But for minimizing the disruption to existing clients and apps, these fields are not removed.  Instead, fields are set to zero.

FIELDCONSTANT VALUECOMMENT
ommers[]RLP([]) = 0xc0
ommersHash0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347= Keccak256(RLP([]))
difficulty0
nonce0x0000000000000000

This EIP for upgrading PoW to PoS explains all the proposed changes in depth. EIP can be found here.

OpCodes

Blockhash opcode will still be there. But since it won’t be mined via PoW, its value can be predictable and the randomness provided by blockchain will be weaker.

DIFFICULTY opcode (0x44) will be updated and renamed to PREVRANDAO. It will return the output of the randomness beacon provided by the beacon chain. This opcode will be the stronger source of randomness on the chain and should be used instead of blockhash. The value exposed by PREVRANDAO will be stored in the ExecutionPayload by the name of `prevRandao`.

Block time

The average block time on ethereum is 13 seconds in the current PoW chain. However, there is a lot of fluctuation in average block time. This does change post-merge. Under PoS, every block comes exactly every 12 seconds. If a validator misses a block, a new block won’t be produced. But everything will happen in the interval of 12 seconds. Smart contracts which assume a particular average block time in their calculations will need to take this into account.

Safe Head & Finalized Blocks

In PoW chains, there is potential for chain reorganizations. This means, that mined blocks can be omitted from the canonical chain for a few reasons. (Let’s not go there. ) To tackle this, usually, applications wait for a fixed number of blocks to be mined on top of a particular block number. 

In PoW when you query the `latest` block using JSON RPC, in case of reorgs, it’s possible that the block won’t be a part of the main chain. 

In the PoS chain, there is a concept called Safe-head. A safe head is the last “finalized” block number which is always going to be a part of the canonical chain. Chances of safe head not being part of the canonical chain are very bleak.

So, JSON RPC API for PoS chain supports two tags for querying blocks – safe and finalised.

safe is the block number that has been produced but the chances of it being not part of the chain are nonzero albeit very less. Requires either large network delay or attack on the network.

finalised is the block number which 99.99% always going to be included in the canonical chain. 

More and more changes will be introduced as Ethereum ships upgrades which makes it more scalable as well as efficient. Hope this post was informative. Do subscribe to the blog for more meaningful content. I am always available on my socials for a chat! 

%d bloggers like this: