3

If I use private variable, can attacker or anyone be able to know what the variable is?

For example.

I declare a private variable named "secret" without initialize its value.

Later after I created the contract, I then interacted with my contract by set the "secret" variable to "hello". Suppose I did this using ether wallet with metamask.

setSecret("hello")

In theory, I know that anyone can't get my private secret by interacting with my Secret contract. But since I set the secret to "hello" in the previous transaction. Will the word "hello" get record in a log file, transaction, or somewhere which can be dig up?

I'm just trying to understand how to keep a secret inside my contract.

This is my example contract

pragma solidity ^0.4.15;

/**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control
 * functions, this simplifies the implementation of "user permission"
 */
contract Ownable {

    address public owner;

    /**
     * @dev The Ownable constructor sets the original 'owner' of the contract to the sender
     * account.
     */
    function Ownable() internal {
        owner = msg.sender;
    }

    /**
     *  @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(msg.sender == owner);
        _;
    }

}

contract Secret is Ownable {

  string private secret;

  function Secret() public {
    secret = "";
  }

  function setSecret(string _secret) public onlyOwner {
    secret = _secret;
  }

}
3

All data stored inside a smart contract is stored in the blockchain.

All data in the blockchain is publicly accessible.

Making a variable private just means it will not be included in your ABI. Anyone can still determine its value.

To store a secret on the blockchain, you must encrypt it off-chain and store the decryption key off-chain.

1
  • 1
    Basically, everything in my contract as well as all the variables are visible to the world. – Geeroz Oct 13 '17 at 8:32

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.