proof of work start

This commit is contained in:
Eitan Chatav 2016-11-08 18:18:09 -08:00
parent 56e5fc3213
commit e9ff110d08
3 changed files with 11 additions and 0 deletions

View File

@ -174,6 +174,7 @@ type net = {
and peer = { and peer = {
gid : gid ; gid : gid ;
public_key : Crypto_box.public_key ; public_key : Crypto_box.public_key ;
(*proof_of_work_nonce : Crypto_box.nonce ;*)
current_nonce : unit -> Crypto_box.nonce ; current_nonce : unit -> Crypto_box.nonce ;
point : point ; point : point ;
listening_port : port option ; listening_port : port option ;

View File

@ -13,6 +13,7 @@ type secret_key = Sodium.Box.secret_key
type public_key = Sodium.Box.public_key type public_key = Sodium.Box.public_key
type channel_key = Sodium.Box.channel_key type channel_key = Sodium.Box.channel_key
type nonce = Sodium.Box.nonce type nonce = Sodium.Box.nonce
type difficulty = int
let random_keypair = Sodium.Box.random_keypair let random_keypair = Sodium.Box.random_keypair
let random_nonce = Sodium.Box.random_nonce let random_nonce = Sodium.Box.random_nonce
@ -27,3 +28,9 @@ let to_public_key = Sodium.Box.Bigbytes.to_public_key
let of_public_key = Sodium.Box.Bigbytes.of_public_key let of_public_key = Sodium.Box.Bigbytes.of_public_key
let to_nonce = Sodium.Box.Bigbytes.to_nonce let to_nonce = Sodium.Box.Bigbytes.to_nonce
let of_nonce = Sodium.Box.Bigbytes.of_nonce let of_nonce = Sodium.Box.Bigbytes.of_nonce
let check_proof_of_work pk nonce difficulty = assert false
let generate_proof_of_work pk difficulty =
let rec loop nonce =
if check_proof_of_work pk nonce difficulty then nonce
else loop (increment_nonce nonce) in
loop (random_nonce ())

View File

@ -12,6 +12,7 @@
type secret_key type secret_key
type public_key type public_key
type nonce type nonce
type difficulty
val random_keypair : unit -> secret_key * public_key val random_keypair : unit -> secret_key * public_key
val random_nonce : unit -> nonce val random_nonce : unit -> nonce
@ -24,3 +25,5 @@ val to_public_key : MBytes.t -> public_key
val of_public_key : public_key -> MBytes.t val of_public_key : public_key -> MBytes.t
val to_nonce : MBytes.t -> nonce val to_nonce : MBytes.t -> nonce
val of_nonce : nonce -> MBytes.t val of_nonce : nonce -> MBytes.t
val check_proof_of_work : public_key -> nonce -> difficulty -> bool
val generate_proof_of_work : public_key -> difficulty -> nonce