Let's say in a contract's storage you keep data for each address (user) of the contract. Let's say there is a token to go along.

Would it be possible to restrict access to the lookup of the storage data for a particular user so that someone needs to send a small amount of the (custom) token to the contract first?


Short answer. Not possible to restrict access to data stored in the contract.

Details. The mining and verification process involves everyone accessing the data, so the default setting is everything visible to everyone. You can consider an encryption strategy for on chain data but it will be tricky.

You can inconvenience people with restricted access functions but it won't prevent a determined adversary from discovering the stored values.

The discussed zksnarks addition (future) may provide a better solution for selective disclosure.

Hope it helps.

  • thanks for the response. there is a cost for reading the data from the contract since it needs to run some code right? but you can do it manually if you want to parse the blockchain yourself. correct?
    – arisalexis
    May 15 '17 at 8:45
  • Using Solidity, we can impose certain rules about what is allowed and what is forbibben. At a deeper level, the miners and verifiers can explore to world state without our permission. In fact, they have to be able to do that for the mining and verification process to work. So, yes, we could say manual exploration of the chain isn't preventable or costly. Best not to put sensitive information into a transaction or state variable that others can see. May 15 '17 at 21:13

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.