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
# Netted balance maps for cross-shard transfers * An explainer for dummies (hopefully easier to follow than the original post, which took me a week to understand: https://ethresear.ch/t/an-even-simpler-meta-execution-environment-for-eth/6704) * update 2020-1-23: an edited version of this was posted as a reply on the thread. ## Intro * we have three shards: A B C * When an EE is deployed, it is exists on all shards. Same code, but a different balance and different stateroot on each shard. * for each EE, each shard maintains a balance map like this: `A: [1, 0, 0]`. * we can visualize the global map as a matrix, but note that it is not maintained in whole anywhere. Rather, each shard maintains one row. ``` A B C A [1, 0, 0] B [0, 0, 0] C [0, 0, 0] ``` * this is the map(s) for an EE with a starting balance = 1 ETH on shard A. ## same-EE cross-shard transfers * same-EE cross-shard transfers are done by updating the map on the sending shard `shard[s1]`; the map on the receiving shard `shard[s2]` is not updated. * in code: `shard[s1].balances[s1][ee] -= xfer_amount` and `shard[s1].balances[s2][ee] += xfer_amount` * in a block on shard A there's a txn that transfers the 1 ETH to shard B (in the same EE). Only the map stored on shard A is updated (Row A), shard B is not aware. ``` A B C A [0, 1, 0] B [0, 0, 0] C [0, 0, 0] ``` * in a block on shard B there's a txn that transfers 1 ETH from B to C (in the same EE). only Row B is updated: ``` A B C A [0, 1, 0] B [0, -1, 1] C [0, 0, 0] ``` * note that the protocol doesn't require any checks for same-EE cross-shard transfers; it is up to the EE to implement checks and ensure that its balance across shards is netted correctly. For example, if a shard's row is all zeros, like Row B was prior to the transfer, then I guess the EE should verify a proof that shard B has a balance in some other row (in this example, shard B had balance 1 in Row A). * But it is no risk to the protocol if an EE doesn't do this correctly, because the protocol requires proofs when transferring from one EE to another. (protocol prevents EE's from issuing new ETH, but doesn't save EE's from accidentally burning or losing their ETH). ## cross-EE same-shard transfers * For cross-EE transfers, the protocol requires proof of an EE's balance across shards ("real balance"). > To perform any transfers of ETH between EEs in a block, the shard must contain a Merkle proof from the most recent state of every shard, showing `shard[i].balances[s][x]` for every shard i to prove the total balance of the EE. ... we check that `real_balance(s, ee_1) >= xfer_amount`. * Take the map from the previous section: ``` A B C A [0, 1, 0] B [0, -1, 1] C [0, 0, 0] ``` * to calculate the "real balance" on a shard, you add up the column. The real balance on shard C is 1, A and B have 0. * to send a transfer to another EE on shard C, you include merkle proofs for the balance map on all shards. This proves sufficient total balance, and sufficient "real balance" on C. ``` AliceEE -before Txn- BobEE A B C A B C A [0, 1, 0] A [0, 0, 0] B [0, -1, 1] B [0, 0, 0] C [0, 0, 0] C [0, 0, 0] ``` * Let's send the 1 ETH we have in AliceEE on shard C, to BobEE on shard C. To perform the transfer, update two maps (AliceEE and BobEE) for the shard we're on. * in code: we check that `real_balance(s, ee_1) >= xfer_amount`, then set `shard[s].balances[s][ee_1] -= xfer_amount` and `shard[s].balances[s][ee_2] += xfer_amount` ``` AliceEE -after Txn- BobEE A B C A B C A [0, 1, 0] A [0, 0, 0] B [0, -1, 1] B [0, 0, 0] C [0, 0, -1] C [0, 0, 1] ``` * This cross-EE same-shard Txn protocol works without coordination across slots (queues, receipts, etc.) because it is isolated from any AliceEE activity that might be happening on other shards in the same slot. Since the "real balance" is on shard C, the only way to do a cross-EE txn is to do it on shard C. The cross-EE txn could fail if a same-EE/cross-shard txn that sends the balance from C back to A, gets included in the block first. But any same-EE/cross-shard AliceEE txns included in shards A and B can be ignored; the worst that could happen is additional netting (-1, +1) entries getting added to the balance map, which won't affect the existing "real balance" on C. [edit]: I don't like this explanation of "without coordination across slots". It is coordinated across slots because the same-EE/cross-shard xfer happens by committing the balance map in a cross-link, and the cross-EE/same-shard also commits the balance maps (for sending EE and receiving EE) to a cross-link.

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