Solidity vs JS

momentummomentum Member Posts: 5
I'm at a bit of a loss as to why intermediary languages are being used instead of the original language they are modeled after. I figured with the simple availability of V8, JS would have been easier to implement over building a unique compiler/interpreter for Solidity.

What am I missing?

Comments

  • jpritikinjpritikin Member Posts: 29
    I think it is important to limit access to regular system APIs like open, read, write, etc. Since ethereum is a singleton computer implemented on many computers, the memory model and system APIs are unique. I'm not saying that it wouldn't be possible to remove lots of stuff from JS to make it suitable, but it might be more work than starting from scratch. That's just a guess though.
  • momentummomentum Member Posts: 5
    edited December 2014
    System APIs don't really exist in native JS - and my understanding is that the run-time constraints are defined by the environment the contract would run in (i.e. Mist or AlethZero) anyway. [i.e. FF or Chrome define the constraints of the JS engine they run and restrict access to the local system resources - I'd expect the environments would run similarly]

    Maybe there's a critical piece of the puzzle I'm missing? I'm still very new to Ethereum.
  • jpritikinjpritikin Member Posts: 29
    I was thinking about this more. Maybe the unusal part is measuring the cost of each instruction as it is executed. Certainly JS doesn't do that.
  • JasperJasper Eindhoven, the NetherlandsMember Posts: 514 ✭✭✭
    It's a completely new 'virtual machine' due to needing an high certainty of sandboxing, determinism, and needing the gas use measured. So then you need to compile to the bytecode, and existing languages dont do that, i am not sure how difficult it is to change them.(though it might be easier for us to reimplement, than learn how to do it with other peoples' compilers)
  • momentummomentum Member Posts: 5
    Well, the ball is already in motion & I'm not trying to make a case for changing anything. I just feel like I'd better understand Ethereum if I understood some of the underlying technical decisions.
  • StephanTualStephanTual London, EnglandMember, Moderator Posts: 1,282 mod
    @momentum‌, it's to do with contracts being deterministic. We cannot have any randomness in the contracts processing, because if we did, the network would never get into consensus as to their results. So for example, we can't have network access from the contracts, because what my computer sees on the internet is probably completely different from a user in say, China. Similarly, you won't find rand() functions in smart contract languages for that exact same reason.

    I hope this helps :)

  • momentummomentum Member Posts: 5
    It does - thanks.
  • chrisethchriseth Member Posts: 170 ✭✭✭
    The EVM is just too different from existing architectures: There are three memory areas which are all accessed differently and have different cost models. The Java virtual machine has a comparable memory model, but it is still too different to be usable, I would say. Also the fact that contracts can call each other without sharing memory is also not really common among existing architectures.
  • linageelinagee Member Posts: 31 ✭✭
    edited December 2014


    Similarly, you won't find rand() functions in smart contract languages for that exact same reason. "

    @StephanTual: If you need something random, I've heard you can use the hash of the current block. (Maybe put it through a few custom math operations to make your "random" slightly more unique.)
  • JasperJasper Eindhoven, the NetherlandsMember Posts: 514 ✭✭✭
    @linagee is that hash available now? I dont think so, you have the hash of the previous block. But obviously that one is known, so you need to use the hash of the previous block, as obtained from a call that you do in the future.

    For larger amounts, or if many people are doing it in a way that alliances with miners can be created,(i.e. many-to-a-gambling-service) miners may drop blocks, when the outcome of the random value does not suit their clients.("miner collusion") This would affect the probabilities. Commiting to random values H(R) and later releasing them, or using a RANDAO(that page needs some improvement..) to have other people do that for you, can make such collusion much more expensive. Instead of losing just a block reward, the RANDAO can be programmed to lose more value than that.
  • linageelinagee Member Posts: 31 ✭✭
    Jasper said:

    @linagee is that hash available now? I dont think so, you have the hash of the previous block.

    Sorry, that's what I mean. Hash of the previous block.
Sign In or Register to comment.