VIDEO

How to Use Timelocks in Ligo | Video Tutorial

Check out a video explainer to learn how Tezos Timelocks work and how you can implement them using Ligo.

By Benjamin Fuentes

A Timelock is a cryptographic primitive that can be used as part of a ‘commit and reveal’ scheme to provide a guarantee that the information associated with the commit is eventually revealed. Lucky for us, Timelocks have been re-enabled on Tezos following the implementation of the Oxford 2 upgrade.

Watch this video to learn how to implement Timelocks using Ligo:

Slides transcript #

Using Timelock, you can temporarily conceal a smart contract’s payload until it is ready to be included in a block. The payload is then decrypted and the smart contract can operate as before. It’s a replacement of sorts for the commit-and-reveal scheme. The latter requires an interactive engagement of participants and can lead to a blocking state.

The Timelock implementation is interactive, allowing access to anyone with the key - blocking is also prevented here because after a set period, a third party can solve the puzzle.

Use case: The Shifumi (rock-paper-scissors) game #

The current game version employs the commit-and-reveal pattern. Two players make moves without revealing information to each other to prevent cheating.

The Android game is available to try already: Shifumi game

Ligo API #

Types #

//A timelocked chest.
type chest
//A key to open a timelocked chest.
type chest_key

Functions #

//Open a timelocked chest given its key and the time difficulty and return the secret payload
let open_chest: (key: chest_key, chest: chest, time: nat) => option<bytes>;

Ligo Test API #

//Function which given a payload and time difficulty, generates a chest and chest_key.
let create_chest: (payload: bytes, time: nat) => [chest, chest_key];

//Function to search for the key of the given chest and time difficulty.
let create_chest_key: (chest: chest, time: nat) => chest_key;

Coin flip game #

  1. An administrator initializes a chest containing Head or Tail;
  2. A player submits a guess. Ex: Head
  3. They have two choices:
  4. The administrator sends the key to open the chest;
  5. Someone tries to find the NAV;
  6. The game is resolved with the key and the result is updated.

Demo #