-
Notifications
You must be signed in to change notification settings - Fork 166
chore: add storage trie #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add storage trie #415
Conversation
b5e49c4
to
0502ac3
Compare
@taxmeifyoucan @raxhvl, this PR is ready for review whenever you get a chance⚡ |
There was a problem hiding this 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…
There was a problem hiding this 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
docs/wiki/EL/evm.md
Outdated
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/wiki/EL/data-structures.md
Outdated
|
||
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. |
There was a problem hiding this comment.
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.
docs/wiki/EL/data-structures.md
Outdated
|
||
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
0502ac3
to
df00c75
Compare
Hi @shane-moore,
ℹ️ How to fix this error:
ℹ️ Checking for typos locally
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 |
1 similar comment
Hi @shane-moore,
ℹ️ How to fix this error:
ℹ️ Checking for typos locally
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 |
8941121
to
489614e
Compare
Hi @shane-moore,
ℹ️ How to fix this error:
ℹ️ Checking for typos locally
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @shane-moore
Changes