morley-1.16.1: Developer tools for the Michelson Language
Safe HaskellNone
LanguageHaskell2010

Morley.Tezos.Crypto.Timelock

Description

Timelock puzzle algorithms implementation.

This module follows the reference implementation for the most part, which you can find in the [tezos repository](https:/gitlab.comtezostezos-blobb1a2ff0334405cafd7465bfa991d23844f0b4e70srclib_crypto/timelock.ml).

For a more high-level overview of the concepts, refer to the timelock documentation page.

The general idea is built upon Rivest, Shamir, Wagner "Time-lock puzzles and timed-release Crypto", there are however some differences from the paper:

  • The paper suggests using RC5 cipher, which Tezos implementation eschews in favor of NaCl's "secret box".
  • The paper suggest generating the symmetric secret key \(K\) directly, then encrypting it with a randomly chosen value \(a\) as \(C_K = K + a^{2^t} \pmod n\). Tezos implementation instead randomly generates only \(a\), and then produces the secret key using BLAKE2b KDF with a fixed key from \(a^{2^t} \pmod n\).
  • Since the secret key is determined only by the "unlocked" value, the time-locked value representation also differs. In the paper it's represented as ((n,a,t,C_K,C_M)), i.e. the tuple of modulus, "locked" value, time, encrypted key and encrypted message. In Tezos implementation it's instead ((a,n,C_M)), and \(t\) is treated as a separate argument.
  • Likely to guard the protocol from guessing attacks, additional "proof" verification is added, described in [Boneh, Bünz, Fisch "A Survey of Two Verifiable Delay Functions"](https:/eprint.iacr.org2018/712.pdf)
Synopsis

Documentation

newtype TLTime Source #

Number of steps a timelock needs to be opened without knowing a "secret", i.e. modulo factorization.

The reference implementation uses OCaml int, and it can only be positive, so on 64-bit architecture it's actually a 62-bit natural. We use Word64 to represent it.

Constructors

UnsafeTLTime 

Fields

Bundled Patterns

pattern TLTime :: Word64 -> TLTime 

Instances

Instances details
Bounded TLTime Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Eq TLTime Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

(==) :: TLTime -> TLTime -> Bool #

(/=) :: TLTime -> TLTime -> Bool #

Num TLTime Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Show TLTime Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Buildable TLTime Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

build :: TLTime -> Builder #

HasCLReader TLTime Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

data Chest Source #

A locked chest

Constructors

Chest 

Fields

Instances

Instances details
Eq Chest Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

(==) :: Chest -> Chest -> Bool #

(/=) :: Chest -> Chest -> Bool #

Show Chest Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

showsPrec :: Int -> Chest -> ShowS #

show :: Chest -> String #

showList :: [Chest] -> ShowS #

Generic Chest Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Associated Types

type Rep Chest :: Type -> Type #

Methods

from :: Chest -> Rep Chest x #

to :: Rep Chest x -> Chest #

Binary Chest Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

put :: Chest -> Put #

get :: Get Chest #

putList :: [Chest] -> Put #

NFData Chest Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

rnf :: Chest -> () #

IsoValue Chest Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

Associated Types

type ToT Chest :: T Source #

TypeHasDoc Chest Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

type Rep Chest Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

type Rep Chest
type ToT Chest Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

type ToT Chest = 'TChest
type TypeDocFieldDescriptions Chest Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

data ChestKey Source #

A chest "key" with proof that it was indeed opened fairly.

Constructors

ChestKey 

Fields

Instances

Instances details
Eq ChestKey Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Show ChestKey Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Generic ChestKey Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Associated Types

type Rep ChestKey :: Type -> Type #

Methods

from :: ChestKey -> Rep ChestKey x #

to :: Rep ChestKey x -> ChestKey #

Binary ChestKey Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

put :: ChestKey -> Put #

get :: Get ChestKey #

putList :: [ChestKey] -> Put #

NFData ChestKey Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

rnf :: ChestKey -> () #

IsoValue ChestKey Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

Associated Types

type ToT ChestKey :: T Source #

TypeHasDoc ChestKey Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

type Rep ChestKey Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

type ToT ChestKey Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Value

type TypeDocFieldDescriptions ChestKey Source # 
Instance details

Defined in Morley.Michelson.Typed.Haskell.Doc

data Ciphertext Source #

Ciphertext with nonce.

Constructors

Ciphertext 

Fields

Instances

Instances details
Eq Ciphertext Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Show Ciphertext Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Generic Ciphertext Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Associated Types

type Rep Ciphertext :: Type -> Type #

Binary Ciphertext Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

NFData Ciphertext Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

Methods

rnf :: Ciphertext -> () #

type Rep Ciphertext Source # 
Instance details

Defined in Morley.Tezos.Crypto.Timelock

data OpeningResult Source #

The result of opening the chest.

Constructors

Correct ByteString

The chest was opened correctly.

BogusCipher

The chest was opened correctly, but the contents do not decode with the given symmetric key.

BogusOpening

The chest was not opened correctly, i.e. proof verification failed.

createChestAndChestKey Source #

Arguments

:: ByteString

Chest content

-> TLTime

Time (in elementary actions) to open without key.

-> IO (Chest, ChestKey) 

Create a timelock puzzle and a key.

createChestKey :: Chest -> TLTime -> ChestKey Source #

Forge a chest key the hard way.

chestBytes :: Chest -> ByteString Source #

Convert a Chest to binary representation, used by Tezos

chestKeyBytes :: ChestKey -> ByteString Source #

Convert a ChestKey to binary representation, used by Tezos

chestFromBytes :: ByteString -> Either Text Chest Source #

Read a Chest from binary representation, used by Tezos

chestKeyFromBytes :: ByteString -> Either Text ChestKey Source #

Read a ChestKey from binary representation, used by Tezos

openChest :: Chest -> ChestKey -> TLTime -> OpeningResult Source #

Try to (quickly) open a chest with the given key, verifying the proof.

mkTLTime :: (Integral i, Bits i) => i -> Either Text TLTime Source #

Safely creates TLTime checking for overflow and underflow. Accepts a number of any type.

unsafeMkTLTime :: HasCallStack => Word64 -> TLTime Source #

Partial function for TLTime creation, it's pre-condition is that the argument must not exceed bounds of the TLTime.

Internal, not safe for cryptography

createChestAndChestKeyFromSeed Source #

Arguments

:: Int

Pseudo-random seed

-> ByteString

Chest content

-> TLTime

TLTime (in elementary actions) to open without key.

-> (Chest, ChestKey) 

Construct a chest purely based on a seed for pseudorandom generator. This is not suitable for cryptography, used in tests.