liability-proof 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +2 -5
- data/bin/lproof +0 -14
- data/lib/liability-proof.rb +1 -1
- data/lib/liability-proof/pretty_printer.rb +2 -2
- data/lib/liability-proof/tree.rb +7 -15
- data/lib/liability-proof/tree/interior_node.rb +3 -3
- data/lib/liability-proof/tree/leaf_node.rb +5 -5
- data/lib/liability-proof/tree/node.rb +13 -6
- data/lib/liability-proof/verifier.rb +4 -6
- data/lib/liability-proof/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd1a3709646aa06e6baf39c31146b46f6b0cada3
|
4
|
+
data.tar.gz: 495c56c9e5a5e386183a19bf646966fd7c4287a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3790c82513fa9d484040e5b830372d6d8dd33c2dd8dd91007922cb553ca48042acedfc444467f2d2fe66afce31bb489d1c07ce56b0bb294eeef397c0ae040ecc
|
7
|
+
data.tar.gz: 86c04ed283e6e6fbfb54ed4e8f01e52122eed9832e6b04ea7bd3cdfc8df6e1955a79866a939f71a1a9037c2691313345206db94bdf3a1eb46a3024cec323ed85
|
data/README.markdown
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
Liability Proof
|
2
2
|
===============
|
3
3
|
|
4
|
+
[![Build Status](https://travis-ci.org/peatio/liability-proof.png?branch=master)](https://travis-ci.org/peatio/liability-proof)
|
5
|
+
|
4
6
|
If you're not familiar with *liability proof* or *the Merkle approach*, check this page: [Proving Your Bitcoin Reserves](https://iwilcox.me.uk/2014/proving-bitcoin-reserves). Basically, every mordern exchanges should prove they really hold the bitcoins/money they claim to.
|
5
7
|
|
6
8
|
### Requirements ###
|
@@ -21,11 +23,6 @@ As command line tool:
|
|
21
23
|
# https://github.com/olalonde/blind-liability-proof#serialized-data-formats-work-in-progress--draft
|
22
24
|
lproof generate -f accounts.json
|
23
25
|
|
24
|
-
# Use -F switch to save numbers as Float instead of String. Save numbers as
|
25
|
-
# String preserve precision well, but some other verification tools doesn't
|
26
|
-
# work well with it, so -F is provided for compatibility only.
|
27
|
-
lproof generate -f accounts.json -F
|
28
|
-
|
29
26
|
# Verify specified partial tree is valid, i.e. the root node calculated from
|
30
27
|
# from the partial tree matches the root node in root.json
|
31
28
|
lproof verify -r root.json -f partial_trees/jan.json
|
data/bin/lproof
CHANGED
@@ -29,20 +29,6 @@ opt_parser = OptionParser.new do |opt|
|
|
29
29
|
options[:partial_trees_dir] = d
|
30
30
|
end
|
31
31
|
|
32
|
-
options[:use_float] = false
|
33
|
-
opt.on("-F", "--use-float", "Print numbers as Float number instead of String in json files. This option is only provided to generating data in compatible format with some verification tools, don't use it unless neccessary. Default to false.") do |f|
|
34
|
-
options[:use_float] = true
|
35
|
-
end
|
36
|
-
|
37
|
-
options[:float_nonce] = false
|
38
|
-
opt.on("--float-nonce", "Use float number as nonce. This option is only provided for compatibility with some verification tools. Default to false.") do |f|
|
39
|
-
options[:float_nonce] = true
|
40
|
-
end
|
41
|
-
|
42
|
-
opt.on("-b", "--blp-format", "Generate json in blind-liability-proof format. Default to false.") do |f|
|
43
|
-
options[:use_float] = true
|
44
|
-
options[:float_nonce] = true
|
45
|
-
end
|
46
32
|
end
|
47
33
|
|
48
34
|
opt_parser.parse!
|
data/lib/liability-proof.rb
CHANGED
@@ -37,9 +37,9 @@ module LiabilityProof
|
|
37
37
|
def lable(node)
|
38
38
|
if data = node['data']
|
39
39
|
if data['user']
|
40
|
-
"#{data['user']}, #{data['nonce']}, #{data['
|
40
|
+
"#{data['user']}, #{data['nonce']}, #{data['sum']}"
|
41
41
|
else
|
42
|
-
"#{data['
|
42
|
+
"#{data['sum']}, #{data['hash']}"
|
43
43
|
end
|
44
44
|
else
|
45
45
|
''
|
data/lib/liability-proof/tree.rb
CHANGED
@@ -13,9 +13,6 @@ module LiabilityProof
|
|
13
13
|
def initialize(accounts, options={})
|
14
14
|
raise ArgumentError, 'accounts is empty' unless accounts && accounts.size > 0
|
15
15
|
|
16
|
-
@use_float = options.delete(:use_float)
|
17
|
-
@float_nonce = options.delete(:float_nonce)
|
18
|
-
|
19
16
|
@accounts = accounts
|
20
17
|
@root = generate
|
21
18
|
@indices = Hash[index_leaves(@root)]
|
@@ -24,7 +21,7 @@ module LiabilityProof
|
|
24
21
|
def root_json
|
25
22
|
{ 'root' => {
|
26
23
|
'hash' => root.hash,
|
27
|
-
'
|
24
|
+
'sum' => root.sum_string }}
|
28
25
|
end
|
29
26
|
|
30
27
|
def partial(user)
|
@@ -41,7 +38,7 @@ module LiabilityProof
|
|
41
38
|
|
42
39
|
def _partial(user, node, index, acc)
|
43
40
|
if node.is_a?(LeafNode)
|
44
|
-
acc['data'] = node.as_json
|
41
|
+
acc['data'] = node.as_json
|
45
42
|
|
46
43
|
if node.user == user
|
47
44
|
acc['data'].merge!({
|
@@ -55,7 +52,7 @@ module LiabilityProof
|
|
55
52
|
follow_child = node.send follow_direction
|
56
53
|
other_child = node.send other_direction
|
57
54
|
|
58
|
-
acc[other_direction.to_s] = { 'data' => other_child.as_json
|
55
|
+
acc[other_direction.to_s] = { 'data' => other_child.as_json }
|
59
56
|
acc[follow_direction.to_s] = { 'data' => nil }
|
60
57
|
_partial user, follow_child, index, acc[follow_direction.to_s]
|
61
58
|
end
|
@@ -64,22 +61,17 @@ module LiabilityProof
|
|
64
61
|
def generate
|
65
62
|
leaves = @accounts.map do |a|
|
66
63
|
user = a['user']
|
67
|
-
|
64
|
+
sum = ::BigDecimal.new a['balance']
|
68
65
|
nonce = a['nonce'] || generate_nonce
|
69
|
-
LeafNode.new(user,
|
66
|
+
LeafNode.new(user, sum, nonce)
|
70
67
|
end
|
71
68
|
|
72
69
|
combine leaves
|
73
70
|
end
|
74
71
|
|
75
72
|
def generate_nonce
|
76
|
-
|
77
|
-
|
78
|
-
rand
|
79
|
-
else
|
80
|
-
# a 16 bytes random string encoded in 32 hex digits
|
81
|
-
OpenSSL::Random.random_bytes(16).unpack("H*").first
|
82
|
-
end
|
73
|
+
# a 16 bytes random string encoded in 32 hex digits
|
74
|
+
OpenSSL::Random.random_bytes(16).unpack("H*").first
|
83
75
|
end
|
84
76
|
|
85
77
|
def combine(nodes)
|
@@ -1,20 +1,20 @@
|
|
1
1
|
module LiabilityProof
|
2
2
|
class Tree
|
3
3
|
|
4
|
-
class InteriorNode < Struct.new(:left, :right, :
|
4
|
+
class InteriorNode < Struct.new(:left, :right, :sum, :hash)
|
5
5
|
include ::LiabilityProof::Tree::Node
|
6
6
|
|
7
7
|
def initialize(left, right)
|
8
8
|
super(left, right)
|
9
9
|
|
10
|
-
self.
|
10
|
+
self.sum = left.sum + right.sum
|
11
11
|
self.hash = generate_hash
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
16
|
def generate_hash
|
17
|
-
LiabilityProof.sha256_base64 "#{
|
17
|
+
LiabilityProof.sha256_base64 "#{sum_string}#{left.hash}#{right.hash}"
|
18
18
|
end
|
19
19
|
|
20
20
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module LiabilityProof
|
2
2
|
class Tree
|
3
3
|
|
4
|
-
class LeafNode < Struct.new(:user, :
|
4
|
+
class LeafNode < Struct.new(:user, :sum, :nonce, :hash)
|
5
5
|
include ::LiabilityProof::Tree::Node
|
6
6
|
|
7
|
-
def initialize(user,
|
8
|
-
raise ArgumentError, "
|
7
|
+
def initialize(user, sum, nonce, hash=nil)
|
8
|
+
raise ArgumentError, "sum must be BigDecimal" unless sum.is_a?(BigDecimal)
|
9
9
|
|
10
|
-
super(user,
|
10
|
+
super(user, sum, nonce)
|
11
11
|
self.hash = hash || generate_hash
|
12
12
|
|
13
13
|
if user && hash && nonce
|
@@ -19,7 +19,7 @@ module LiabilityProof
|
|
19
19
|
|
20
20
|
# a sha256 hash encoded in 64 hex digits
|
21
21
|
def generate_hash
|
22
|
-
LiabilityProof.sha256_base64 "#{user}|#{
|
22
|
+
LiabilityProof.sha256_base64 "#{user}|#{sum_string}|#{nonce}"
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
@@ -3,16 +3,23 @@ module LiabilityProof
|
|
3
3
|
|
4
4
|
module Node
|
5
5
|
|
6
|
-
def as_json
|
7
|
-
{ '
|
6
|
+
def as_json
|
7
|
+
{ 'sum' => sum_string, 'hash' => hash }
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def sum_string
|
11
|
+
decimal_to_digits sum
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def decimal_to_digits(d)
|
15
|
+
_, significant_digits, _, exponent = d.split
|
16
|
+
if d.zero?
|
17
|
+
'0'
|
18
|
+
elsif exponent >= significant_digits.size
|
19
|
+
d.to_i.to_s
|
20
|
+
else
|
21
|
+
d.to_s('F')
|
22
|
+
end
|
16
23
|
end
|
17
24
|
|
18
25
|
end
|
@@ -21,9 +21,7 @@ module LiabilityProof
|
|
21
21
|
def match?
|
22
22
|
partial_tree = partial_tree_json['partial_tree']
|
23
23
|
|
24
|
-
|
25
|
-
@reduced_root = reduce(partial_tree).as_json(use_float)
|
26
|
-
|
24
|
+
@reduced_root = reduce(partial_tree).as_json
|
27
25
|
@reduced_root == expect_root
|
28
26
|
end
|
29
27
|
|
@@ -31,7 +29,7 @@ module LiabilityProof
|
|
31
29
|
if match?
|
32
30
|
puts "Partial tree verified successfully!\n\n"
|
33
31
|
puts "User: #{@user_node.user}"
|
34
|
-
puts "Balance: #{@user_node.
|
32
|
+
puts "Balance: #{@user_node.sum_string}"
|
35
33
|
else
|
36
34
|
raise "Mismatch! Expected root: #{expect_root.inspect}, calculated root: #{@reduced_root.inspect}"
|
37
35
|
end
|
@@ -51,10 +49,10 @@ module LiabilityProof
|
|
51
49
|
def reduce(node)
|
52
50
|
if node['data']
|
53
51
|
user = node['data']['user']
|
54
|
-
|
52
|
+
sum = ::BigDecimal.new node['data']['sum'].to_s
|
55
53
|
nonce = node['data']['nonce']
|
56
54
|
hash = node['data']['hash']
|
57
|
-
leaf = Tree::LeafNode.new user,
|
55
|
+
leaf = Tree::LeafNode.new user, sum, nonce, hash
|
58
56
|
@user_node = leaf if leaf.user
|
59
57
|
leaf
|
60
58
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liability-proof
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peatio Opensource
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|