yolodice-validator 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.md +7 -0
- data/README.md +63 -0
- data/bin/yolodice-validator +6 -0
- data/bin/yolodice-validator~ +8 -0
- data/lib/yolodice_validator.rb +153 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8a2160b0ead0ebe22d92886f3df4a16e9573508e
|
4
|
+
data.tar.gz: d7ff434b6b0abd5c95261d3326049c49bc8c27f9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eda200e0a3523860383c5e36615195d85858eeea5bcc2f69fb23b41e7a32cad591a7bac3cf902f7a7a2f986bb1e7ee3d78fd304dd815908c848e68bd8561dc9e
|
7
|
+
data.tar.gz: b9b0f506d8dda7fd26f0351f759e2219828f009ac546ea3d9cdfc32be2ac2f5ed905e6552640270d314fda4f807120871f3565196dd5a22917e9cbe42b17321b
|
data/LICENSE.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2016 Ethan White (YOLOdice.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
YOLOdice bet validator
|
2
|
+
======================
|
3
|
+
|
4
|
+
[YOLOdice](https://yolodice.com) is a simple online Bitcoin game you can play against the house. In heart of it lies a pseudorandom number generator that returns bet results used to determine if bets placed by players win or lose. Players can independently verify if the bets are "fair".
|
5
|
+
|
6
|
+
This Ruby utility let's you validate the following:
|
7
|
+
|
8
|
+
* if the seed hash matches the seed,
|
9
|
+
* if your bets on YOLOdice have been generated according to the *Provably fair* algorithm,
|
10
|
+
* if the profit for each bet has been calculated properly.
|
11
|
+
|
12
|
+
For more information about the algorithms used in YOLOdice, check out our [Frequently Asked Questions](https://yolodice.dev/#faq/provably-fair).
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
The validator does not depend on any gems. It's only necessare to get the validator's code to use it. Alternatively you can install it as a gem. It will then install it's own executable, `yolodice-validator` in the system.
|
17
|
+
|
18
|
+
### Using a gem from RubyGems
|
19
|
+
|
20
|
+
gem install yolodice-validator
|
21
|
+
|
22
|
+
### By cloning the git repo
|
23
|
+
|
24
|
+
git clone https://github.com/ethan-nx/yolodice-validator.git
|
25
|
+
|
26
|
+
This will clone the whole repo.
|
27
|
+
|
28
|
+
### Download the ZIP archive and unpack it
|
29
|
+
|
30
|
+
Github provides a ZIP archive of the most current revision of the code. Find it here: https://github.com/ethan-nx/yolodice-validator/archive/master.zip
|
31
|
+
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
If you installed the utility as a gem in order to run the code simply type:
|
36
|
+
|
37
|
+
yolodice_validator DUMP_FILE
|
38
|
+
|
39
|
+
If you cloned the git repo or downloaded the source, try this:
|
40
|
+
|
41
|
+
ruby lib/yolodice-validator.rb DUMP_FILE
|
42
|
+
|
43
|
+
You can get the `DUMP_FILE` by visiting your YOLOdice account and entering the [Seeds panel](https://yolodice.com/#seeds). Then click on any archived seed, a pop-up will appear. Click "Verify bets" button and download the generated dump. That's the file you need.
|
44
|
+
|
45
|
+
Example usage:
|
46
|
+
|
47
|
+
|
48
|
+
$ yolodice_validator ~/Downloads/seed_dump_2.csv
|
49
|
+
Seed seems OK, validating individual bets
|
50
|
+
.................................................
|
51
|
+
All bets verified OK
|
52
|
+
|
53
|
+
Example check of a seed that contains invalid data:
|
54
|
+
|
55
|
+
$ yolodice_validator ~/Downloads/seed_dump_2.csv
|
56
|
+
MISMATCH: secret_hashed_hex, in file: e93e86fd421942a319403738e7dcdbe1f1bf3371ae43d26ff6768d97c2c948d0, calculated: e93e86fd421942a319409738e7dcdbe1f1bf3371ae43d26ff6768d97c2c948d0
|
57
|
+
Seed data is not valid, checking bets anyway.
|
58
|
+
MISMATCH: bet 6 result, in file: 723763, calculated: 729763
|
59
|
+
MISMATCH: bet 7 result, in file: 899308, calculated: 499308
|
60
|
+
MISMATCH: bet 7 profit, in file: 2, calculated: 0
|
61
|
+
.................................................
|
62
|
+
4 errors found.
|
63
|
+
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# Copyright (c) 2016 Ethan White (YOLOdice.com)
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
# copy of this software and associated documentation files (the "Software"),
|
5
|
+
# to deal in the Software without restriction, including without limitation
|
6
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
7
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
8
|
+
# Software is furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
18
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
19
|
+
# DEALINGS IN THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'openssl'
|
22
|
+
require 'csv'
|
23
|
+
|
24
|
+
class YolodiceGenerator
|
25
|
+
|
26
|
+
def initialize server_key_hex, client_phrase
|
27
|
+
@server_key = [server_key_hex].pack("H*")
|
28
|
+
@client_phrase = client_phrase
|
29
|
+
end
|
30
|
+
|
31
|
+
def server_key_hex
|
32
|
+
@server_key.unpack('H*')[0]
|
33
|
+
end
|
34
|
+
|
35
|
+
def server_key_hash_hex
|
36
|
+
# OpenSSL::Digest::SHA256.hexdigest server_key_hex
|
37
|
+
OpenSSL::Digest::SHA256.hexdigest server_key_hex
|
38
|
+
end
|
39
|
+
|
40
|
+
# Runs the algorithm that returns bet result.
|
41
|
+
def roll nonce
|
42
|
+
hash = OpenSSL::HMAC.hexdigest 'sha512', @server_key, "#{@client_phrase}.#{nonce}"
|
43
|
+
out = nil
|
44
|
+
while !out || out >= 1_000_000
|
45
|
+
out = hash.slice!(0,5).to_i 16
|
46
|
+
end
|
47
|
+
out
|
48
|
+
end
|
49
|
+
|
50
|
+
# When given bet result and bet input parameters the function returns a Hash
|
51
|
+
# that include bet profit.
|
52
|
+
def generate_bet nonce, amount, target, range
|
53
|
+
result = roll nonce
|
54
|
+
profit = (amount * (1_000_000.to_f / target * (1 - 0.01) - 1)).floor
|
55
|
+
win = case range
|
56
|
+
when 'lo'
|
57
|
+
result < target
|
58
|
+
when 'hi'
|
59
|
+
result > 999_999 - target
|
60
|
+
end
|
61
|
+
profit = -amount unless win
|
62
|
+
{
|
63
|
+
result: result,
|
64
|
+
profit: profit,
|
65
|
+
win: win
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
class YolodiceValidator
|
72
|
+
|
73
|
+
def initialize input_file
|
74
|
+
@input_file = input_file
|
75
|
+
@mismatch_count = 0
|
76
|
+
end
|
77
|
+
|
78
|
+
def run
|
79
|
+
CSV.open @input_file do |file|
|
80
|
+
# parse first line
|
81
|
+
seed_id0, secret_hashed_hex0, secret_hex0, client_phrase0, seed_created_at0 = file.shift
|
82
|
+
@generator = YolodiceGenerator.new secret_hex0, client_phrase0
|
83
|
+
assume 'secret_hashed_hex', secret_hashed_hex0, @generator.server_key_hash_hex
|
84
|
+
if @mismatch_count == 0
|
85
|
+
puts "Seed seems OK, validating individual bets."
|
86
|
+
else
|
87
|
+
puts "Seed data is not valid, checking bets anyway."
|
88
|
+
end
|
89
|
+
print '.'
|
90
|
+
@last_dot = true
|
91
|
+
# read the rest of lines, verify individual bets
|
92
|
+
while bet_data = file.shift do
|
93
|
+
bet_id0, nonce0, rolled0, target0, range0, amount0, profit0 = bet_data
|
94
|
+
bet_id0 = bet_id0.to_i
|
95
|
+
nonce0 = nonce0.to_i
|
96
|
+
rolled0 = rolled0.to_i
|
97
|
+
target0 = target0.to_i
|
98
|
+
amount0 = amount0.to_i
|
99
|
+
profit0 = profit0.to_i
|
100
|
+
|
101
|
+
bet = @generator.generate_bet nonce0, amount0, target0, range0
|
102
|
+
assume "bet #{bet_id0} result", rolled0.to_i, bet[:result]
|
103
|
+
assume "bet #{bet_id0} profit", profit0.to_i, bet[:profit]
|
104
|
+
if nonce0 % 1000 == 0
|
105
|
+
print '.'
|
106
|
+
@last_dot = true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
print "\n"
|
110
|
+
if @mismatch_count == 0
|
111
|
+
puts "All bets verified OK"
|
112
|
+
else
|
113
|
+
puts "#{@mismatch_count} errors found."
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
def assume label, v0, v1
|
121
|
+
unless v0 == v1
|
122
|
+
print "\n" if @last_dot
|
123
|
+
puts "MISMATCH: #{label}, in file: #{v0}, calculated: #{v1}"
|
124
|
+
@mismatch_count += 1
|
125
|
+
@last_dot = false
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
class << self
|
131
|
+
|
132
|
+
def parse_opts argv
|
133
|
+
# There is only one option - pass a file containing a CSV dump
|
134
|
+
usage = "Usage: yolodice_validator DUMP_FILE"
|
135
|
+
unless argv.length == 1
|
136
|
+
puts usage
|
137
|
+
exit
|
138
|
+
end
|
139
|
+
return { input_file: argv[0] }
|
140
|
+
end
|
141
|
+
|
142
|
+
def run opts
|
143
|
+
yv = YolodiceValidator.new opts[:input_file]
|
144
|
+
yv.run
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
if __FILE__ == $0
|
151
|
+
options = YolodiceValidator.parse_opts ARGV
|
152
|
+
YolodiceValidator.run options
|
153
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yolodice-validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ethan_nx
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A utility that lets you verify your bets and seeds from the Bitcoin game
|
14
|
+
YOLOdice.com.
|
15
|
+
email:
|
16
|
+
executables:
|
17
|
+
- yolodice-validator
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- LICENSE.md
|
22
|
+
- README.md
|
23
|
+
- bin/yolodice-validator
|
24
|
+
- bin/yolodice-validator~
|
25
|
+
- lib/yolodice_validator.rb
|
26
|
+
homepage: https://github.com/ethan-nx/yolodice-validator
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project:
|
46
|
+
rubygems_version: 2.5.1
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: Bet validator for YOLOdice.com
|
50
|
+
test_files: []
|