Skip to content
/ vdf Public

A verifiable delay function based on cyclic group Z/nZ

License

Notifications You must be signed in to change notification settings

greensea/vdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vdf

A verifiable delay function based on cyclic group $\mathbb{Z} \big/ n\mathbb{Z}$

Usage

// Init an VDF instance
// See Note section to learn how to pick q and n
p = big.NewInt(5)
q = big.NewInt(11)
v := vdf.New(p, q)


// Eval an proof
x := big.NewInt(7)
t := 1<<20
y := vdf.Eval(x, t)

fmt.Printf("7^(2^(2^20)) mod %v == %v\n", v.N(), y)


// Verify the proof
isValid := vdf.Verify(big.NewInt(7), t, y)

fmt.Printf("isValid == %v\n", isValid)

There is a demo on go playground: https://go.dev/play/p/hLBsSgbHn2a

Math

We have a VDF function initalized with prime P and Q.

Now we calcualte

$$ N = P * Q $$

The eval function calculates:

$$ y = x^{2^{t}} \mod N $$

Where x is a random number, t is hardness.

The time complexity of eval function is $O(t)$.

The verify function calculates:

$$ s = (P - 1) \times (Q - 1) $$

$$ r = 2^{t} \mod s $$

$$ y = x^{r} \mod N $$

The time complexity of verify function is $O(\log{}{t})$.

Note

  • When t == $2^{20}$, and with 512 bits N, it takes about 2 seconds to eval and 1ms to verify on an Ryzen 5 2600 CPU.

  • It is strongly recommend pick P and Q with an RSA key generator.

Generate P and Q with Golang

import (
    "crypto/rsa"
    "crypto/rand"
)

// Generate 512 bits RSA key
rsaKey, err := rsa.GenerateKey(rand.Reader, 512)

p := rsaKey.Primes[0]
q := rsaKey.Primes[1]

fmt.Printf("p = %v, q = %v\n", p, q)

About

A verifiable delay function based on cyclic group Z/nZ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages