Skip to content
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

Scout host functions getShardId(), getShardStateRoot(shardId, offset). #38

Open
poemm opened this issue Jan 22, 2020 · 1 comment
Open

Comments

@poemm
Copy link

poemm commented Jan 22, 2020

The motivation for this proposal is to allow dapp developers to experiment with cross-shard communication through the beacon chain.

Analogous to how POSIX threads has pthread_self() to identify the thread id, and how OpenCL has get_global_id() and get_local_id() to identify the work item id, Scout EEs may wish to identify which shard they are executing in. I hereby propose a new scout host function getShardId() -> uint32 which returns 0 if called from the beacon chain, 1 if called from the first shard, 2 if called from the second shard, ..., n if called from the nth shard.

Moreover, analogous to how POSIX threads can read from shared pointers to local data, and how OpenCL threads can read from __global or __local pointers to __private data, EEs executing on a shard may wish to read from the beacon chain to local memory. I hereby propose a second new scout host function getShardStateRoot(shardId, offset) -> uint32 which takes as arguments a shard id as described above, and takes a memory offset similar to other scout functions. The host function has a side-effect of writing that shardId's 32-byte state root (see below) at the current time step to the EE's local memory at the offset. If either of the arguments are out-of-range, then it writes nothing. This host function returns 0 unless an argument was out-of-range, then it returns 1.

Now the unspecified part -- we must define what a shard is, define what an EE is relative to shards, define what code is relative to EEs, and define what a shard writes to the beacon chain at each time step. A first attempt follows, but it is incomplete. At each time step, each shard updates its state root to the beacon chain, where the state root of a shard is the 32-byte merkle root of all EEs in that shard. For merkleization, each EE is a leaf which contains the following.

  • 32-byte EE address (this needs specification) which corresponds to the Merkle path to this leaf,
  • 32-byte Eth balance (same as Eth1 balance),
  • 32-byte hash of the code that the EE executes when it is called (this needs specification), and
  • the 32-byte state root of the EE (accessed with scout functions loadPreStateRoot() and savePostStateRoot()).
    Merkleization obeys SSZ rules, though it may be wise to allow the user to easily replace the merkleization rule to allow prototyping without depending on SSZ.

Finally, I hereby propose changes to the Scout yaml format to initialize each EE, and to specify shardIds for each execution. This needs discussion.

Concrete use-cases are not yet available.

@poemm
Copy link
Author

poemm commented Mar 15, 2020

Prototyped here https://github.com/poemm/scout_wabt.cpp/tree/getShard_host_funcs .

Retrospective: The interface is reasonable. The unspecified part explained above remains unspecified.

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

No branches or pull requests

2 participants
@poemm and others