DEV Community

Cover image for Solidity: Is a Hidden Variable Possible?
Erhan Tezcan
Erhan Tezcan

Posted on

Solidity: Is a Hidden Variable Possible?

Here is a question that has come to my mind: can we hide some variable in a contract storage?

Formally, can we somehow make a transaction (or series of transactions) such that in the end, there is an arbitrary value stored at some position p of some contract, where the probability of this value being stored at some position q is 1 / 2^256 for all q (or negligibly less than that for some other q)?

Note that we don't care if we know what the value is, we just don't want to show where it is stored within. I also prefer no random oracles in play here.

I actually don't know the answer to this problem! In fact, and I am here to see your comments! So come on, let us brainstorm together 🧠🌪️

My Attempt

My initial idea was to have a storage contract with the following runtime code:

PUSH1 0xFF // our arbitrary value
<some position>
SSTORE
Enter fullscreen mode Exit fullscreen mode

If I delegatecall this guy after somehow assigning a position, I will have the arbitrary value in my storage.

Then, we have to solve how to feed that position value to this contract without making it be noticed in a transaction.

What I have attempted:

  • I tried to see if I can somehow use balance as a position, and try to send ether without showing it. selfdestruct is the only way to do this implicitly, but it can be seen under internal transactions.
  • Even if we somehow get the balance to our contract, we have to get rid of it in the same transaction so that it can't be seen afterwards, and we can't do that. Even if selfdestruct were to work, the storage would get cleaned up too.
  • Okay then, maybe I can get the balance of some other address and use it as my position? How do we provide that address without showing though.
  • ...

Note that this is just out of curiosity and for the sake of challenge. At the time of writing this, I am %99 sure this is not possible at all. Nevertheless, what I can't formally prove I can't be sure about; so here we are.

Other points of interest:

  • Can I somehow make use of inline assembly to set .slot of a variable to hide it?
  • (might add more here as I edit the post)

Top comments (0)