HackMD
    • Sharing Link copied
    • /edit
    • View mode
      • Edit mode
      • View mode
      • Book mode
      • Slide mode
      Edit mode View mode Book mode Slide mode
    • 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
    • More (Comment, Invitee)
    • Publishing
    • Commenting Enable
      Disabled Forbidden Owners Signed-in users Everyone
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Invitee
    • No invitee
    • Options
    • Versions and GitHub Sync
    • Transfer ownership
    • Delete this note
    • Template
    • Save as template
    • Insert from template
    • Export
    • Google Drive Export to Google Drive
    • Gist
    • Import
    • Google Drive Import from Google Drive
    • Gist
    • Clipboard
    • Download
    • Markdown
    • HTML
    • Raw HTML
Menu Sharing Help
Menu
Options
Versions and GitHub Sync Transfer ownership Delete this note
Export
Google Drive Export to Google Drive Gist
Import
Google Drive Import from Google Drive Gist Clipboard
Download
Markdown HTML Raw HTML
Back
Sharing
Sharing Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
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
More (Comment, Invitee)
Publishing
More (Comment, Invitee)
Commenting Enable
Disabled Forbidden Owners Signed-in users Everyone
Permission
Owners
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Invitee
No invitee
   owned this note    owned this note      
Published Linked with GitHub
Like BookmarkBookmarked
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
## SSZ & Typed Transactions End goal is for blocks to be SSZ from top to bottom. For this document, I'll use python class syntax for SSZ Container schemas for simplicity. ```python class Block: parent: bytes32 transactions_root: bytes32 receipts_root: bytes32 uncles_root: bytes32 ``` One property that we get from SSZ is the ability to substitute a hash for the actual object. In this case, lets look at the `parent`. ```python # schema for a block that references its parent with a hash class Block: parent: bytes32 ... # schema for a block that includes the full parent class BlockWithParent: parent: Block ... parent = Block(...) parent_hash = hash_tree_root(parent, sedes=Block) block = Block(parent=parent_hash, ...) block_with_parent = BlockWithParent(parent=parent, ...) block_hash = hash_tree_root(block, sedes=Block) block_with_parent_hash = hash_tree_root(block_with_parent, sedes=BlockWithParent) assert block_hash == block_with_parent_hash ``` This simple example is meant to demonstrate this hash substitution principle. Lets look at a more practical way that we can take advantage of this property by exploring the `transaction_root`. ```python class Block: parent: bytes32 transaction_root: bytes32 ... ``` The `transaction_root` in this example is the `hash_tree_root(transaction_list, sedes=TransactionList)`, where `transaction_list` is the list of transactions in the block. The hash substitution property of SSZ means that we can define the following schema which will have the same hash as the block above. ```python class BlockWithFullTransactionList: parent: bytes32 transaction_list: TransactionList ... ``` In the *current* protocol, we have a distinct model that is used for the header chain, and then some ad-hoc models that we use in the DevP2P protocol to ship around block bodies and block receipts. In order to validate the block body or receipts, one must reconstruct the `transaction_trie` or other relevent tries from the received payload to verify the data against the header. In a world where blocks are SSZ, we have the ability to define a schema like `BlockWithFullTransactionList` which would compute to the same hash as the `Block` model. This enables us to have a minimal schema that is used for the header chain, and a more verbose schema that is more suitable for transmission of this data over the network for use cases like syncing the chain. And since the different schemas result in the same hash, it means that the block hash is the merkle root under which we can create a single merkle proof against any subset of the block data. These proofs can even reach into parent blocks! Now, lets look at how best to define `TransactionList`. ```python class TypedTransaction: type: uint8 txn_root: bytes32 TransactionList = List[TypedTransaction, max_length=...] ``` This simplistic top level model for the `TransactionList` assumes that the `Transaction.hash` is an SSZ hash. Using the hash substitution property, that means that we can also define a richer schema that will result in an equivalent hash. ```python class Transaction: to: bytes20 data: List[uint8, max_length=...] ... class FullTypedTransaction: type: uint8 transaction: Transaction FullTransactionList = List[FullTypedTransaction, max_length=...] ``` This allows us to have a both a minimal representation containing only the transaction hashes using `TransactionList` or a verbose representation that contains the actual transaction details using `FullTransactinList`. In order to take advantage of this, we **must** use a transaction hash that represents an SSZ hash tree root. Now, we need to extend this to support multiple transaction types. The ideal solution is to use a `Union` SSZ type. This ensures that we can have merkle proofs against the block root that extend down into the transaction objects themselvs. If use of a `Union` type is deemed to not be a viable way forward we *could* define the transaction as an opaque binary payload. ```python class FullTypedTransaction: type: uint8 payload: List[uint8, max_length=...] ``` In this model, to get at the actual rich transaction object requires parsing the `(type, payload)` and then using the `type` value to determine how `payload` would need to be deserialized. Under this approach, it would be more difficult to make a proof against the details of an individual transaction as the merkle proof would not be able to do more than assert things about the binary payload but not against the individual fields.

Import from clipboard

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 lost 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?

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

Sign in via SAML

or

Sign in via GitHub

Help

  • English
  • 中文
  • 日本語

Documents

Tutorials

Book Mode Tutorial

Slide Example

YAML Metadata

Resources

Releases

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

Versions and GitHub Sync

Sign in to link this note to GitHub Learn more
This note is not linked with GitHub Learn more
 
Add badge Pull Push GitHub Link Settings
Upgrade now

Version named by    

More Less
  • Edit
  • Delete

Note content is identical to the latest version.
Compare with
    Choose a version
    No search result
    Version not found

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. Learn more

       Sign in to GitHub

      HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

      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
      Available push count

      Upgrade

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Upgrade

      Danger Zone

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

      Syncing

      Push failed

      Push successfully