Wei Han Ng
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
1
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# Ethereum Bytecode and Code Chunk Analysis Code chunking is a strategy for breaking up bytecode into smaller chunks, which helps reduce witness size. However, this approach is only effective if a relatively small portion of the bytecode is accessed during execution. This analysis explores byte and chunk access patterns to evaluate the utility of code chunking. ## Methodology The complete repository which includes the data collection and analysis code can be found [here](https://github.com/weiihann/chunk-analysis). ## Analysis ### Key Dataset Statistics - **Block range:** 15537394 (The Merge)–22000000 - **Block Count:** 100898 (spreaded evenly across the block range) - **Total contract interactions**: 19,934,701 - **Min. unique contracts interacted with per block:** 1 - **Median unique contracts interacted with per block:** 187 - **Max. unique contracts interacted with per block:** 659 - **Total unique contracts interacted with:** 1,220,017 ![](https://hackmd.io/_uploads/rkvgYJZvex.png) --- ### Bytes Access Patterns This section examines the proportion of bytecode accessed during contract execution: ``` Bytes Accessed Ratio = bytes accessed / total bytecode size ``` ![](https://hackmd.io/_uploads/Syt4YJ-Peg.png) ![](https://hackmd.io/_uploads/rJZrFJ-Pxx.png) **Core Finding:** On average, only **22.8%** of the contract bytecode was accessed in a block. **Detailed Insights:** - **Median proportion accessed:** 17.1% - **By contract size:** - **Tiny (<1 KiB):** avg 62.9%, median 61.2% - **Small (1–5 KiB):** avg 21.6%, median 15.8% - **Medium (5–10 KiB):** avg 15.0%, median 13.0% - **Large (10–20 KiB):** avg 16.5%, median 17.3% - **Very Large (20–24 KiB):** avg 16.1%, median 15.1% **Interpretation:** For contracts larger than 1 KiB, only a small fraction of the bytecode is accessed. Contracts under 1 KiB tend to have more of their bytecode accessed. This is expected, as small contracts usually contain fewer functions that are repeatedly invoked. --- ### Chunk Access Patterns Referencing [EIP-2926](https://eips.ethereum.org/EIPS/eip-2926) as a code chunking solution, we split the contract bytecode into 31-byte chunks and assess the proportion of 31-byte chunks accessed: ``` Total number of chunks = bytecode size / 31 Chunks Accessed Ratio = chunks accessed / total number of chunks ``` ![](https://hackmd.io/_uploads/S1c4qJbPxg.png) ![](https://hackmd.io/_uploads/SkpN5kbvxx.png) **Core Finding:** On average, only **29.6%** of 32-byte chunks were accessed in a block. **Detailed Insights:** - **Median proportion accessed:** 24.7% - **By contract size:** - **Tiny (<1 KiB):** avg 69.1%, median 66.7% - **Small (1–5 KiB):** avg 30.8%, median 23.5% - **Medium (5–10 KiB):** avg 22.0%, median 19.6% - **Large (10–20 KiB):** avg 22.2%, median 24.5% - **Very Large (20–24 KiB):** avg 21.7%, median 21.1% **Interpretation:** The results are similar to the bytes accessed ratio. Chunk access is also low for contracts over 1 KiB. However, the overall chunk accessed ratios are slightly higher than byte accessed ratios, suggesting that not all bytes in the accessed chunks were used. --- ### Chunks Efficiency In this section, we explore how efficient chunks are, i.e., how many bytes in the chunks are actually used: ``` Chunks Efficiency = bytes accessed / (chunks accessed * 31) ``` ![](https://hackmd.io/_uploads/rkO1KxWDee.png) ![](https://hackmd.io/_uploads/r1jkYg-Dxe.png) **Core Finding:** On average, **68.9%** of the bytes in the 31-byte chunks were accessed. That's roughly 21 bytes in every 31-byte chunks on average. This indicates that more than half of the bytes in 31-byte chunks were accessed. To maximize chunk efficiency, we may consider smaller chunk sizes (e.g., 16-byte chunks). However, this comes at the cost of increased hashing overhead. --- ### Code-Access Instructions This section evaluates the impact of opcodes that access the entire code, namely: - `EXTCODESIZE` - `EXTCODECOPY` - `CODECOPY` - `CODESIZE` When one of these opcodes is executed, it requires access to all of the bytes in the bytecode. In the past sections of evaluating the access ratios, we exclude them from the results. Here, we assess how including them changes the access ratios. We split them into two categories: 1. Code Size (`EXTCODESIZE`, `CODESIZE`) 2. Code Copy (`EXTCODECOPY`, `CODECOPY`) The reason for the 2 categories is because [EIP2926](https://eips.ethereum.org/EIPS/eip-2926) adds the code size in the account field. Therefore, once it's implemented, code size opcodes will no longer require access to the entire bytecode. ![](https://hackmd.io/_uploads/Hk4jaeZvee.png) In total, **46.6%** of contracts per block contain either the code size or code copy opcodes. Among these, **40.7%** contain code size opcodes, while only **10.6%** contain the code copy opcodes. ![download (9)](https://hackmd.io/_uploads/HkWzzzZwex.png) ![download (10)](https://hackmd.io/_uploads/HJ4MMM-Dll.png) ![download (11)](https://hackmd.io/_uploads/B1vfMMbwgg.png) ![download (12)](https://hackmd.io/_uploads/HJqffGbPxl.png) **Avg Bytes Access Ratio** - Original: 22.8% - With Code Size: 54.0% (+31.2%) - With Code Copy: 31.5% (+8.7%) **Avg Chunks Access Ratio** - Original: 29.6% - With Code Size: 57.8% (+28.2%) - With Code Copy: 37.6% (+8.0%) After including the code-access instructions, we do see a moderate increase in the access ratios. However, it's mostly due to code size opcodes. As mentioned before, the addition of code size in the account field would make code copy opcodes the only instructions to access the entire bytecode. Since the amount of code copy instructions is significantly lesser, the overall access ratios are lower. --- ## Is Code Chunking A Viable Solution? Referencing [EIP-2926](https://eips.ethereum.org/EIPS/eip-2926), the main point of code chunking is to reduce witness size, as the current status quo requires the whole bytecode to be used in the code proof. Our analysis has shown that not all of the bytes in a contract's bytecode are used. In fact, only a relatively small proportion of the bytes and chunks are used. Based on the current access patterns, if we were to implement code chunking, we would significantly reduce the amount of actual bytes used included in the code witness. The addition of code size in the account field in EIP2926 would effectively make code copy opcodes the only instructions that requires accessing the entire bytecode. In addition, as shown in our findings, the amount of code copy opcodes is significantly less than the code size. Therefore, we would further reduce the average code witness size based on the current access pattern. One additional exploration that we can conduct is to determine the optimal chunk size. In EIP-2926, it uses 31-byte chunks. We may want to explore smaller chunk sizes, such as 16-byte, to maximize the number of bytes utilized per chunk. However, this comes at a cost of additional hash overhead. Therefore, we need to experiment with different chunk sizes to find the optimal balance.

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully