github.com/line/ostracon@v1.0.10-0.20230328032236-7f20145f065d/crypto/vrf/README.md (about)

     1  # VRF
     2  
     3  VRF implementation is set by `func init()` with `build` option
     4  
     5  ## Interface
     6  * package/file
     7    * line/ostracon/crypto/vrf
     8      * `var defaultVrf vrfEd25519`
     9      * vrf.go
    10      * vrf_test.go
    11  ```go
    12  type vrfEd25519 interface {
    13  	Prove(privateKey []byte, message []byte) (Proof, error)
    14  	Verify(publicKey []byte, proof Proof, message []byte) (bool, error)
    15  	ProofToHash(proof Proof) (Output, error)
    16  ```
    17  
    18  ## Implementations
    19  
    20  Use `func init()` with `build` option
    21  
    22  * package/file
    23    * line/ostracon/crypto/vrf
    24      * (r2ishiguro = default)
    25        * `//go:build libsodium`
    26        * `// +build !libsodium,!coniks`
    27        * `func init() { defaultVrf = newVrfEd25519r2ishiguro() }`
    28        * `const ProofSize = 81`
    29        * vrf_r2ishiguro.go
    30      * (coniks)
    31        * `//go:build coniks`
    32        * `// +build coniks`
    33        * `func init() { defaultVrf = newVrfEd25519coniks() }`
    34        * `const ProofSize = 96`
    35        * vrf_coniks.go
    36        * vrf_coniks_test.go
    37      * (libsodium)
    38        * `//go:build libsodium`
    39        * `// +build libsodium`
    40        * `func init() { defaultVrf = newVrfEd25519libsodium() }`
    41        * `const ProofSize = int(libsodium.PROOFBYTES)`
    42        * vrf_libsodium.go
    43        * vrf_libsodium_test.go
    44  
    45  ### Status
    46  
    47  | impl | available | memo |
    48  |:---|:---|:---|
    49  |r2ishiguro|o|(default)|
    50  |coniks|x|no compatibility between *crypto ED25519* and *coniks ED25519* (See `TestProveAndVerify_ConiksByCryptoED25519`)|
    51  |libsodium|o| need to build libsodium (See `libsodium` task of `Makefile`)|
    52  
    53  ### Attention
    54  
    55  * There is no compatibility between *r2ishiguro.Prove/libsodium.Verify* and *libsodium.Prove/r2ishiguro.Verify* (See `TestProveAndVerifyCompatibilityLibsodium`)
    56  * Ostracon Network should use `r2ishiguro` or `libsodium` (Can't use both at the same time in Ostracon Network)
    57  
    58  ### libsodium (bind C implementations)
    59  * package/file
    60    * line/ostracon/crypto/vrf/internal/vrf
    61      * `// +build libsodium`
    62      * vrf.go
    63      * vrf_test.go
    64      * libsodium: submodule (See `.gitmodule`)
    65      * sodium: libs (See `libsodium` task of `Makefile`)
    66  
    67  ## How to test
    68  
    69  ```shell
    70  # r2ishiguro
    71  go test github.com/line/ostracon/crypto/vrf -tags r2ishiguro
    72  # libsodium
    73  go test github.com/line/ostracon/crypto/vrf -tags libsodium
    74  # internal libsodium only
    75  go test github.com/line/ostracon/crypto/vrf/internal/vrf -v -tags libsodium
    76  
    77  # coniks is not available, but if you want to do, you can see no-compatibility
    78  go test github.com/line/ostracon/crypto/vrf -tags coniks
    79  ```
    80  
    81  ## How to benchmark
    82  
    83  ```shell
    84  # r2ishiguro
    85  go test -bench Benchmark github.com/line/ostracon/crypto/vrf -run ^$ -benchtime=1000x -count 10 -benchmem -v
    86  # libsodium
    87  go test -bench Benchmark github.com/line/ostracon/crypto/vrf -run ^$ -benchtime=1000x -count 10 -benchmem -v -tags libsodium
    88  ```
    89  
    90  ## How to build
    91  
    92  ```shell
    93  # r2ishiguro
    94  make build
    95  # libsodium
    96  LIBSODIUM=1 make build
    97  ```