Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines EIP-684, a proposal to prevent contract code from being overwritten by making contract creation fail when the destination address already meets the collision conditions.

This explanation translates, summarizes, and expands on the following specification.

For more articles about EIPs, see the following page.

Overview

This EIP prohibits creating a new smart contract at an Ethereum address that already contains contract code.

When a smart contract is deployed, it is assigned an address that serves as its identifier. If existing contract code could be overwritten through another deployment, an attacker could alter the contract's behavior without authorization, creating a security risk.

Under this EIP, attempting to create a contract at an address that already contains code results in an error, preventing unauthorized overwriting through contract creation. This strengthens Ethereum's security and helps enforce the immutability of deployed contract code.

Specification

EIP-684 specifies a rule governing contract creation on Ethereum.

If the destination address of a new contract already has a nonzero nonce or nonempty code, contract creation is not permitted.

The nonce is an account counter; for an externally owned account, it tracks transactions sent from that account. The code length indicates the size of the smart contract code deployed at the address.

The rule prevents attempts to forcibly deploy a new contract at an address that is already in use under these conditions.

The proposal specifies that this change applies retroactively to all previously mined blocks, extending the collision rule across the blockchain's history. The original article presents this as a measure to protect the integrity of historical transactions.

Additional Considerations

Smart contracts rely heavily on the immutability of deployed code. This property provides confidence that contract code cannot simply be tampered with after deployment and contributes to trust and transparency.

The original article discusses a theoretical threat in which an attacker with substantial computational resources might attempt to change code at a specific address and use the contract for unauthorized operations.

Such an attack, if it could bypass the blockchain's security mechanisms, could involve unauthorized transfers or manipulation of data. Recognizing these risks and taking measures to address them is important for maintaining the security of blockchain-based systems and smart contracts.

Backward Compatibility

As an execution-layer upgrade, this proposal requires a hard fork.

Tests

text
Address : 0xd0bBEc6D2c628b7e2E6D5556daA14a5181b604C5,
Balance : 1000000000000000000, // 1 ether
Nonce   : 0,
code    : "",

Address : 0x7658771dc6Af74a3d2F8499D349FF9c1a0DF8826,
Balance : 0,
Nonce   : 1,
Code    : "0xB0B0FACE",

This example shows the assets and state assigned to two addresses in the blockchain's initial state (genesis block).

The first address has a balance of 1 ETH, a nonce of 0, and empty code. It represents a typical externally owned account (EOA).

The second address has a balance of 0, a nonce of 1, and code represented by 0xB0B0FACE. The presence of code indicates that this address is a contract account.

The test describes a contract-creation attempt initiated by the first transaction sent from the first address, without using a salt (additional data used in certain contract-creation operations). The creation must fail and the transaction must revert.

In this context, a revert means that execution fails and its state changes are rolled back. In the test, the expected failure concerns the genesis allocation and the contract-creation collision conditions defined by the proposal.

Security

This EIP is a security upgrade that enforces the immutability of deployed code against contract-creation collisions.

Citation

Vitalik Buterin (@vbuterin), Renan Rodrigues de Souza (@RenanSouza2), "EIP-684: Revert creation in case of collision," Ethereum Improvement Proposals, no. 684, March 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-684.

Conclusion

EIP-684 proposes making contract creation fail at an address that satisfies the collision conditions, preventing existing code from being overwritten through contract creation.

If you have questions, feel free to contact me on Twitter.

Twitter @cardene777

I also publish articles on the following platforms.

https://chaldene.net/