quilt / simulation

A tool to simulate Ethereum 2.0 execution
12 stars 2 forks source link

Simulation Repository Roadmap (draft, subject to change) #21

Open gjtrowbridge opened 4 years ago

gjtrowbridge commented 4 years ago

Simulation Repository Roadmap (subject to change)

Overall Goals:

Goal 1: Provide a basic interface for interacting with an Eth2-like simulation, specifically for creating and testing EEs.

Proposed Initial Interface

High-level Simulation Methods

We anticipate adding many more methods in the future, but here are the functions we think are most necessary for the initial goal of testing EEs in an Eth2-like environment.

// Add a new execution environment, return EE index
fn create_execution_environment(a: args::CreateExecutionEnvironment) -> u32 {}

// Add a new shard block containing a list of transactions that need to be executed
// Execute all transactions on the appropriate shards / EEs, return ShardBlock index
fn create_shard_block(args: args::CreateShardBlock) -> u32 {}

// Get an EE that was previously added
fn get_execution_environment(args: args::GetExecutionEnvironment) -> ExecutionEnvironment {}

// Get a shard block that was previously added
fn get_shard_block(args: args::GetShardBlock) -> ShardBlock {}

// Get the specified ShardState, will contain EE states
fn get_shard_state(args: args::GetShardState) -> ShardState {}

Types / Structs

All types that are defined in the Phase 0 and Phase 1 spec documents will look the same in this simulation, with a couple exceptions: 1) Where appropriate, the simulation will either "mock" or neglect to include fields that are not relevant for the current goals of the simulation.

Unspecced Stuff

The following "unspecced" types will be included in the simulation:

struct ExecutionEnvironment {
    // arbitrary eWASM byte code
    wasm_code: Vec<u8>,
}

// Represents a transaction on a specific shard for a specific execution environment
struct ShardTransaction {
    // Arbitrary-length bytes included with the transaction
    // Could include arguments, witness data, or anything else this specific EE might require
    data: Vec<u8>,
    // The index of the execution environment in which this transaction will run
    ee_index: u32,
}

ExecutionEnvironment will be stored in the simulation on the spec's BeaconState struct as follows: Note: "Crosslinked" shard state was recently "specced", and is stored on BeaconState.shard_states

struct BeaconState {
    // ...(fields from the spec here)
    // ...(minus any unneeded fields)

    execution_environments: Vec<ExecutionEnvironment>
}

ShardTransaction will be passed to the simulation as part of ShardBlock, as follows:

struct ShardBlock {
    transactions: Vec<ShardTransaction>,
}

Note: this may not follow the spec exactly, but is useful for being able to execute a pre-bundled set of transactions on an EE via the create_shard_block function above. If necessary, this interface (and the associated structs) may change in the future.


ExecutionEnvironments will have shard-specific state, which will be stored as 32 bytes of arbitrary data (in most EEs, this 32 bytes is expected to be used to store the root hash of the EE's state tree)

This shard-specific state will be stored on the the spec's ShardState struct as follows:

struct ShardState {
    // ...(fields from the spec here)
    // ...(minus any unneeded fields)

    // One 32-byte chunk of data for each of the execution environments
    execution_environment_states: Vec<[u8; 32]>,
}
Function Arguments
mod args {
    struct CreateExecutionEnvironment {
        wasm_code: Vec<u8>,
    }

    struct CreateShardBlock {
        shard_index: u32,
        transactions: Vec<ShardTransactions>,
    }

    struct GetExecutionEnvironment {
        execution_environment_index: u32,
    }

    struct GetShardBlock {
        shard_chain_index: u32,
        shard_block_index: u32,
    }

    struct GetShardState {
        // Initially, this method will only return the latest shard state, so it only requires the shard index
        // If necessary, this interface can be modified in the future to allow access to "older" copies of ShardState
        // for a given shard. 
        shard_index: u32,
    }
}

Goal 2: Support existing efforts to provide one or more examples of ExecutionEnvironments

The simulation repo already has some very basic EEs that can be used with the simulation (eg. users can create the EE in the simulation, run transactions on that EE, see the state update, etc).

However, one effort currently being worked on in parallel is to create one or more full-featured EEs that includes some of the features expected in "production" Eth2 EEs, such as:

The simulation should add whatever features are necessary to be compatible with this work.

Goal 2+: Keep up-to-date with the spec and add features as-necessary to support users

SamWilsn commented 4 years ago

I'm not sure if it would be too much detail, but since you're showing the API for calling into the simulation, what are your thoughts on showing the API for EEs?

gjtrowbridge commented 4 years ago

I'm not sure if it would be too much detail, but since you're showing the API for calling into the simulation, what are your thoughts on showing the API for EEs?

By EE API are you referring to the host functions available to EEs?

SamWilsn commented 4 years ago

By EE API are you referring to the host functions available to EEs?

Both sides. So functions the EE has to export, and host functions.

villanuevawill commented 4 years ago

Looks good! Might be interesting to add host functions, etc. in a future PR.

gjtrowbridge commented 4 years ago

By EE API are you referring to the host functions available to EEs?

Both sides. So functions the EE has to export, and host functions.

I think currently there's nothing set in stone for functions EE has to export (since AFAIK technically the plan is for them to be arbitrary code), though I'd imagine most EEs would adhere to some sort of standard for functionality. Will definitely plan to add host functions to this in the future.

Looks good! Might be interesting to add host functions, etc. in a future PR.

Yep, will plan to add a list of these to the roadmap sometime soon (though it doesn't seem super urgent to publish that list so may not prioritize it immediately), and of course even once that list is up we can always add more (or remove some) as necessary in the future.