0

My thought is that we come up with a random number in one block and make it private so no one can see it. The timer will allow a few blocks to be mined and then the revealNumber function allows the secret number to be known and then generates another random number. I think this would eliminate the possibility for block manipulation? Is there any way that someone could see something that is private?

pragma solidity ^0.5.4;


contract SKYLotto {

  uint256 private secretNumber;
  uint256 public releasedNumber;
  uint256 public time;

    function randomGen() public {
        secretNumber = uint(keccak256(abi.encodePacked(now, msg.sender))) % 10;
        time = now + 30 seconds;
    }    

    function revealNumber() public {
      enter code here  require(now > time);
        releasedNumber = secretNumber;
        randomGen();
    }
}
  • 1
    make it private so no one can see it - that won't work; the only reason to declare a state-variable private is to semantically emphasize that no one should want to see it. But if somebody decides that they do, for some reason, then they can. No way for you to prevent that, so don't count on it for security! – goodvibration Feb 13 at 7:47
1

Yes, someone can see private values. Private simply tells contracts what they can and cannot read. People can extract the data from the private value.

Please see this thread. And also in the api for solidity it states: "Everything you use in a smart contract is publicly visible, even local variables and state variables marked private."

  • Thought that might be the case. Thank you. So oraclize is the way to go for now – CryptoPuff Feb 13 at 11:50

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.