Why not use a general purpose VM?

Maybe it's a naive question and maybe it's been answered a million times, but I haven't found it asked/answered explicitly. If it has, please give a link.

Why not use a general purpose VM and let people write code in the language of their choice?

Best Answer

Answers

  • JasperJasper Eindhoven, the NetherlandsMember Posts: 514 ✭✭✭
    If you mean stuff like virtualbox, remember, Ethereum is for very small amounts of calculation that has to be done with consensus to be useful. General purpose programs are too slow. Also, stuff like virtualbox probably have some bugs.

    Otherwise, there are (at least)two reasons.
    1. It has to run identically, exactly. On all full nodes. Otherwise you get a fork.
      Even in the face of attack, and anyone can put arbitrary EVM code on there.
    2. We need to keep track of how much computation effort it is to run, otherwise attacks would try to. To do this, we keep track of gas, and at the beginning, the user indicates how much it at max costs. If it doesnt reach that, the difference is refunded, otherwise, all gas is still bought and burned. (This ensures that infinite loops and stuff isnt cost-effective at attacking, aswel as regulating the level of activity on Ethereum.)
    3. We need to keep track of an Ethereum state, and it has to be rewindable. We also want to be able to have lightweight client. This puts additional contracts.
    So to keep good control on those issues, we basically to do it ourselves. A stack machine isnt that complicated a thing, btw.(infact bitcoin has one too) That said, if you(/anyone) can retarget existing languages to Ethereum, you're welcome :)

    Finally, libraries arent exactly aimed at what we want. Infact Bitcoin was kindah stung by this, with transaction mallabilty. Basically, the openssl does make signatures properly, and it does check properly, however you can fiddle a bit at 'unimportant' bits of data and it will still find the signature correct. However, parts bitcoin assumed you could not fiddle at it.
  • tenaciousmvtenaciousmv Member Posts: 4
    Hi Jasper, thanks for the quick reply.

    Suppose we would use Docker containers instead of Ethereum's custom VM. Bear with me as I explore this hypothesis, and tell me where it would break.

    1. It has to run identically on all full nodes.

    Docker provides images capability. Images are built deterministically with a script. Every full node can start with the same base image, and dapps/contracts would be installed on top of that shared image with a publically available script. Each dapp/contract would run in a separate Docker container.

    2. We need to keep track of how much computation effort a contract uses.

    Docker provides monitoring and resource limiting tools for RAM, I/O and disk. The same approach of max-gas and upfront gas payments with the reimbursement at the end of transaction, or a transaction rollback if it ran out of gas, could apply. If a Docker container uses too many resources, it can be paused and rolled back to a previous snapshot.

    3. We need to keep track of Ethereum state, and it has to be rewindable.

    Docker provides copy-on-write instant snapshots. We could do a snapshot after each transaction, and after each block. So we could rollback both individual transactions and block chains that lost proof-of-work race with other nodes.

    Jasper, do you mind if I link to this discussion on hackernews? I feel like this could benefit from some discussion from the rest of the Bitcoin community.
  • StephanTualStephanTual London, EnglandMember, Moderator Posts: 1,282 mod
    What Jasper said, plus, remember the VMs in Ethereum are barebone by design: they need to run fast, be very easily audited, and have no requirements for 'bells and whistles'. That's why we didn't opt for the JVM.

    I've heard of plans to potentially standardize through http://llvm.org/, but nothing concrete. Right now I think the VMs are appropriate, even ideal, for the job.
  • tenaciousmvtenaciousmv Member Posts: 4
    Hey guys, sorry for the long radio silence.

    Let's continue on https://news.ycombinator.com/item?id=8292916
  • JasperJasper Eindhoven, the NetherlandsMember Posts: 514 ✭✭✭
    Kindah think you're underestimating the problem. *Anyone* can throw in his program and have a go at taking down the entire system if it goes wrong once.

    Dont really know how to say more than i already said. (Well, native extensions are sort of a related topic.)
  • tenaciousmvtenaciousmv Member Posts: 4
    I get it, resource management is a big a problem that applies to CPU, RAM and storage. Capabilities to do such resource management exist, though they may not be refined to the extent the blockchain needs. We will be reaching out to ZeroVM, Docker and other sandboxing projects to better assess the ETA of feature-completeness in this domain.

    (reposting to https://news.ycombinator.com/item?id=8292916)
Sign In or Register to comment.