5

Been thinking about this for a while, and came on this question: Can a contract access another contract's storage?.

What is the design rationale behind NOT allowing these types of reads? It seems trivial to implement on ETH currently. Now if ETH decided to shard later on then yes there might be problems with concurrent ordering between shards, but right now in a single monolithic chain, this is trivial to do.

Can someone explain to me if this design decision to NOT allow a contract to read another account's state is driven by technical or philosophical reasons? Thanks!

2 Answers 2

1

Historically it's considered good practice to keep variables private by default in object oriented programming. One reason is that we often want to maintain tight control over how our variables are manipulated in order to avoid unexpected changes. See this question or this question for more discussion.

I think contract variables are private by default for similar reasons. There might be situations where we don't want external contracts to read our contract variables, so for safety we need to explicitly declare which variables are public (or define our own getters, etc).

2
  • I don't have a detailed technical understanding of ETH, so what you're saying is that there is no easy way to parse the smart contract on the blockchain to figure out what the current state is? Can you simply query a full node for that current state? (assuming the full node keeps it in some readable representation in a DB beyond just bytecode)
    – reedvoid
    Commented Oct 17, 2018 at 22:56
  • AFAIK there's no direct way for one contract to read non-public variables from another contract. But from outside the blockchain it's possible to read the state of a contract with JavaScript, etc. See this question or this question. Commented Oct 18, 2018 at 4:21
0

I can add that, giving that the compiler generates automatically getters to access any variable declared “public” in a contract, (i.e. other contract can read storage if you want to) the situation is very clear: you can share whatever you decide to share, but other are prevented to write in your private world. That is the maximum you can have if you are working on valuable data and processes.

On the other side your account must be accessible in reading publicly (and indeed you can have the balance and the transaction list and so on for any EOA or SC), but it is trivial that if someon could be able to write in it without your permission, the account is no longer an account, I.e. a space where one person or entity is the only responsible person.

So the general philosophy is: all the world can read, but the owner only can write. EOA or Smart Contract, the same philosophy.

2
  • Unsure if this answers the question, I'm asking about read access, not write access.
    – reedvoid
    Commented Oct 17, 2018 at 22:54
  • What is not clear to you, then? I explained both of them, read and write. The general philosophy it that: you can read ALL (no cryptography implied that prevent readability), but you can interact with selected (by the owner of the smart contract or by default for EAO, i.e. physical person’ accounts, said in a somehow simpler way). What answer did you expect?
    – Rick Park
    Commented Oct 18, 2018 at 5:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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