0

I'm working on a smart contract to run a fair lottery game. The winner is chosen by way of random number generation. The current plan is to get the random number from an oracle source. However, this has made me wonder - how does the oracle communicate the number to the blockchain securely?

Because everything in a smart contract is visible (much like anything stored in a HTML file) they cannot hold a private key without it being visible so any public-private key encryption is no longer secure? Therefore how do you know that the externally generated random number has been sent to your smart contract securely and not been intercepted and changed along the way? The scenario that jumps to mind is when the random number is committed to the blockchain but miners could reject it if it didn't result in a win for them (same reason using an external random number generator is recommended). So how does it happen securely?

Any thoughts/explanation/instruction would be great!

1 Answer 1

1

As you have correctly pointed out, in general, you can't transmit secrets in the open because they will quickly become public.

I'm going to set aside the question of randomness source because that is, in itself, a complex puzzle. Also, the question of miners disregarding transactions that make them lose the game is probably addressed more directly at the consensus level.

In terms of your "secret" transmission, here is an idea to consider.

You can safely transmit the hash of a secret and you can make claimants prove they know the secret by producing a data set that correctly hashes to the value held in the contract. Once used, you will want to take care to ensure the same secret is never used again because it will be revealed.

Hope it helps.

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.