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

Things to decide for phase 2 #702

Closed
vbuterin opened this issue Feb 28, 2019 · 8 comments
Closed

Things to decide for phase 2 #702

vbuterin opened this issue Feb 28, 2019 · 8 comments
Labels
general:RFC Request for Comments phase2

Comments

@vbuterin
Copy link
Contributor

vbuterin commented Feb 28, 2019

What is the above missing?

@hwwhww hwwhww added the phase2 label Feb 28, 2019
@axic
Copy link
Member

axic commented Feb 28, 2019

I think this looks like a great list to start the discussion!

We have already started collecting ideas regarding ewasm here: https://github.com/ewasm/design/issues. I think some of these can be applied to the "Eth1.x" version of ewasm, but definitely don't see any reason they couldn't be applied to Eth2.0.

Regarding contract addressing:

  • Possible alternative: optional sequential addresses for contract creation (rationale: with much smaller addresses, using libraries may be much more efficient)

We are exploring "contract linking" in its various forms as an alternative to this. That would eliminate "calls" needed to interact with libraries.

@vbuterin
Copy link
Contributor Author

That would eliminate "calls" needed to interact with libraries.

Interesting! Though this still seems like it would not remove the need for blocks with transactions using that library to need to provide a merkle branch of the code to prove execution statelessly.

More broadly, I feel like one question that the EWASM team could help a lot by figuring out is, what kind of an interface would EWASM have with respect to the wider system? The simplest possible interface for example would be the ability to run execute_code(code, data), with the ability to escape internally with call(address, data) and ffi(data); then everything else (eg. providing environment variables, reading/writing storage) can be done at the outside level with the FFI.

If the interface is settled, then work on everything-outside-the-VM and everything-inside-the-VM could just proceed separately.

How far away is the EWASM team from being able to lay down an opinion on this?

@lrettig
Copy link

lrettig commented Mar 13, 2019

what kind of an interface would EWASM have with respect to the wider system? The simplest possible interface for example would be the ability to run execute_code(code, data), with the ability to escape internally with call(address, data) and ffi(data)

It just struck me that this configuration feels a lot like an operating system with a kernel mode and a user mode--where, in this case, Ewasm contract code is running in user mode and has one or more system calls it can make which switch the context back to "kernel" (EEI) mode. I wonder if we shouldn't take design cues from existing operating system design. @axic, @jakelang and others know way more about this topic than I do.

@axic
Copy link
Member

axic commented Mar 24, 2019

The simplest possible interface for example would be the ability to run execute_code(code, data), with the ability to escape internally with call(address, data) and ffi(data)

I am not sure I understand what these functions would do. Is execute_code an API for the client to execute contract code? Is it an API exposed to contracts?

From my personal perspective I have two goals:

  1. reduce the opportunity for contracts to deal with raw code
  2. make use of webassembly imports/exports and reduce the need to come up with arbitrary ABI encoding

The main reason for 1) is to simplify the points in the system where code validation must occur.

While I would wish to create really nice high level abstractions with 2), this may be limited by execution overhead that we must also take into consideration.

Did a semi-long write up of a potential async interface here: ewasm/design#185

@cdetrio
Copy link
Member

cdetrio commented Mar 24, 2019

what kind of an interface would EWASM have with respect to the wider system? The simplest possible interface for example would be the ability to run execute_code(code, data), with the ability to escape internally with call(address, data) and ffi(data); then everything else (eg. providing environment variables, reading/writing storage) can be done at the outside level with the FFI.

Ewasm is just wasm (it works on any generic wasm engine). It looks like this:

Memory = new WebAssembly.Memory({initial: 10}) // 10 pages at 64kb each
Gas = new WebAssembly.Global({value:'i32', mutable:true}, 3141590);
Imports = { Memory, "ethereum": { Gas, callDataCopy, storageLoad, storageWrite, callToContract, returnDataCopy, finish, revert, useGas } }

code = db.get(address) // code has useGas statements that were injected at deployment time
contractModule = new WebAssembly.instantiate(code, imports).
contractModule.run("main") // execute_code(code, data)

// Ewasm host functions implemented here
function useGas(amount) {
  Gas.value -= amount
  if (Gas.value < 0) throw "OOG"
}
function callDataCopy(offset) {
  Memory.set("0x00000calldata", offset)
}
function finish(resultOffset) {
  console.log("contract call returned data:", Memory.get(resultOffset))
}
function storageLoad() {}
function callToContract() {} // call(address, data)
...

If the interface is settled, then work on everything-outside-the-VM and everything-inside-the-VM could just proceed separately. How far away is the EWASM team from being able to lay down an opinion on this?

Well the wasm interface is settled (for wasm 1.0). You can do ret = ffi(data), where ret and data are one of four types: i32, i64, f32, f64. In Ewasm (a subset of wasm) you're restricted to i32 and i64. Also, you can pass multiple arguments ffi(data1, data2, ...), but only one return value (wasm 2.0 might support multiple return values). If you want to pass an argument that is more than 32 bits of data, you pass a pointer to a memory location.

The Ewasm interface is the set of FFI functions ("host functions" in webassembly docs). For Ewasm 1.0, the host functions basically mirror those EVM opcodes that can't be reduced to pure wasm instructions. There's like 32 of them, so the Ewasm 1.0 interface is 32 host functions minus a couple redundancies (e.g. CALLDATACOPY => callDataCopy(resultOffset, dataOffset, size) and CALLDATALOAD => callDataCopy(resultOffset, dataOffset, 32)).

For Ewasm 2.0, the set of FFI/host-functions would depend on how phase 2 works. Personally, I consider the host functions as outside-the-VM (i.e. host functions are a part of the client, not a part of the VM).

Then what falls inside-the-VM that can proceed separately? Mainly just making code run faster (optimizing interpreters, making compilers robust) and making sure that code terminates (metering, and reducing the slowdown between metered and unmetered code).

@benjaminion
Copy link
Contributor

A relatively minor issue, but learning lessons from Eth 1, how about a mandatory checksum for Eth 2.0 addresses?

EIP55 retro-fitted a checksum format to Eth 1, but this is still not fully adopted/enforced. Including a checksum as part of the protocol would be a step forward for user safety. I realise that the Eth 2 address format is not yet specified, this notwithstanding.

@cdetrio
Copy link
Member

cdetrio commented Apr 26, 2019

I would argue that Eth2 validator addresses at phase 0 should have mandatory checksums, and the checksum should be verified by the Eth1 deposit contract.

@ChihChengLiang ChihChengLiang added the general:RFC Request for Comments label May 17, 2019
@hwwhww
Copy link
Contributor

hwwhww commented May 25, 2023

closing this ancient issue

@hwwhww hwwhww closed this as completed May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
general:RFC Request for Comments phase2
Projects
None yet
Development

No branches or pull requests

8 participants
@axic @cdetrio @vbuterin @lrettig @ChihChengLiang @hwwhww @benjaminion and others