Submitted by anon
The discrepancy in deployment nonce behavior between zkSync Era and EVM can cause problems for contract factories and developers. zkSync Era starts the deployment nonce at zero, unlike the EVM, where it starts at one. This difference may lead to incorrect predictions of child contract addresses.
As per EIP-161, its specified that account creation transactions and the CREATE operation should increase the nonce beyond its initial value by one.
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-161.md#specification
In other words, when an EOA (for example with nonce 100) deploys a contract (named as contract X), the nonces will be (please note that the nonce of the newly-deployed contract X is also incremented by one):
And when in another transaction, this contract X deploys another contract (named as contract Y), the nonces will be (again please note that the nonce of the newly-deployed contract Y is also incremented by one):
However, during the zkSync Era, there is a divergence from the Ethereum standard. In this context, the deployment nonce for a newly created contract initiates at zero. This deviation from the EVM standard can impact factories that anticipate the addresses of child contracts and make decisions based on these assumptions. Such factories might mistakenly assume that their nonce starts at 1, mirroring the EVM, leading to discrepancies between anticipated and actual addresses of the deployed child contracts.
It is advisable to increment the deployment nonce of a contract by one before invoking its constructor. Moreover, this contrast should be documented to provide clarity for developers.
https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/system-contracts/contracts/ContractDeployer.sol#L322
Context
miladpiri (zkSync) acknowledged and commented:
Alex the Entreprenerd (judge) commented:
Alex the Entreprenerd (judge) commented:
anon (warden) commented:
Alex the Entreprenerd (judge) commented:
vladbochok (zkSync) commented:
