Skip to content

Conversation

shane-moore
Copy link
Contributor

Changes

  • updated the EL data structures page to include overview of the Transaction Trie 🌳

@shane-moore
Copy link
Contributor Author

@taxmeifyoucan @raxhvl, this PR is ready for review whenever you get a chance⚡

@raxhvl raxhvl requested a review from Copilot April 8, 2025 04:53
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

docs/wiki/EL/data-structures.md:193

  • Insert a space after 'insertion.' to correct the sentence spacing; it should be 'before insertion. This prevents attackers…'
…each slot index is hashed with keccak-256 before insertion.This prevents attackers…

@raxhvl raxhvl self-assigned this Apr 8, 2025
Copy link
Member

@raxhvl raxhvl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is coming up nicely @shane-moore

Again, it’s important to note that storage is not part of the EVM itself, rather the currently executing contract account. More specifically, the contract account contains a **storage root*** that points to a separate Merkle Patricia Trie for that contract's storage.
Again, it’s important to note that storage is not part of the EVM itself, rather the currently executing contract account. More specifically, the contract account contains a **storage root** that points to a separate Merkle Patricia Trie for that contract's storage.

The example above shows only a small section of the account's storage. Like memory, all the values in storage are well-defined as zero. Also, when a contract executes an `SSTORE` opcode that sets a storage slot’s value from non-zero back to zero, the operation becomes eligible for a gas refund (the gas is not returned immediately, but is credited to the transaction’s refund counter)​. This refund is applied at the end of the transaction to offset some of the gas cost, effectively rewarding the freeing of storage space.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The example above shows only a small section of the account's storage. Like memory, all the values in storage are well-defined as zero. Also, when a contract executes an `SSTORE` opcode that sets a storage slot’s value from non-zero back to zero, the operation becomes eligible for a gas refund (the gas is not returned immediately, but is credited to the transaction’s refund counter)​. This refund is applied at the end of the transaction to offset some of the gas cost, effectively rewarding the freeing of storage space.
The example above shows only a small section of the account's storage. Like memory, all the values in storage are well-defined as zero. Also, when a contract executes an `SSTORE` opcode that sets a storage slot’s value from non-zero back to zero, the operation becomes eligible for a gas refund (the gas is not returned immediately, but is credited to the transaction’s refund counter)​. This refund for freeing up valuable storage space from state trie is applied at the end of the transaction to offset some of the gas cost, effectively rewarding the freeing of storage space.

Added rationale behind storage. Feel free to reframe better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raxhvl, I got you. Updated in latest commit 489614e


In the previous section, we described how each account leaf in the **World State Trie** contains a `storageRoot`, which is the keccak-256 hash of the root node of a separate Merkle Patricia Trie, the **Storage Trie**. This trie is not embedded in the **World State Trie** but referenced via the `storageRoot`, enabling storage to be updated and proven independently while still contributing to the global state root.

The **Storage Trie** represents a contract’s persistent state as a mapping of 256-bit storage slots indices (keys) to 256-bit RLP-encoded values. Like the World State Trie, it uses a secure key scheme where each slot index is hashed with keccak-256 before insertion.This prevents attackers from crafting keys that cause long traversal paths or highly unbalanced trie structures, which could otherwise be exploited for DOS attacks by inducing excessive computation during trie lookups or updates.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Indicate the mapping of index -> value is sometimes called a storage slot. You have used the "storage slot" in the note below, so maybe define it here.


The **Storage Trie** represents a contract’s persistent state as a mapping of 256-bit storage slots indices (keys) to 256-bit RLP-encoded values. Like the World State Trie, it uses a secure key scheme where each slot index is hashed with keccak-256 before insertion.This prevents attackers from crafting keys that cause long traversal paths or highly unbalanced trie structures, which could otherwise be exploited for DOS attacks by inducing excessive computation during trie lookups or updates.

> While high-level languages (e.g., Solidity) define how contract variables are laid out across storage slots, this layout is abstracted at the execution layer. The trie treats all slots as uniform key-value entries.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The storage layout abstraction exists in solidity and not in the execution layer. Execution layer implements the abstraction.

Copy link
Contributor

@taxmeifyoucan taxmeifyoucan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Shane, great continuation!

Copy link

Hi @shane-moore,

⚠️ Potential typos found in your pull request:

  • 📄 ./docs/eps/intro.md (line(s) 102):
    1. ❌ Karim

ℹ️ How to fix this error:

  1. If these are actual typos:

    • Open the files at the specified line numbers and fix them
  2. If these are names or one-off nouns:

    • Wrap them in <name> tags
    • Example: <name>Alex Pereira</name>
    • Use this for people's names or unique terms that appear rarely
  3. If these are valid terms:

    • Add them to wordlist.txt (one word per line)
    • Terms must be plain text without spaces/special chars
    • The list is case-insensitive
  4. If these are code terms:

    • Wrap them in backticks (`) in your markdown

ℹ️ Checking for typos locally

  1. Install aspell for your platform
  2. Navigate to project root and run:
for f in **/*.md ; do echo $f ; aspell --lang=en_US --mode=markdown --home-dir=. --personal=wordlist.txt --ignore-case=true --camel-case --add-sgml-skip nospellcheck list < $f | sort | uniq -c ; done

Learn more about wordlist format

1 similar comment
Copy link

Hi @shane-moore,

⚠️ Potential typos found in your pull request:

  • 📄 ./docs/eps/intro.md (line(s) 102):
    1. ❌ Karim

ℹ️ How to fix this error:

  1. If these are actual typos:

    • Open the files at the specified line numbers and fix them
  2. If these are names or one-off nouns:

    • Wrap them in <name> tags
    • Example: <name>Alex Pereira</name>
    • Use this for people's names or unique terms that appear rarely
  3. If these are valid terms:

    • Add them to wordlist.txt (one word per line)
    • Terms must be plain text without spaces/special chars
    • The list is case-insensitive
  4. If these are code terms:

    • Wrap them in backticks (`) in your markdown

ℹ️ Checking for typos locally

  1. Install aspell for your platform
  2. Navigate to project root and run:
for f in **/*.md ; do echo $f ; aspell --lang=en_US --mode=markdown --home-dir=. --personal=wordlist.txt --ignore-case=true --camel-case --add-sgml-skip nospellcheck list < $f | sort | uniq -c ; done

Learn more about wordlist format

Copy link

Hi @shane-moore,

⚠️ Potential typos found in your pull request:

  • 📄 ./docs/eps/intro.md (line(s) 102):
    1. ❌ Karim

ℹ️ How to fix this error:

  1. If these are actual typos:

    • Open the files at the specified line numbers and fix them
  2. If these are names or one-off nouns:

    • Wrap them in <name> tags
    • Example: <name>Alex Pereira</name>
    • Use this for people's names or unique terms that appear rarely
  3. If these are valid terms:

    • Add them to wordlist.txt (one word per line)
    • Terms must be plain text without spaces/special chars
    • The list is case-insensitive
  4. If these are code terms:

    • Wrap them in backticks (`) in your markdown

ℹ️ Checking for typos locally

  1. Install aspell for your platform
  2. Navigate to project root and run:
for f in **/*.md ; do echo $f ; aspell --lang=en_US --mode=markdown --home-dir=. --personal=wordlist.txt --ignore-case=true --camel-case --add-sgml-skip nospellcheck list < $f | sort | uniq -c ; done

Learn more about wordlist format

@shane-moore
Copy link
Contributor Author

hi @raxhvl, just implemented your legit suggestions in latest commit 489614e. Feel free to take a look when you have a minute.

cc @taxmeifyoucan

@raxhvl raxhvl self-requested a review April 14, 2025 05:47
Copy link
Member

@raxhvl raxhvl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @shane-moore

@raxhvl raxhvl merged commit fa266cb into eth-protocol-fellows:main Apr 14, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants