You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This repository contains basic code for verifiable random function(vrf.go), and a simple selection mechanism(sortition.go).
2
+
This repository contains basic code for verifiable random function(vrf.go), and a simple selection mechanism(sortition.go).
3
3
4
-
Note that vrf implementation is originally from Yahoo's work(2017, Apache 2.0), which retrieved from[here](https://github.com/r2ishiguro/vrf/tree/master/go/vrf_ed25519).
4
+
Note that this vrf implementation is originally from Yahoo's work(2017, Apache 2.0), which can be retrieved[here](https://github.com/r2ishiguro/vrf/tree/master/go/vrf_ed25519).
5
5
6
-
In this repository, I modified it because 1) it was far away from go convention(I'm not good at the convention though), 2) It was not good for utilizing vrf output, which can be used for cryptographic sortition or selection mechanism in blockchain technologies.
6
+
In this repository, I modified it because 1) it was far away from the go convention (though I'm not good at the convention), 2) it was not good for utilizing vrf outputfor cryptographic sortition or selection mechanisms in blockchain technologies.
7
7
8
-
So, here's the change log. 1) all the function names changed to be carmelCase instead of snake_case. 2) all the functions became private except Prove(), Hash(), Verify(). 3) Prove() function now returns not only proof(pi) but also vrf output so that users can easily use them without calling Hash() function.
8
+
This is the change log: 1) All the function names were changed to be carmelCase instead of snake_case. 2) All the functions became private except Prove(), Hash(), Verify(). 3) Prove() function now returns not only proof(pi) but also vrf output so that users can easily use them without calling Hash() function.
9
9
10
-
In addition, I made a simple selection mechanism(can be called a kind of cryptographic sortition). This may help you to understand how to use vrf output. For more details, [click here](https://github.com/yoseplee/vrf#3-a-simple-selection-mechanism).
10
+
In addition, I made a simple selection mechanism (this can be called a kind of cryptographic sortition). This may help you to understand how to use vrf output. For more details, [click here](https://github.com/yoseplee/vrf#3-a-simple-selection-mechanism).
11
11
12
-
Any kind of contribution will be welcomed. Thanks!
12
+
Any kind of contribution will be welcome. Thanks!
13
13
14
14
# Appendix
15
15
## 1. Available VRF Implementations
@@ -24,50 +24,50 @@ Any kind of contribution will be welcomed. Thanks!
24
24
* uses SHA512 instead of SHA256
25
25
## 2. Concept of VRF(Verifiable Random Function)
26
26

27
-
* A pseudorandom number can be verified by anyone who has sender's public key
28
-
* A sender can generate a pseudorandom number with his/her private key and message
29
-
*its result(a random number) and the proof is returned and throw them to a receiver
30
-
*A receiver can verify the number that sender generated that pseudorandom number with (sender's public key, proof, pseudorandom number, message)
27
+
* A pseudorandom number can be verified by anyone who has a sender's public key
28
+
* A sender can generate a pseudorandom number with their private key and message
29
+
*the result(a random number) and the proof is returned and both are sent to a receiver
30
+
*The receiver can verify the number the sender generated with the sender's public key, proof, pseudorandom number, and message
31
31
32
32
### 2.1. Functions in VRF
33
-
> Generally, VRF implementation has 3 function below
34
-
1. Keygen(VRF_GEN): generates key pair(secret key, public key)
35
-
2. Evaluate(VRF_EVAL): generates pseudorandom number and its proof
36
-
3. Verify(VRF_VER): verify the random number with proof
33
+
> Generally, VRF implementation has the 3 functions below
34
+
1. Keygen(VRF_GEN): generates a key pair(secret key, public key)
35
+
2. Evaluate(VRF_EVAL): generates a pseudorandom number and its proof
36
+
3. Verify(VRF_VER): verifies the random number with proof
37
37
38
-
### 2.2. Three Properties of VRF
38
+
### 2.2. The Three Properties of VRF
39
39
> [Gorka Irazoqui Apecechea's article posted to Medium - see how it works would be great for you](https://medium.com/witnet/cryptographic-sortition-in-blockchains-the-importance-of-vrfs-ad5c20a4e018)
40
40
1. Collision resistance: it is hard to find two inputs that map to the same output
41
-
2. Pseudorandomness: the output is indistinguishable from random by anyone not knowing the secret key
42
-
3. Trusted Uniqueness: That requires that, given a public key, a VRF input m corresponding to a unique output for the same input value, result should be unique
41
+
2. Pseudorandomness: the output is unidentifiable as a random number for anyone not knowing the secret key
42
+
3. Trusted Uniqueness: This requires that, given a public key, for a VRF input m corresponding to a unique output for the same input value, the result should be unique
43
43
44
44
## 3. A simple selection mechanism
45
-
> This also called as cryptographic sortition
45
+
> This is also called cryptographic sortition
46
46
### 3.1. Calculate Random number from hash(vrf output)
* Can calculate a random ratio range in [0, 1] from vrf output which is unique for a message, and verifiable for all the others who have issuer's public key and its proof
48
+
* Can calculate a random ratio range [0, 1] from the vrf output which is unique to a message and verifiable for everyone who has the issuer's public key and its proof
49
49
* The Ratio can be calculated as follows:
50
50
* ratio = hash / (2^hashlen)
51
51
* And **its probability is uniformly distributed**
52
52
> To calculate the result by yourself, just run the main function. It's ready for you! e.g. $go run .
53
53
54
54
### 3.2. Implement the selection mechanism
55
55

56
-
* Now we can implement a cryptographic sortition using VRF by setting a threshold or range which can represents selection by itself
56
+
* Now we can implement a cryptographic sortition using VRF by setting a threshold or range which can represent a selection by itself.
57
57
* Example
58
-
*let's say we have set range [0, 0.1] and any ratios which value is in it means the selected one
59
-
* Peer 'A' calculated ratio and its value is 0.03
60
-
* Then 'A' can claim that he/she is selected and can verify it by providing the proof
61
-
* Peer 'B' calculated ratio and its value is 0.5
62
-
* Then 'B' cannot claim that he/she is selected as its value is out of range [0, 0.1]
58
+
*Let's say we have set a range [0, 0.1] and any ratio whose value falls in that range is a selected value
59
+
* Peer 'A' calculated a ratio and its value is 0.03
60
+
* Then 'A' can claim that they have selected a value and can verify it by providing the proof
61
+
* Peer 'B' calculated a ratio and its value is 0.5
62
+
* Then 'B' cannot claim that they have selected a value as its value is outside of the range [0, 0.1]
63
63
64
64
### 3.3. Result
65
-
* In the code written in sortition, the threshold set for 0.3, which means that only participants who got the value under 0.3 will be selected
66
-
* To execute experiment to see if its expected rate of selection, test code is ready for run sortition for 1000 times and count the ratio of success
65
+
* In the code written in the sortition, the threshold was set to 0.3, which means that only participants who got a value under 0.3 will be selected
66
+
* To see if it falls in the expected selection ratio, I ran the test code, which runs sortition 1000 times and counts the ratio of success
67
67
```sh
68
68
# at the root directory of the project
69
69
cd sortition/
70
70
go test
71
71
```
72
-
* As the random variable from vrf output is from the uniform distribution, expected ratio of success will be almost the same as the threshold
73
-
*if you are very lucky, you would see fail as this is probability case.
72
+
* As the random variable from vrf output is from a uniform distribution, the expected ratio of success will be almost the same as the threshold
73
+
*As this is probability-based test, there is a small chance that you get lucky and see it fail.
0 commit comments