Skip to content

Commit

Permalink
Merge pull request #39 from hyeonLewis/kip-239
Browse files Browse the repository at this point in the history
[KIP-239] EXTCODEHASH opcode for Kaia
  • Loading branch information
hyeonLewis authored Dec 31, 2024
2 parents d1cfac1 + 906185a commit e97c3b8
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions KIPs/kip-239.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
kip: 239
title: EXTCODEHASH opcode for Kaia
author: Lewis (@hyeonLewis)
discussions-to: https://github.com/kaiachain/kips/issues/38
status: Draft
type: Core
created: 2024-12-27
---

## Simple Summary

Clarifies and aligns the implementation of `EXTCODEHASH` opcode with [EIP-1052](https://eips.ethereum.org/EIPS/eip-1052) and [EIP-2929](https://eips.ethereum.org/EIPS/eip-2929).

## Abstract

This KIP explains the historical implementation differences of `EXTCODEHASH` in Kaia compared to Ethereum. It also specifies the complete alignment with EIPs starting from the Prague hardfork.

## Motivation

The `EXTCODEHASH` opcode in Kaia has had implementation differences from EIPs. These difference was fixed in the Cancun hardfork but require further alignment, particularly regarding gas costs after the Prague hardfork. This KIP aims to provide clear explanation of the changes and ensure complete compatibility with EIPs.

## Specification

### Parameters

| Parameter | Value |
| ----------------- | -------------------------------------------------------------------- |
| `ZERO_CODE_HASH` | `0x0000000000000000000000000000000000000000000000000000000000000000` |
| `EMPTY_CODE_HASH` | `0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470` |

### EIP-1052

The `EXTCODEHASH` opcode according to EIP-1052 should return:

- For non-existent accounts: `ZERO_CODE_HASH`
- For accounts with no code: `EMPTY_CODE_HASH`

In Kaia, the `EXTCODEHASH` opcode returns:

| Hardfork | Non-existent | No code | Note |
| ------------- | ----------------- | ----------------- | -------------------------------------------------------- |
| Before Cancun | `EMPTY_CODE_HASH` | `EMPTY_CODE_HASH` | Wrong EIP-1052 implementation for non-existent accounts. |
| Cancun | `ZERO_CODE_HASH` | `EMPTY_CODE_HASH` | Fully compatible with EIP-1052. |
| Prague | `ZERO_CODE_HASH` | `EMPTY_CODE_HASH` | |

### EIP-2929

The constant gas cost for `EXTCODEHASH` opcode, which is same as `WarmStorageReadCostEIP2929`, should be 100 after the Kore hardfork which introduced EIP-2929.

In Kaia, the `EXTCODEHASH` opcode has the following gas costs:

| Hardfork | Constant gas cost | Note |
| ----------- | ----------------- | -------------------------------------------------------- |
| Before Kore | 400 | `ExtcodeHashGasConstantinople` |
| Kore | 100 | Brought EIP-2929. |
| Cancun | 400 | Fixed `EXTCODEHASH`, but accidentally shadowed EIP-2929. |
| Prague | 100 | Fully compatible with EIP-2929. |

## Backwards Compatibility

The fix of gas cost for `EXTCODEHASH` opcode is backwards incompatible since the Prague hardfork. Note that the EIP-1052 implementation was already fixed in the Cancun hardfork.

## References

[EIP-1052](https://eips.ethereum.org/EIPS/eip-1052)
[EIP-2929](https://eips.ethereum.org/EIPS/eip-2929)

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

0 comments on commit e97c3b8

Please sign in to comment.