9

I just started studying about smart contracts and from what I understand, smart contracts only deal with the data present on the blockchain. While working on a private blockchain, I want to know whether a smart contract in the blockchain can access external data and make changes to it. By external, I mean the data present on the nodes in the blockchain network, not data from the internet. So, no oracles. Since smart contracts are deterministic and gets executed on every node, assume I have the same file in the "datadir" of every node on the network. Can I access this file from a smart contract and make changes to it if necessary?

5

You are right. Out of the box, Ethereum is completely isolated.

https://solidity.readthedocs.io/en/latest/introduction-to-smart-contracts.html#index-6

The Ethereum Virtual Machine

Overview

The Ethereum Virtual Machine or EVM is the runtime environment for smart contracts in Ethereum. It is not only sandboxed but actually completely isolated, which means that code running inside the EVM has no access to network, filesystem or other processes. Smart contracts even have limited access to other smart contracts.

An alternative could be having an external machine listen for events in the blockchain. It can decide what to do based on those.

3

In theory if you're running a private chain your validators control the validation software, so you can program it to do whatever you like. However, since it's designed for a public chain that expects validation to be deterministic and self-contained, the Ethereum software as originally shipped doesn't, on its own, give you a way to do this.

One thing you might want to look at would be native contracts in Hydrachain, where IIUC you can write arbitrary python code and get your validators to run it, and use the results in contracts.

Another approach looks a bit like oracles, but it doesn't change your trust model in the way that oracles normally would: Get each of your validators to run a parallel system that watches the public blockchain and publish signed data (or send signed transactions, it comes to the same thing) testifying to what they saw. Then in your contract, check each that each thing you want to verify has been signed off on by 51% of validators. You can be screwed if 51% of your validators collude to lie about what they saw on the public blockchain, but your private blockchain is broken under those conditions anyway.

  • How exactly are the native contracts helpful in this scenario? Did you mean to say that native contracts can read/write external data since they're not getting executed on the EVM? Also, can we configure native contracts to run on a specific node rather than every node on the network? – galahad Jun 14 '16 at 19:36
  • Yes, exactly. So I'm thinking you'd have some native code that would be basically reading the external Ethereum blockchain, and you could send it transactions saying, "Give me the response to a call to contract X with these parameters". I suspect the parallel validators-as-oracles approach is simpler, though. – Edmund Edgar Jun 15 '16 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.