-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathREADME
166 lines (129 loc) · 6.58 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
This is ChronoBit, a secure timestamper using P2Pool. It can create proofs
that a given timestamped data existed before a confirmation date.
Confirmation date is generally the one of the next Bitcoin block found by
P2Pool. User's data is hashed, then the hash is put into P2Pool's share
coinbase, and then all the following P2Pool shares are stacked on top of
that share. Finally, some P2Pool share will become an actual bitcoin block,
and everyone can confirm the timestamp of a bitcoin block using any bitcoin
client or blockexplorer.
If you know P2Pool's shares hashes and are sure they existed at the time
they say they did, the proof's timestamp gets the granularity of P2Pool's
shares; otherwise it has granularity that of the found Bitcoin block.
For more info on P2Pool visit:
http://p2pool.info/ (unofficial stats page)
https://github.com/forrestv/p2pool (github project page)
For more info on bitcoin, visit:
http://bitcoin.org/
INSTALLATION
Currently none, just use the extracted .pl files and make sure configs
are in current directory.
The following CPAN modules will be required - get them via CPAN or your
distro's package manager (if it has them) or otherwise make sure they're
installed:
AnyEvent
AnyEvent::JSONRPC::HTTP::Client
AnyEvent::JSONRPC::HTTP::Server
Any::Moose
Data::ParseBinary
Digest::SHA
Digest::SHA::PurePerl
IO::All
JSON::XS
Log::Log4perl
LWP::UserAgent
YAML::Syck
To create timestamps you'll also need to be mining on P2Pool, git commit
52d0f3357b or later.
CONFIGURATION
$ cp chronobit.conf-sample chronobit.conf
$ cp log.conf-sample log.conf
$ ed/vi/emacs/joe/nano/pico *.conf
Please set your chainid as the lowest available number greater than 0,
such that it doesn't collide with existing merged mining daemons.
The only other merged mining chainid that I know of is that of namecoind
and it's 1, so I set my chainid to 2.
'proofs' is a location (relative or absolute) to where you want your proofs
of timestamp to be stored, please make sure that this directory exists
(you'll have to create it manually).
DOCUMENTATION
Is currently held in this file, as well as at the top of each perl script
in comments.
USAGE
CREATING A TIMESTAMP
Run chronobitd.pl.
Run P2Pool with --merged and point it at the running chronobitd.pl (you
configured the port it listens on in chronobit.conf).
P2Pool will start querying chronobit for hashes. Take your data, sha256
it (e.g. via the commandline sha256sum utility). Give your hash to
chronobitd like this:
$ ./jsonrpc_client.pl http://localhost:8080 '["set_hash","<your_hash>"]'
You should see something like:
$VAR1 = bless( do{\(my $o = 1)}, 'JSON::XS::Boolean' );
That's effectively a true value returned by chronobitd, acknowledging that
it got your hash.
Then wait for P2Pool to find a share (you have to be mining on P2Pool for
this to work). When it does, chronobitd will log an INFO message saying
something like "got p2pool share <...> for hash <...>". It will also store
a proof from your hash to that share's hash in the proof directory.
Chronobitd will continue to create proofs for each new P2Pool share found,
in case the one found was orphan or dead. If you got your proof, you can
prevent that by running:
$ ./jsonrpc_client.pl http://localhost:8080 '["unset_hash"]'
At any time you can also change the hash (with another set_hash) or check
what hash is currently stored (with "debug").
OK, now that we have a proof going from your data's hash up to a P2Pool's
share hash, we need to create another proof from the P2Pool's share up
to a bitcoin block. This is currently done manually. You'll have to wait
for P2Pool to find a block, but not longer than until it forgets your
share (which is something like 24 hours). Then you can create a proof
between any 2 shares (a bitcoin block is also just a share):
$ ./traverse_shares.pl <bitcoin_block_hash> <hash_of_share_with_proof>
That might take a while and will query p2pool for share data (using
its address taken from chronobit.conf) extensively. When it's done,
it'll save the proof to the usual location. You can then merge your
original proof with any number of other proofs - in order to create
one single proof for your data up to the bitcoin block:
$ ./merge_proofs.pl <proof1> [<proof2>...]
VERIFYING A TIMESTAMP'S PROOF
Just run this:
$ ./verify_proof.pl < <your_proof>
Notice it takes the proof on stdin, not as argument. You can make this
tool more verbose by giving it an argument (let's say --verbose) - it'll
then explain each step of the proof.
Each step effectively consists of one or more of:
- beginning SHA state (this is effectively done by P2Pool in order to
"compress" a number of bytes that are in front of the hash into
a smaller state of SHA),
- bytes to prepend,
- the current data (current hash),
- bytes to append.
All this will be taken together and hashed. A step can also reverse bytes
in the current hash.
OPTIMIZING PROOF'S LENGTH
It's possible to reduce the first proof's length. The "first proof"
meaning the proof from your data to the p2pool share's hash. To do this,
you start by getting the share's data. First you need to reverse the bytes
of the share's hash, because p2pool interprets it backwards. Let's say
your original $SHARE_HASH is the one you got from the proof filename, and
it ends with a bunch of zeros. You can convert it to start with that bunch
of zeroes instead with:
$ P2POOL_SHARE_HASH=`echo $SHARE_HASH | xxd -r -ps | \
./reverse_bytes.pl | xxd -ps -c100`
Then you build a short proof using p2pool's share_data from the previous
share's hash to your share's hash:
$ curl http://127.0.0.1:9332/web/share_data/$P2POOL_SHARE_HASH | \
./share2proof.pl
Pay attention to the filename that share2proof created. It's the
<share_proof> expected by shorten_proof_from_share.pl. The <orig_proof>
is simply the original proof created by chronobitd when it first got
the share. Knowing this, you can run shorten_proof_from_share.pl and
get the short version of your original proof.
In future, it will be also possible to shorten the proofs from the p2pool
share up to the bitcoin block by utilizing p2pool's far_share_hashes.
That's on the TODO list.
CONTACT
You can find me on freenode irc channel #chronobit
DONATIONS
1FCkd4x31nTDQjJGp5Wp86xMqBNsgFCAhf
--
vim: sw=2 ts=2 expandtab