The commit-and-reveal scheme
In the commit-and-reveal scheme, first, a hash of the original secret is submitted to the blockchain. This secret hash is recorded and stored on-chain in the contract. Once all the players or parties have submitted their secret hash, they all have to reveal their choice by submitting salt, using which they have generated the secret hash. A salt is like a password; using this an user can generate a secret hash. This secret is generated by combining the data (to be hidden) and salt and taking hash of this combined data. You can use any hashing algorithm to generate hashes. We have used keccak256 hashing algorithm in the sample code
This way of first committing the secret hash and later revealing it prevents players ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access