├── COPYING ├── ChronoBit ├── Bitcoin.pm ├── Bitcoin │ ├── VarIntAdapter.pm │ └── VarStrAdapter.pm ├── JSONRPC.pm ├── P2Pool.pm ├── Proof.pm ├── ProofFile.pm ├── ProofStep.pm ├── ProofStore.pm ├── SHA.pm ├── SHAState.pm ├── StructClass.pm └── Util.pm ├── README ├── TODO ├── add_data_to_proof.pl ├── chronobit.conf-sample ├── chronobitd.pl ├── jsonrpc_client.pl ├── log.conf-sample ├── merge_proofs.pl ├── reverse_bytes.pl ├── sample_proofs └── hello_world.proof ├── share2proof.pl ├── shorten_proof_from_share.pl ├── t ├── chronobit_jsonrpc.t ├── proof.t ├── proofstep.t ├── sha.t ├── sha_state.t ├── util.t └── var_len.t ├── traverse_shares.pl └── verify_proof.pl /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /ChronoBit/Bitcoin.pm: -------------------------------------------------------------------------------- 1 | package ChronoBit::Bitcoin; 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use base 'Exporter'; 7 | our @EXPORT = qw/tx_out_point tx_in tx_out tx mrkllink block_header 8 | aux_pow mm_coinbase var_int var_str var_bytes/; 9 | 10 | use Data::ParseBinary; 11 | use ChronoBit::Bitcoin::VarIntAdapter; 12 | use ChronoBit::Bitcoin::VarStrAdapter; 13 | 14 | sub var_int { 15 | return ChronoBit::Bitcoin::VarIntAdapter::var_int(@_); 16 | } 17 | 18 | sub var_str { 19 | return ChronoBit::Bitcoin::VarStrAdapter::var_str(@_); 20 | } 21 | 22 | sub var_bytes { 23 | return ChronoBit::Bitcoin::VarStrAdapter::var_bytes(@_); 24 | } 25 | 26 | sub tx_out_point { 27 | return Struct($_[0], 28 | Bytes('hash', 32), 29 | ULInt32('index') 30 | ) 31 | } 32 | 33 | sub tx_in { 34 | return Struct($_[0], 35 | tx_out_point('previous_output'), 36 | var_int('script_length'), 37 | Field('signature_script', sub { $_->ctx->{script_length} }), 38 | ULInt32('sequence') 39 | ) 40 | } 41 | 42 | sub tx_out { 43 | return Struct($_[0], 44 | ULInt64('value'), 45 | var_int('pk_script_length'), 46 | Field('pk_script', sub { $_->ctx->{pk_script_length} }) 47 | ) 48 | } 49 | 50 | sub tx { 51 | return Struct($_[0], 52 | ULInt32('version'), 53 | var_int('tx_in_count'), 54 | Array(sub { $_->ctx->{tx_in_count} }, tx_in('tx_in')), 55 | var_int('tx_out_count'), 56 | Array(sub { $_->ctx->{tx_out_count} }, tx_out('tx_out')), 57 | ULInt32('lock_time') 58 | ) 59 | } 60 | 61 | sub mrkllink { 62 | return Struct($_[0], 63 | Bytes('block_hash', 32), 64 | var_int('branch_count'), 65 | Array(sub { $_->ctx->{branch_count} }, Bytes('branch', 32)), 66 | ULInt32('index') 67 | ) 68 | } 69 | 70 | sub block_header { 71 | return Struct($_[0], 72 | ULInt32('version'), 73 | Bytes('prev_block', 32), 74 | Bytes('merkle_root', 32), 75 | ULInt32('timestamp'), 76 | ULInt32('bits'), 77 | ULInt32('nonce') 78 | ) 79 | } 80 | 81 | sub aux_pow { 82 | return Struct($_[0], 83 | tx('coinbase_txn'), 84 | mrkllink('merkle_link'), 85 | var_int('aux_branch_count'), 86 | Array(sub { $_->ctx->{aux_branch_count} }, Bytes('aux_branch', 32)), 87 | ULInt32('index'), 88 | block_header('parent_block'), 89 | 90 | ) 91 | } 92 | 93 | sub mm_coinbase { 94 | return Struct($_[0], 95 | Magic("\xfa\xbemm"), 96 | Bytes('block_hash', 32), 97 | ULInt32('merkle_size'), 98 | ULInt32('merkle_nonce') 99 | ) 100 | } 101 | 102 | 1; 103 | -------------------------------------------------------------------------------- /ChronoBit/Bitcoin/VarIntAdapter.pm: -------------------------------------------------------------------------------- 1 | package ChronoBit::Bitcoin::VarIntAdapter; 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::ParseBinary; 7 | 8 | our @ISA = qw/Data::ParseBinary::Adapter/; 9 | 10 | sub _encode { 11 | my ($self, $value) = @_; 12 | 13 | my $ret = { value => $value, b1 => $value }; 14 | if($value >= 0xfd) { 15 | if($value <= 0xffff) { 16 | $ret->{b1} = 0xfd; 17 | } elsif($value <= 0xffffffff) { 18 | $ret->{b1} = 0xfe; 19 | } else { 20 | $ret->{b1} = 0xff; 21 | } 22 | } 23 | 24 | return $ret; 25 | } 26 | 27 | sub _decode { 28 | my ($self, $value) = @_; 29 | 30 | return $value->{value}; 31 | } 32 | 33 | sub var_int { 34 | return ChronoBit::Bitcoin::VarIntAdapter->create(Struct($_[0], 35 | Byte("b1"), 36 | IfThenElse("value", sub { $_->ctx->{b1} < 0xfd }, 37 | Value('uint8_t value', sub { $_->ctx->{b1} }), 38 | IfThenElse('>8 value', sub { $_->ctx->{b1} == 0xfd }, 39 | ULInt16('uint16_t value'), 40 | IfThenElse('>16 value', sub { $_->ctx->{b1} == 0xfe }, 41 | ULInt32('uint32_t value'), 42 | ULInt64('uint64_t value') 43 | ) 44 | ) 45 | ) 46 | )) 47 | } 48 | 49 | 1; 50 | 51 | -------------------------------------------------------------------------------- /ChronoBit/Bitcoin/VarStrAdapter.pm: -------------------------------------------------------------------------------- 1 | package ChronoBit::Bitcoin::VarStrAdapter; 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::ParseBinary; 7 | use ChronoBit::Bitcoin::VarIntAdapter; 8 | 9 | our @ISA = qw/Data::ParseBinary::Adapter/; 10 | 11 | sub _encode { 12 | my ($self, $value) = @_; 13 | 14 | return { 15 | length => length($value), 16 | value => $value, 17 | }; 18 | } 19 | 20 | sub _decode { 21 | my ($self, $value) = @_; 22 | 23 | return $value->{value}; 24 | } 25 | 26 | sub var_str { 27 | return ChronoBit::Bitcoin::VarStrAdapter->create(Struct($_[0], 28 | ChronoBit::Bitcoin::VarIntAdapter::var_int('length'), 29 | String('value', sub { $_->ctx->{length} }, encoding => 'ascii'), 30 | )) 31 | } 32 | 33 | sub var_bytes { 34 | return ChronoBit::Bitcoin::VarStrAdapter->create(Struct($_[0], 35 | ChronoBit::Bitcoin::VarIntAdapter::var_int('length'), 36 | Field('value', sub { $_->ctx->{length} }), 37 | )) 38 | } 39 | 40 | 1; 41 | -------------------------------------------------------------------------------- /ChronoBit/JSONRPC.pm: -------------------------------------------------------------------------------- 1 | package ChronoBit::JSONRPC; 2 | use Any::Moose; 3 | 4 | use JSON::XS; 5 | use Log::Log4perl; 6 | use Digest::SHA qw(sha256); 7 | 8 | use ChronoBit::Util; 9 | use ChronoBit::Bitcoin; 10 | use ChronoBit::Proof; 11 | use ChronoBit::ProofStore; 12 | 13 | my $log = Log::Log4perl->get_logger(__PACKAGE__); 14 | 15 | has 'cfg' => (is => 'ro'); 16 | has 'curhash' => (is => 'ro'); 17 | has 'hash_proofs' => (is => 'ro'); # maps a hash (hex) to an array of shares which have a proof for it 18 | has 'our_shares' => (is => 'ro'); # maps a share's hash (hex) to a proof 19 | has 'proof_store' => (is => 'rw'); 20 | 21 | sub BUILD { 22 | my ($self) = @_; 23 | 24 | $self->proof_store(ChronoBit::ProofStore->new( 25 | outdir => $self->cfg->{proofs}, 26 | )); 27 | } 28 | 29 | sub getauxblock { 30 | my ($self, @params) = @_; 31 | 32 | if(@params == 0) { 33 | # this is a call for our hash 34 | $log->trace('getauxblock called'); 35 | return { 36 | chainid => int $self->cfg->{chainid}, 37 | hash => defined($self->curhash) ? 38 | bin2hex(scalar reverse hex2bin($self->curhash)) : 39 | '00'x32, 40 | target => 'p2pool', 41 | }; 42 | } else { 43 | # this is a response with a found p2pool share 44 | my ($hash, $pow_hex) = @params; 45 | $hash = bin2hex(scalar reverse hex2bin($hash)); 46 | 47 | $log->trace("getauxblock response: " . encode_json(\@params)); 48 | 49 | if($hash ne '00'x32) { 50 | my $pow = aux_pow->parse(hex2bin($pow_hex)); 51 | my $share_hash = bin2hex($pow->{merkle_link}->{block_hash}); 52 | 53 | $log->info("got p2pool share $share_hash for hash $hash"); 54 | my $proof = ChronoBit::Proof->new_from_pow(hex2bin($hash), $pow); 55 | $self->proof_store->save($proof); 56 | } else { 57 | $log->debug("got p2pool response of empty hash, boring"); 58 | } 59 | 60 | return JSON::XS::true; 61 | } 62 | } 63 | 64 | sub set_hash { 65 | my ($self, @params) = @_; 66 | 67 | $self->{curhash} = $params[0]; 68 | return JSON::XS::true; 69 | } 70 | 71 | sub unset_hash { 72 | my ($self, @params) = @_; 73 | 74 | $self->{curhash} = undef; 75 | return JSON::XS::true; 76 | } 77 | 78 | sub debug { 79 | my ($self, @params) = @_; 80 | 81 | return { cur => $self->curhash }; 82 | } 83 | 84 | sub all_methods { 85 | return qw/getauxblock set_hash unset_hash debug/; 86 | } 87 | 88 | 1; 89 | -------------------------------------------------------------------------------- /ChronoBit/P2Pool.pm: -------------------------------------------------------------------------------- 1 | package ChronoBit::P2Pool; 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use base 'Exporter'; 7 | our @EXPORT = qw/small_block_header share_data share_info hash_link 8 | share_common share1a share1b share ref_type/; 9 | 10 | use Data::ParseBinary; 11 | use ChronoBit::Bitcoin; 12 | 13 | sub list { 14 | return Struct($_[0], 15 | var_int('length'), 16 | Array(sub { $_->ctx->{length} }, $_[1]) 17 | ) 18 | } 19 | 20 | sub small_block_header { 21 | return Struct($_[0], 22 | var_int('version'), # must be constrained to 32 bits, apparently 23 | Bytes('previous_block', 32), 24 | ULInt32('timestamp'), 25 | ULInt32('bits'), 26 | ULInt32('nonce') 27 | ) 28 | } 29 | 30 | sub share_data { 31 | return Struct($_[0], 32 | Bytes('previous_share_hash', 32), 33 | var_bytes('coinbase'), 34 | ULInt32('nonce'), 35 | Bytes('pubkey_hash', 20), 36 | ULInt64('subsidy'), 37 | ULInt16('donation'), 38 | ULInt8('stale_info'), # 0 nothing, 253 orphan, 254 doa, apparently 39 | var_int('desired_version') 40 | ) 41 | } 42 | 43 | sub share_info { 44 | return Struct($_[0], 45 | share_data('share_data'), 46 | Bytes('far_share_hash', 32), 47 | ULInt32('max_bits'), 48 | ULInt32('bits'), 49 | ULInt32('timestamp'), 50 | ) 51 | } 52 | 53 | sub hash_link { 54 | return Struct($_[0], 55 | Bytes('state', 32), 56 | # extra_data is a 0-length string? :-O 57 | var_int('length') 58 | ) 59 | } 60 | 61 | sub share_common { 62 | return Struct($_[0], 63 | small_block_header('min_header'), 64 | share_info('share_info'), 65 | Struct('ref_merkle_link', 66 | list('branch', Bytes('', 32)), 67 | var_int('index') 68 | ), 69 | hash_link('hash_link') 70 | ) 71 | } 72 | 73 | sub share1a { 74 | return Struct($_[0], 75 | share_common('common'), 76 | 77 | list('merkle_link', Bytes('branch', 32)), 78 | # here's apparently a 0-bit int which will always be 0 :-O 79 | # ah, that's gotta be gentx's index 80 | ) 81 | } 82 | 83 | sub share1b { 84 | return Struct($_[0], 85 | share_common('common'), 86 | list('other_txs', tx) 87 | ) 88 | } 89 | 90 | sub share { 91 | return Struct($_[0], 92 | var_int('type'), 93 | var_int('contents_length'), # that's actually wrapping the remainder in var_str, but I want to avoid it 94 | Switch('contents', sub { $_->ctx->{type} }, { 95 | 4 => share1a('1a'), 96 | 5 => share1b('1b'), 97 | }) 98 | ) 99 | } 100 | 101 | sub ref_type { 102 | return Struct($_[0], 103 | Magic("\xfc\x70\x03\x5c\x7a\x81\xbc\x6f"), # XXX: that varies with network, but nvmd for now 104 | share_info('share_info'), 105 | ) 106 | } 107 | 108 | # this is the donation script 109 | our $gentx_before_refhash = 110 | "\x43\x41\x04\xff\xd0\x3d\xe4\x4a\x6e\x11\xb9\x91\x7f\x3a\x29\xf9". 111 | "\x44\x32\x83\xd9\x87\x1c\x9d\x74\x3e\xf3\x0d\x5e\xdd\xcd\x37\x09". 112 | "\x4b\x64\xd1\xb3\xd8\x09\x04\x96\xb5\x32\x56\x78\x6b\xf5\xc8\x29". 113 | "\x32\xec\x23\xc3\xb7\x4d\x9f\x05\xa6\xf9\x5a\x8b\x55\x29\x35\x26". 114 | "\x56\x66\x4b\xac\x00\x00\x00\x00\x00\x00\x00\x00\x21\x20"; 115 | 116 | 1; 117 | -------------------------------------------------------------------------------- /ChronoBit/Proof.pm: -------------------------------------------------------------------------------- 1 | package ChronoBit::Proof; 2 | use Any::Moose; 3 | 4 | with 'ChronoBit::StructClass'; 5 | 6 | use Data::ParseBinary; 7 | use Digest::SHA qw/sha256/; 8 | 9 | use ChronoBit::Bitcoin; 10 | use ChronoBit::P2Pool; 11 | use ChronoBit::ProofStep; 12 | use ChronoBit::SHAState; 13 | use ChronoBit::Util; 14 | 15 | sub struct { 16 | return Struct('proof', 17 | Bytes('from', 32), 18 | Bytes('to', 32), 19 | var_int('len'), 20 | Array(sub { $_->ctx->{len} }, ChronoBit::ProofStep->struct), 21 | ); 22 | } 23 | 24 | has 'from' => (is => 'rw'); # binary 25 | has 'to' => (is => 'rw'); # binary 26 | has 'len' => (is => 'rw', default => 0); 27 | has 'step' => (is => 'rw', isa => 'ArrayRef'); 28 | 29 | around 'new_from_binary' => sub { 30 | my ($meth, $class, @args) = @_; 31 | 32 | my $ret = $class->$meth(@args); 33 | 34 | # XXX hack: go through all our steps and bless them 35 | for(my $i = 0; $i < scalar @{$ret->step}; $i++) { 36 | bless $ret->step->[$i], 'ChronoBit::ProofStep'; 37 | if($ret->step->[$i]->type == 0) { 38 | bless $ret->step->[$i]->{normal}->{state}, 'ChronoBit::SHAState'; 39 | } 40 | } 41 | 42 | return $ret; 43 | }; 44 | 45 | sub add_step { 46 | my ($self, $step) = @_; 47 | 48 | $self->len($self->len + 1); 49 | push @{$self->{step}}, $step; 50 | } 51 | 52 | sub perform { 53 | my ($self) = @_; 54 | 55 | my $cur = $self->from; 56 | for(my $i = 0; $i < $self->len; $i++) { 57 | $cur = $self->step->[$i]->perform($cur); 58 | } 59 | 60 | return $cur; 61 | } 62 | 63 | sub explain { 64 | my ($self) = @_; 65 | 66 | my $text = "Start with " . bin2hex($self->from) . "\n"; 67 | my $buf = $self->from; 68 | for(my $i = 0; $i < $self->len; $i++) { 69 | my $cur; 70 | ($buf, $cur) = $self->step->[$i]->explain($buf); 71 | $text .= $cur; 72 | } 73 | if($self->to eq $buf) { 74 | $text .= "Arrive at "; 75 | } else { 76 | $text .= "PROOF INCORRECT, should get " 77 | } 78 | 79 | return $text . bin2hex($self->to) . "\n"; 80 | } 81 | 82 | sub verify { 83 | my ($self) = @_; 84 | 85 | return $self->perform eq $self->to; 86 | } 87 | 88 | # helper function that adds proof steps from a merkle branch 89 | sub _mrklbranch2proof { 90 | my ($class, $idx, $count, $branch, $proof, $extra_code) = @_; 91 | 92 | for(my $i = 0; $i < $count; $i++) { 93 | my $step = ChronoBit::ProofStep->new; 94 | 95 | my $which; 96 | if($idx % 2 == 0) { 97 | # we're on the left 98 | $which = 'suffix'; 99 | } else { 100 | # we're on the right 101 | $which = 'prefix'; 102 | } 103 | 104 | $step->normal->{$which} = $branch->[$i]; 105 | $proof->add_step($step); 106 | $idx >>= 1; 107 | 108 | if($extra_code) { 109 | &$extra_code($proof); 110 | } 111 | } 112 | } 113 | 114 | # builds a proof from given hash (one set with set_hash rpc call) 115 | # up to the coinbase (using aux_branch from aux PoW) 116 | # $hash is expected to be binary 117 | # $aux_pow is expected to be a parsed struct 118 | sub new_aux2coinbase { 119 | my ($class, $hash, $aux_pow) = @_; 120 | 121 | my $raw_coinbase = $aux_pow->{coinbase_txn}->{tx_in}->[0]->{signature_script}; 122 | 123 | my $mm_coinbase = mm_coinbase->parse( 124 | substr($raw_coinbase, index($raw_coinbase, "\xfa\xbemm"), 44)); 125 | 126 | my $proof = $class->new( 127 | from => $hash, 128 | to => scalar reverse $mm_coinbase->{block_hash} 129 | ); 130 | 131 | $class->_mrklbranch2proof($aux_pow->{index}, 132 | $aux_pow->{aux_branch_count}, $aux_pow->{aux_branch}, $proof); 133 | 134 | # one last sha256 (remember they get double-sha256ed?) 135 | $proof->add_step(ChronoBit::ProofStep->new); 136 | 137 | return $proof; 138 | } 139 | 140 | # builds a proof from given coinbase up to the generation transaction's hash 141 | # takes a parsed gentx as input 142 | sub new_coinbase2gentx { 143 | my ($class, $gentx) = @_; 144 | 145 | my $raw_coinbase = $gentx->{tx_in}->[0]->{signature_script}; 146 | 147 | my $src_hash = mm_coinbase->parse( 148 | substr($raw_coinbase, index($raw_coinbase, "\xfa\xbemm"), 44))->{block_hash}; 149 | my $gentx_bin = tx->build($gentx); 150 | 151 | my $proof = $class->new( 152 | from => $src_hash, 153 | to => sha256(sha256($gentx_bin)), 154 | ); 155 | 156 | # simply find the latest occurence of coinbase in the gentx. 157 | # the latter one we find, the more we can compress in front 158 | my $loc = -1; 159 | my $newloc; 160 | my $revfound = 0; 161 | while(($newloc = index($gentx_bin, $src_hash, $loc + 1)) >= 0) { 162 | $loc = $newloc; 163 | } 164 | # maybe a reverse? 165 | while(($newloc = index($gentx_bin, scalar reverse $src_hash, $loc + 1)) 166 | > $loc) { 167 | $loc = $newloc; 168 | $revfound = 1; 169 | } 170 | die 'no hash in gentx?' if($loc < 0); 171 | 172 | if($revfound) { 173 | $proof->add_step(ChronoBit::ProofStep->new(type => 1)); 174 | } 175 | 176 | $proof->add_step(ChronoBit::ProofStep->new(normal => { 177 | prefix => substr($gentx_bin, 0, $loc), 178 | suffix => substr($gentx_bin, $loc + 32), 179 | })); 180 | 181 | # one last sha256 182 | $proof->add_step(ChronoBit::ProofStep->new); 183 | 184 | return $proof; 185 | } 186 | 187 | # builds a proof from given generation transaction's hash up to the block's 188 | # merkle root. 189 | # takes a parsed aux PoW as input 190 | sub new_gentx2mrklroot { 191 | my ($class, $aux_pow) = @_; 192 | 193 | my $proof = $class->new( 194 | from => sha256(sha256(tx->build($aux_pow->{coinbase_txn}))), 195 | to => $aux_pow->{parent_block}->{merkle_root}, 196 | ); 197 | 198 | my $ml = $aux_pow->{merkle_link}; 199 | $class->_mrklbranch2proof($ml->{index}, $ml->{branch_count}, 200 | $ml->{branch}, $proof, sub { 201 | # after each step, add another round of sha256 - merkle tree 202 | # use double sha256ing, whereas aux_branch only one 203 | $_[0]->add_step(ChronoBit::ProofStep->new); 204 | } 205 | ); 206 | 207 | return $proof; 208 | } 209 | 210 | # builds a proof for a block (from merkle root) 211 | sub new_mrklroot2block { 212 | my ($class, $block_header) = @_; 213 | 214 | my $hdr_bin = block_header->build($block_header); 215 | 216 | my $proof = $class->new( 217 | from => $block_header->{merkle_root}, 218 | to => sha256(sha256($hdr_bin)), 219 | ); 220 | 221 | $proof->add_step(ChronoBit::ProofStep->new(normal => { 222 | prefix => substr($hdr_bin, 0, 36), 223 | suffix => substr($hdr_bin, 68) 224 | })); 225 | 226 | $proof->add_step(ChronoBit::ProofStep->new); 227 | 228 | return $proof; 229 | } 230 | 231 | # builds a new proof by merging existing ones (keeps refs to existing 232 | # steps, however, so don't mess around with steps) 233 | sub new_merged { 234 | my ($class, @proofs) = @_; 235 | 236 | die "no proofs given" unless @proofs > 0; 237 | 238 | my $proof = $class->new(); 239 | my $first = 1; 240 | 241 | foreach my $p (@proofs) { 242 | unless($first) { 243 | if($proof->to eq scalar reverse $p->from) { 244 | $proof->add_step(ChronoBit::ProofStep->new(type => 1)); 245 | } else { 246 | die "proofs don't match up" unless($proof->to eq $p->from); 247 | } 248 | } 249 | 250 | if($first) { 251 | $proof->from($p->from); 252 | $first = 0; 253 | } 254 | $proof->to($p->to); 255 | 256 | foreach my $s (@{$p->step}) { 257 | $proof->add_step($s); 258 | } 259 | } 260 | 261 | return $proof; 262 | } 263 | 264 | # creates a new hash from PoW 265 | sub new_from_pow { 266 | my ($class, $hash, $pow) = @_; 267 | 268 | my @proofs = ( 269 | ChronoBit::Proof->new_aux2coinbase($hash, $pow), 270 | ChronoBit::Proof->new_coinbase2gentx($pow->{coinbase_txn}), 271 | ChronoBit::Proof->new_gentx2mrklroot($pow), 272 | ChronoBit::Proof->new_mrklroot2block($pow->{parent_block}), 273 | ); 274 | 275 | return ChronoBit::Proof->new_merged(@proofs); 276 | } 277 | 278 | # builds a proof from a p2pool share (proof from previous share's hash 279 | # to this share's hash) 280 | sub new_from_share { 281 | my ($class, $share, $share_hash) = @_; 282 | 283 | die "unimplemented share type" unless($share->{type} == 4); 284 | 285 | my $proof = $class->new( 286 | from => $share->{contents}->{common}->{share_info}->{share_data}-> 287 | {previous_share_hash}, 288 | to => $share_hash, 289 | ); 290 | 291 | # first convert our previous share's hash into share_info. 292 | # that's needed for the ref_hash later. 293 | # we do it by building the entire share_info and then removing our 294 | # prev share's hash from the (8,40) location (first 8 bytes is network's 295 | # magic) 296 | my $ref_type = ref_type->build({ share_info => 297 | $share->{contents}->{common}->{share_info} 298 | }); 299 | $proof->add_step(ChronoBit::ProofStep->new(normal => { 300 | prefix => substr($ref_type, 0, 8), 301 | suffix => substr($ref_type, 40), 302 | })); 303 | 304 | # hash it again 305 | $proof->add_step(ChronoBit::ProofStep->new); 306 | 307 | # now we have ref_hash in our buffer (just need to add 4x00 to it) 308 | # so we can append it to our gentx's state 309 | my $hash_link = $share->{contents}->{common}->{hash_link}; 310 | $proof->add_step(ChronoBit::ProofStep->new(normal => { 311 | state => ChronoBit::SHAState->new(len => $hash_link->{length}, 312 | state => $hash_link->{state}), 313 | suffix => "\0"x4, 314 | prefix => '', 315 | })); 316 | 317 | # hash it again 318 | $proof->add_step(ChronoBit::ProofStep->new); 319 | 320 | # and now that we have gentx's hash in buffer, we can build up from 321 | # it up to merkle root 322 | $class->_mrklbranch2proof(0, # gentx's index is always 0 323 | $share->{contents}->{merkle_link}->{length}, 324 | $share->{contents}->{merkle_link}->{branch}, 325 | $proof, sub { 326 | # after each step, add another round of sha256 - merkle tree 327 | # use double sha256ing, whereas aux_branch only one 328 | $_[0]->add_step(ChronoBit::ProofStep->new); 329 | } 330 | ); 331 | 332 | # now that we have merkle root in buffer, we can build our share's 333 | # hash from it 334 | my $sbh = $share->{contents}->{common}->{min_header}; 335 | my $block = block_header->build({ 336 | version => $sbh->{version}, # damn, these HAD to be incompatible... 337 | # p2pool's is a var_int, bitcoin's is a uint32 338 | prev_block => $sbh->{previous_block}, 339 | merkle_root => "\x0"x32, # we'll fill it up later 340 | timestamp => $sbh->{timestamp}, 341 | bits => $sbh->{bits}, 342 | nonce => $sbh->{nonce}, 343 | }); 344 | $proof->add_step(ChronoBit::ProofStep->new(normal => { 345 | prefix => substr($block, 0, 36), 346 | suffix => substr($block, 68), 347 | })); 348 | 349 | # final sha and we have our share's/block's hash 350 | $proof->add_step(ChronoBit::ProofStep->new); 351 | 352 | return $proof; 353 | } 354 | 355 | 1; 356 | -------------------------------------------------------------------------------- /ChronoBit/ProofFile.pm: -------------------------------------------------------------------------------- 1 | package ChronoBit::ProofFile; 2 | use Any::Moose; 3 | 4 | with 'ChronoBit::StructClass'; 5 | 6 | use Data::ParseBinary; 7 | use ChronoBit::Bitcoin; 8 | use ChronoBit::Proof; 9 | 10 | sub struct { 11 | return Struct($_[0], 12 | Magic("\xd4\x97\xcf\x52"), 13 | var_str('data'), 14 | var_int('timestamp'), 15 | ULInt32('timestamp_usec'), 16 | ChronoBit::Proof->struct('proof'), 17 | ); 18 | } 19 | 20 | 1; 21 | -------------------------------------------------------------------------------- /ChronoBit/ProofStep.pm: -------------------------------------------------------------------------------- 1 | package ChronoBit::ProofStep; 2 | use Any::Moose; 3 | 4 | with 'ChronoBit::StructClass'; 5 | 6 | use Data::ParseBinary; 7 | use Digest::SHA; 8 | 9 | use ChronoBit::SHA; 10 | use ChronoBit::SHAState; 11 | use ChronoBit::Bitcoin; 12 | use ChronoBit::Util; 13 | use ChronoBit::P2Pool; 14 | 15 | sub struct { 16 | return Struct('step', 17 | var_int('type'), # 00 - normal step, 01 - reverse bytes 18 | If(sub { $_->ctx->{type} == 0 }, 19 | Struct('normal', 20 | ChronoBit::SHAState->struct, 21 | var_bytes('prefix'), 22 | var_bytes('suffix'), 23 | ), 24 | ), 25 | ); 26 | } 27 | 28 | has 'type' => (is => 'rw', default => 0); 29 | has 'normal' => (is => 'rw', isa => 'HashRef', default => sub { { 30 | state => ChronoBit::SHAState->new(len => 0, state => ''), 31 | prefix => '', 32 | suffix => '', 33 | } }); 34 | 35 | sub BUILD { 36 | my ($self) = @_; 37 | 38 | die 'unknown proofstep type ' . $self->type unless($self->type == 0 || 39 | $self->type == 1); 40 | 41 | # make sure there's a state, even if it's empty 42 | unless(exists $self->normal->{state}) { 43 | $self->normal->{state} = ChronoBit::SHAState->new(len => 0, 44 | state => ''); 45 | } 46 | } 47 | 48 | # returns bytes for padding a state with the donation script 49 | sub _donation_pad { 50 | my ($self, $state_len) = @_; 51 | 52 | if($state_len % 64 != 0) { 53 | my $pad = $ChronoBit::P2Pool::gentx_before_refhash; 54 | return substr($pad, 55 | length($pad) - $state_len % 64 56 | ); 57 | } else { 58 | return ''; 59 | } 60 | } 61 | 62 | sub perform { 63 | my ($self, $buf) = @_; 64 | 65 | if($self->type == 0) { 66 | my $sha; 67 | my $state = $self->normal->{state}; 68 | if($state->{len} > 0) { 69 | # if our length is shorter than sha's block, pad with 70 | # p2pool's donation address 71 | $state->{extra_data} = $self->_donation_pad($state->{len}); 72 | $sha = ChronoBit::SHA->new_from_state($state); 73 | } else { 74 | $sha = Digest::SHA->new(256); 75 | } 76 | 77 | $sha->add($self->normal->{prefix} || ''); 78 | $sha->add($buf); 79 | $sha->add($self->normal->{suffix} || ''); 80 | 81 | return $sha->digest; 82 | } elsif($self->type == 1) { 83 | return scalar reverse $buf; 84 | } else { 85 | die "unknown type"; 86 | } 87 | } 88 | 89 | sub explain { 90 | my ($self, $buf) = @_; 91 | 92 | my $out = ''; 93 | if($self->type == 0) { 94 | if($self->normal->{state}->{len} > 0) { 95 | $out .= sprintf("Begin with SHA state %s len %d data %s\n", 96 | bin2hex($self->normal->{state}->{state}), 97 | $self->normal->{state}->{len}, 98 | bin2hex($self->_donation_pad($self->normal->{state}->{len})), 99 | ); 100 | } 101 | if($self->normal->{prefix}) { 102 | $out .= "Prepend bytes: " . bin2hex($self->normal->{prefix}) . "\n"; 103 | } 104 | if($self->normal->{suffix}) { 105 | $out .= "Append bytes: " . bin2hex($self->normal->{suffix}) . "\n"; 106 | } 107 | $out .= "Perform SHA-256 on the result. "; 108 | } elsif($self->type == 1) { 109 | $out = "Reverse all bytes. "; 110 | } else { 111 | die "unknown type"; 112 | } 113 | 114 | my $res = $self->perform($buf); 115 | $out .= "Get " . bin2hex($res) . "\n"; 116 | 117 | return ($res, $out); 118 | } 119 | 120 | 1; 121 | -------------------------------------------------------------------------------- /ChronoBit/ProofStore.pm: -------------------------------------------------------------------------------- 1 | package ChronoBit::ProofStore; 2 | use Any::Moose; 3 | 4 | use IO::All; 5 | 6 | use ChronoBit::Util; 7 | use ChronoBit::ProofFile; 8 | 9 | has 'outdir' => (is => 'rw'); 10 | has 'proofs' => (is => 'rw', isa => 'ArrayRef'); 11 | has 'froms' => (is => 'rw', isa => 'HashRef'); # maps from -> { to => idx, ... } 12 | has 'tos' => (is => 'rw', isa => 'HashRef'); # maps to -> { from => idx, ... } 13 | 14 | # adds a proof to the store and returns number of proofs added (0 if it already existed) 15 | sub add { 16 | my ($self, $proof) = @_; 17 | 18 | unless(exists($self->froms->{$proof->from}->{$proof->to})) { 19 | my $idx = push(@{$self->proofs}, $proof) - 1; 20 | $self->froms->{$proof->from}->{$proof->to} = $idx; 21 | $self->tos->{$proof->to}->{$proof->from} = $idx; 22 | return 1; 23 | } else { 24 | return 0; 25 | } 26 | } 27 | 28 | # saves a proof to disk, returns a filename 29 | sub save { 30 | my ($self, $proof, $proof_data) = @_; 31 | 32 | my $time = time; 33 | 34 | my $data = ChronoBit::ProofFile->struct->build({ 35 | data => $proof_data || '', 36 | timestamp => $time, 37 | timestamp_usec => 0, 38 | proof => $proof, 39 | }); 40 | 41 | my $outfile = io->catfile($self->outdir, sprintf("%s-%s-%d-%d-%d.proof", 42 | bin2hex($proof->from), bin2hex($proof->to), $time, 0, length($data) 43 | )); 44 | 45 | $data > $outfile; 46 | $outfile->close; 47 | 48 | return $outfile->name; 49 | } 50 | 51 | 1; 52 | -------------------------------------------------------------------------------- /ChronoBit/SHA.pm: -------------------------------------------------------------------------------- 1 | package ChronoBit::SHA; 2 | use Any::Moose; 3 | 4 | extends 'Digest::SHA::PurePerl'; 5 | use Data::ParseBinary; 6 | use ChronoBit::SHAState; 7 | 8 | my $h_struct = Array(8, SBInt32()); 9 | 10 | sub new_from_state { 11 | my ($class, $state) = @_; 12 | 13 | my $ret = $class->new(256); 14 | $ret->{H} = $h_struct->parse($state->state); 15 | $ret->{lenll} = $state->len * 8; 16 | $ret->{blockcnt} = ($state->len * 8) % 512; 17 | $ret->{block} = $state->extra_data; 18 | 19 | return $ret; 20 | } 21 | 22 | sub get_state { 23 | my ($self) = @_; 24 | 25 | return ChronoBit::SHAState->new( 26 | state => $h_struct->build($self->{H}), 27 | len => int($self->{lenll} / 8), 28 | extra_data => $self->{block}, 29 | ); 30 | } 31 | 32 | 1; 33 | -------------------------------------------------------------------------------- /ChronoBit/SHAState.pm: -------------------------------------------------------------------------------- 1 | package ChronoBit::SHAState; 2 | use Any::Moose; 3 | 4 | with 'ChronoBit::StructClass'; 5 | 6 | use Data::ParseBinary; 7 | use ChronoBit::Bitcoin; 8 | 9 | sub struct { 10 | return Struct('state', 11 | var_int('len'), # this is the digest length up to this state 12 | If(sub { $_->ctx->{len} > 0 }, 13 | Bytes('state', 32), 14 | ), 15 | # we purposefully don't include extra_data as it's always 0 16 | # -- any real extra_data bytes can be in ProofStep's prefix. 17 | ); 18 | } 19 | 20 | has 'state' => (is => 'rw'); 21 | has 'len' => (is => 'rw'); 22 | has 'extra_data' => (is => 'rw'); 23 | 24 | 1; 25 | -------------------------------------------------------------------------------- /ChronoBit/StructClass.pm: -------------------------------------------------------------------------------- 1 | # base class that wraps up the Data::ParseBinary and provides methods 2 | # for parse and build. 3 | 4 | package ChronoBit::StructClass; 5 | use Any::Moose 'Role'; 6 | 7 | requires 'struct'; 8 | 9 | sub dump { 10 | my ($self) = @_; 11 | 12 | return $self->struct->build($self); 13 | } 14 | 15 | sub new_from_binary { 16 | my ($class, $bytes) = @_; 17 | 18 | $class->new($class->struct->parse($bytes)); 19 | } 20 | 21 | 1; 22 | -------------------------------------------------------------------------------- /ChronoBit/Util.pm: -------------------------------------------------------------------------------- 1 | package ChronoBit::Util; 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use base 'Exporter'; 7 | our @EXPORT = qw/hex2bin bin2hex/; 8 | 9 | sub hex2bin { 10 | return pack('(H2)*', unpack('(a2)*', $_[0])); 11 | } 12 | 13 | sub bin2hex { 14 | return join('', unpack('(H2)*', $_[0])); 15 | } 16 | 17 | 1; 18 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This is ChronoBit, a secure timestamper using P2Pool. It can create proofs 2 | that a given timestamped data existed before a confirmation date. 3 | 4 | Confirmation date is generally the one of the next Bitcoin block found by 5 | P2Pool. User's data is hashed, then the hash is put into P2Pool's share 6 | coinbase, and then all the following P2Pool shares are stacked on top of 7 | that share. Finally, some P2Pool share will become an actual bitcoin block, 8 | and everyone can confirm the timestamp of a bitcoin block using any bitcoin 9 | client or blockexplorer. 10 | 11 | If you know P2Pool's shares hashes and are sure they existed at the time 12 | they say they did, the proof's timestamp gets the granularity of P2Pool's 13 | shares; otherwise it has granularity that of the found Bitcoin block. 14 | 15 | For more info on P2Pool visit: 16 | http://p2pool.info/ (unofficial stats page) 17 | https://github.com/forrestv/p2pool (github project page) 18 | 19 | For more info on bitcoin, visit: 20 | http://bitcoin.org/ 21 | 22 | INSTALLATION 23 | Currently none, just use the extracted .pl files and make sure configs 24 | are in current directory. 25 | 26 | The following CPAN modules will be required - get them via CPAN or your 27 | distro's package manager (if it has them) or otherwise make sure they're 28 | installed: 29 | 30 | AnyEvent 31 | AnyEvent::JSONRPC::HTTP::Client 32 | AnyEvent::JSONRPC::HTTP::Server 33 | Any::Moose 34 | Data::ParseBinary 35 | Digest::SHA 36 | Digest::SHA::PurePerl 37 | IO::All 38 | JSON::XS 39 | Log::Log4perl 40 | LWP::UserAgent 41 | YAML::Syck 42 | 43 | To create timestamps you'll also need to be mining on P2Pool, git commit 44 | 52d0f3357b or later. 45 | 46 | CONFIGURATION 47 | $ cp chronobit.conf-sample chronobit.conf 48 | $ cp log.conf-sample log.conf 49 | $ ed/vi/emacs/joe/nano/pico *.conf 50 | 51 | Please set your chainid as the lowest available number greater than 0, 52 | such that it doesn't collide with existing merged mining daemons. 53 | The only other merged mining chainid that I know of is that of namecoind 54 | and it's 1, so I set my chainid to 2. 55 | 56 | 'proofs' is a location (relative or absolute) to where you want your proofs 57 | of timestamp to be stored, please make sure that this directory exists 58 | (you'll have to create it manually). 59 | 60 | DOCUMENTATION 61 | Is currently held in this file, as well as at the top of each perl script 62 | in comments. 63 | 64 | USAGE 65 | CREATING A TIMESTAMP 66 | Run chronobitd.pl. 67 | Run P2Pool with --merged and point it at the running chronobitd.pl (you 68 | configured the port it listens on in chronobit.conf). 69 | P2Pool will start querying chronobit for hashes. Take your data, sha256 70 | it (e.g. via the commandline sha256sum utility). Give your hash to 71 | chronobitd like this: 72 | 73 | $ ./jsonrpc_client.pl http://localhost:8080 '["set_hash",""]' 74 | 75 | You should see something like: 76 | 77 | $VAR1 = bless( do{\(my $o = 1)}, 'JSON::XS::Boolean' ); 78 | 79 | That's effectively a true value returned by chronobitd, acknowledging that 80 | it got your hash. 81 | Then wait for P2Pool to find a share (you have to be mining on P2Pool for 82 | this to work). When it does, chronobitd will log an INFO message saying 83 | something like "got p2pool share <...> for hash <...>". It will also store 84 | a proof from your hash to that share's hash in the proof directory. 85 | 86 | Chronobitd will continue to create proofs for each new P2Pool share found, 87 | in case the one found was orphan or dead. If you got your proof, you can 88 | prevent that by running: 89 | 90 | $ ./jsonrpc_client.pl http://localhost:8080 '["unset_hash"]' 91 | 92 | At any time you can also change the hash (with another set_hash) or check 93 | what hash is currently stored (with "debug"). 94 | 95 | OK, now that we have a proof going from your data's hash up to a P2Pool's 96 | share hash, we need to create another proof from the P2Pool's share up 97 | to a bitcoin block. This is currently done manually. You'll have to wait 98 | for P2Pool to find a block, but not longer than until it forgets your 99 | share (which is something like 24 hours). Then you can create a proof 100 | between any 2 shares (a bitcoin block is also just a share): 101 | 102 | $ ./traverse_shares.pl 103 | 104 | That might take a while and will query p2pool for share data (using 105 | its address taken from chronobit.conf) extensively. When it's done, 106 | it'll save the proof to the usual location. You can then merge your 107 | original proof with any number of other proofs - in order to create 108 | one single proof for your data up to the bitcoin block: 109 | 110 | $ ./merge_proofs.pl [...] 111 | 112 | VERIFYING A TIMESTAMP'S PROOF 113 | Just run this: 114 | 115 | $ ./verify_proof.pl < 116 | 117 | Notice it takes the proof on stdin, not as argument. You can make this 118 | tool more verbose by giving it an argument (let's say --verbose) - it'll 119 | then explain each step of the proof. 120 | 121 | Each step effectively consists of one or more of: 122 | - beginning SHA state (this is effectively done by P2Pool in order to 123 | "compress" a number of bytes that are in front of the hash into 124 | a smaller state of SHA), 125 | - bytes to prepend, 126 | - the current data (current hash), 127 | - bytes to append. 128 | All this will be taken together and hashed. A step can also reverse bytes 129 | in the current hash. 130 | 131 | OPTIMIZING PROOF'S LENGTH 132 | It's possible to reduce the first proof's length. The "first proof" 133 | meaning the proof from your data to the p2pool share's hash. To do this, 134 | you start by getting the share's data. First you need to reverse the bytes 135 | of the share's hash, because p2pool interprets it backwards. Let's say 136 | your original $SHARE_HASH is the one you got from the proof filename, and 137 | it ends with a bunch of zeros. You can convert it to start with that bunch 138 | of zeroes instead with: 139 | 140 | $ P2POOL_SHARE_HASH=`echo $SHARE_HASH | xxd -r -ps | \ 141 | ./reverse_bytes.pl | xxd -ps -c100` 142 | 143 | Then you build a short proof using p2pool's share_data from the previous 144 | share's hash to your share's hash: 145 | 146 | $ curl http://127.0.0.1:9332/web/share_data/$P2POOL_SHARE_HASH | \ 147 | ./share2proof.pl 148 | 149 | Pay attention to the filename that share2proof created. It's the 150 | expected by shorten_proof_from_share.pl. The 151 | is simply the original proof created by chronobitd when it first got 152 | the share. Knowing this, you can run shorten_proof_from_share.pl and 153 | get the short version of your original proof. 154 | 155 | In future, it will be also possible to shorten the proofs from the p2pool 156 | share up to the bitcoin block by utilizing p2pool's far_share_hashes. 157 | That's on the TODO list. 158 | 159 | CONTACT 160 | You can find me on freenode irc channel #chronobit 161 | 162 | DONATIONS 163 | 1FCkd4x31nTDQjJGp5Wp86xMqBNsgFCAhf 164 | 165 | -- 166 | vim: sw=2 ts=2 expandtab 167 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Plans for future: 2 | 3 | - number tests 4 | - PODify docs 5 | - write up the specification of the proof file (and make sure it's OK) 6 | - shorten Proof::new_from_share 7 | - get rid of blessing hacks for new_from_binary, perhaps by making the classes 8 | inherit Data::ParseBinary::Struct and/or adding more adapters 9 | - create a nicer framework for commandline tools 10 | - make commandline tools get actual commandline arguments 11 | - make the config file location more configurable 12 | - add a proof splitter (to split a long proof into shorter ones) 13 | - add a proof manager (that'll automatically find shares etc) 14 | - add a proper proof creator 15 | - use far_share_hash to jump by 100s to make proofs shorter 16 | 17 | Later future: 18 | - group up shares into merkle trees to reduce size of proofs 19 | - create "authorities" that'll sign merkle roots of such trees to prove 20 | that shares actually existed at said times - this will allow more 21 | granularity in the timestamps 22 | - create a p2p network where users can send data to be timestamped to miners, 23 | removing the need for everyone who wants to timestamp data to be a miner. 24 | - optimize it, maybe even rewrite parts in C 25 | 26 | -------------------------------------------------------------------------------- /add_data_to_proof.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | 3 | # takes a proof (given as argument) and adds data from stdin as the 4 | # proof's data. Doesn't validate anything. 5 | 6 | use strict; 7 | use warnings; 8 | 9 | use IO::All; 10 | use YAML::Syck; 11 | 12 | use ChronoBit::Proof; 13 | use ChronoBit::ProofFile; 14 | use ChronoBit::ProofStore; 15 | 16 | print "Loading your proof, wait...\n"; 17 | my $proof_file = ChronoBit::ProofFile->struct->parse( 18 | scalar io($ARGV[0])->slurp); 19 | 20 | # XXX: haxx 21 | my $proof = ChronoBit::Proof->new_from_binary( 22 | ChronoBit::Proof->struct->build($proof_file->{proof}) 23 | ); 24 | 25 | $| = 1; 26 | print "Go ahead and type your data\n"; 27 | my $data = io('-')->slurp; 28 | print "Thanks, please wait till I save the proof...\n"; 29 | 30 | my $cfg = LoadFile('chronobit.conf'); 31 | 32 | my $ps = ChronoBit::ProofStore->new(outdir => 33 | $cfg->{proofs}, 34 | ); 35 | 36 | my $filename = $ps->save($proof, $data); 37 | printf "Proof saved to $filename\n"; 38 | -------------------------------------------------------------------------------- /chronobit.conf-sample: -------------------------------------------------------------------------------- 1 | port: 8080 2 | chainid: 2 3 | log_conf: log.conf 4 | p2pool: http://127.0.0.1:9332 5 | proofs: proofs 6 | -------------------------------------------------------------------------------- /chronobitd.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use AnyEvent; 7 | use JSON::XS; 8 | use AnyEvent::JSONRPC::HTTP::Server; 9 | use YAML::Syck; 10 | use Data::Dumper; 11 | use Log::Log4perl; 12 | 13 | use ChronoBit::Bitcoin; 14 | use ChronoBit::Util; 15 | use ChronoBit::JSONRPC; 16 | 17 | my $cfg = LoadFile('chronobit.conf'); 18 | Log::Log4perl->init_and_watch($cfg->{log_conf}, 5); 19 | my $log = Log::Log4perl->get_logger; 20 | 21 | my $jsonrpc = ChronoBit::JSONRPC->new(cfg => $cfg); 22 | 23 | sub jsonrpc_handler { 24 | my ($method, $res_cv, @params) = @_; 25 | 26 | $res_cv->result($jsonrpc->$method(@params)); 27 | } 28 | 29 | my %callbacks = map { my $m = $_; $m => sub { jsonrpc_handler($m, @_); } } $jsonrpc->all_methods(); 30 | 31 | my $server = AnyEvent::JSONRPC::HTTP::Server->new( port => $cfg->{port}, host => '0.0.0.0' ); 32 | $server->reg_cb(%callbacks); 33 | 34 | $log->info('starting'); 35 | my $quit_program = AnyEvent->condvar; 36 | $quit_program->recv; 37 | -------------------------------------------------------------------------------- /jsonrpc_client.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use AnyEvent; 7 | use JSON::XS; 8 | use AnyEvent::JSONRPC::HTTP::Client; 9 | use Data::Dumper; 10 | 11 | $Data::Dumper::Useqq = 1; 12 | 13 | my $client = AnyEvent::JSONRPC::HTTP::Client->new( 14 | url => $ARGV[0] 15 | ); 16 | 17 | print Dumper($client->call(@{decode_json($ARGV[1])})->recv); 18 | -------------------------------------------------------------------------------- /log.conf-sample: -------------------------------------------------------------------------------- 1 | log4perl.rootLogger = TRACE, A1 2 | log4perl.appender.A1 = Log::Log4perl::Appender::Screen 3 | log4perl.appender.A1.layout = Log::Log4perl::Layout::PatternLayout 4 | log4perl.appender.A1.layout.ConversionPattern=[%d %p %c] %m%n 5 | -------------------------------------------------------------------------------- /merge_proofs.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | 3 | # merges all proofs given as args 4 | 5 | use strict; 6 | use warnings; 7 | 8 | use IO::All; 9 | use YAML::Syck; 10 | 11 | use ChronoBit::Proof; 12 | use ChronoBit::ProofFile; 13 | use ChronoBit::ProofStore; 14 | 15 | my @proof_file = map { 16 | ChronoBit::ProofFile->struct->parse(scalar io($_)->slurp); 17 | } @ARGV; 18 | my @proof = map { 19 | # XXX: haxx 20 | ChronoBit::Proof->new_from_binary( 21 | ChronoBit::Proof->struct->build($_->{proof}) 22 | ) 23 | } @proof_file; 24 | 25 | my $newproof = ChronoBit::Proof->new_merged(@proof); 26 | 27 | my $cfg = LoadFile('chronobit.conf'); 28 | 29 | my $ps = ChronoBit::ProofStore->new(outdir => 30 | $cfg->{proofs}, 31 | ); 32 | 33 | my $filename = $ps->save($newproof, $proof_file[0]->{data}); # TODO: keep timestamp too 34 | printf "Saved proof to $filename\n"; 35 | -------------------------------------------------------------------------------- /reverse_bytes.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use Data::Dumper; 7 | use IO::All; 8 | 9 | my $foo = io('-')->slurp; 10 | 11 | print scalar reverse $foo; 12 | -------------------------------------------------------------------------------- /sample_proofs/hello_world.proof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/goblin/chronobit/9c0899554a3f57abde812a0b9d35a5570c91e1c6/sample_proofs/hello_world.proof -------------------------------------------------------------------------------- /share2proof.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | 3 | # takes binary share data on stdin (as returned by /web/share_data/share...) 4 | # and makes it into a proof (joining its parent's hash to this share's hash) 5 | 6 | use strict; 7 | use warnings; 8 | 9 | use IO::All; 10 | use YAML::Syck; 11 | 12 | use ChronoBit::P2Pool; 13 | use ChronoBit::Proof; 14 | use ChronoBit::ProofStore; 15 | 16 | my $data = io('-')->slurp; 17 | my $share = share->parse($data); 18 | 19 | my $proof = ChronoBit::Proof->new_from_share($share, ''); 20 | $proof->to($proof->perform); 21 | 22 | my $cfg = LoadFile('chronobit.conf'); 23 | 24 | my $ps = ChronoBit::ProofStore->new(outdir => 25 | $cfg->{proofs}, 26 | ); 27 | 28 | my $filename = $ps->save($proof); 29 | printf "Saved proof to $filename\n"; 30 | -------------------------------------------------------------------------------- /shorten_proof_from_share.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | 3 | # usage: ./shorten_proof_from_share.pl 4 | 5 | # is a long proof made automatically by chronobitd from 6 | # getauxblock response. It's a proof from your original data up to the share's 7 | # hash. 8 | # 9 | # is a short proof made with share2proof.pl from share_data. 10 | # It's a proof from the previous share's hash to the data share's hash 11 | # (data share is the share that contains the originally timestamped data) 12 | # 13 | # Both proofs must arrive at the same hash (of p2pool share). 14 | # 15 | # The script will merge the 2 proofs to create a smaller proof for the original 16 | # hash (it'll output a shorter version of the first file). 17 | 18 | use strict; 19 | use warnings; 20 | 21 | use IO::All; 22 | use YAML::Syck; 23 | 24 | use ChronoBit::Proof; 25 | use ChronoBit::ProofFile; 26 | use ChronoBit::ProofStore; 27 | use ChronoBit::ProofStep; 28 | 29 | my @proof_file = map { 30 | ChronoBit::ProofFile->struct->parse(scalar io($_)->slurp); 31 | } @ARGV; 32 | my @proof = map { 33 | # XXX: haxx 34 | ChronoBit::Proof->new_from_binary( 35 | ChronoBit::Proof->struct->build($_->{proof}) 36 | ) 37 | } @proof_file; 38 | my $newproof = ChronoBit::Proof->new( 39 | from => $proof[0]->from, 40 | to => $proof[0]->to, 41 | ); 42 | 43 | die "wrong proofs" unless($proof[0]->to eq $proof[1]->to); 44 | 45 | # first, copy all large proof's steps up to byte reversal. 46 | # Byte reversal gets us data that goes in the coinbase. 47 | my $ok = 0; 48 | for(my $i = 0; my $step = $proof[0]->step->[$i]; $i++) { 49 | $newproof->add_step($step); 50 | if($step->type == 1) { 51 | $ok = 1; 52 | last; 53 | } 54 | } 55 | die "no byte reversal?" unless $ok; 56 | 57 | # compute that coinbase 58 | my $coinbase = $newproof->perform; 59 | 60 | # this is the first step of shorter proof: 61 | my $step1 = $proof[1]->step->[0]->normal; 62 | 63 | # find me the position at which our coinbase starts in step1's suffix: 64 | die "wtf" unless(length($coinbase) == 32); 65 | my $pos = index($step1->{suffix}, $coinbase); 66 | 67 | # now create a step that'll put that coinbase in shorter proof's perspective 68 | $newproof->add_step(ChronoBit::ProofStep->new(normal => { 69 | prefix => $step1->{prefix} . $proof[1]->from . substr($step1->{suffix}, 70 | 0, $pos), 71 | suffix => substr($step1->{suffix}, $pos + 32), 72 | })); 73 | 74 | # and copy all the remaining steps 75 | for(my $i = 1; $i < $proof[1]->len; $i++) { 76 | $newproof->add_step($proof[1]->step->[$i]); 77 | } 78 | 79 | my $cfg = LoadFile('chronobit.conf'); 80 | 81 | my $ps = ChronoBit::ProofStore->new(outdir => 82 | $cfg->{proofs}, 83 | ); 84 | 85 | my $filename = $ps->save($newproof, $proof_file[0]->{data}); # TODO: keep timestamp too 86 | printf "Saved proof to $filename\n"; 87 | -------------------------------------------------------------------------------- /t/chronobit_jsonrpc.t: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | use Test::More; 5 | 6 | use JSON::XS; 7 | use Log::Log4perl qw(:easy); 8 | 9 | Log::Log4perl->easy_init($INFO); 10 | 11 | BEGIN { use_ok('ChronoBit::JSONRPC'); } 12 | 13 | my $j = ChronoBit::JSONRPC->new(cfg => { chainid => 2, proofs => 'foo' }); 14 | is($j->curhash, undef); 15 | 16 | is_deeply($j->getauxblock(), { chainid => 2, hash => '00'x32, target => 'p2pool' }); 17 | is_deeply($j->set_hash('1a'.'31'x31), JSON::XS::true); 18 | is($j->curhash, '1a'.'31'x31); 19 | is_deeply($j->getauxblock(), { chainid => 2, hash => ('31'x31 . '1a'), target => 'p2pool' }); 20 | 21 | # TODO: test some PoWs 22 | # is_deeply($j->getauxblock('31'x31 . '1a', $ 23 | 24 | is_deeply($j->unset_hash(), JSON::XS::true); 25 | is($j->curhash, undef); 26 | is_deeply($j->getauxblock(), { chainid => 2, hash => '00'x32, target => 'p2pool' }); 27 | 28 | done_testing; 29 | -------------------------------------------------------------------------------- /t/proof.t: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | use Test::More; 5 | 6 | use JSON::XS; 7 | use ChronoBit::Bitcoin; 8 | use ChronoBit::P2Pool; 9 | use ChronoBit::Util; 10 | 11 | BEGIN { use_ok('ChronoBit::Proof'); } 12 | 13 | my $getauxblock_response = decode_json(); 14 | my $p2pool_share = hex2bin(); 15 | 16 | my $hash = scalar reverse hex2bin($getauxblock_response->[0]); 17 | my $aux_pow = aux_pow()->parse(hex2bin($getauxblock_response->[1])); 18 | 19 | my $proof = ChronoBit::Proof->new_aux2coinbase($hash, $aux_pow); 20 | 21 | my @proof_step_data = qw/ 22 | 62bec4f577596e44ea8361ac937e86ddd138c70af1499e3af6d00fdd4b1ef230 23 | 30f21e4bdd0fd0f63a9e49f10ac738d1dd867e93ac6183ea446e5977f5c4be62 24 | 7f622456e0b9ce587556cc1d19f6c3e9b8cd3c947029c473dfdbd7723e025923 25 | 535c7202a304b93f5b4e71dbb0ce1e2f7505664ba693174ff70a82f291320561 26 | 0cf21aa00ed012fa9c963ec38062027c8d2d1fe194e508d937ee450000000000 27 | /; 28 | 29 | # it looks nicer in 'prove' when bin2hexed 30 | is(bin2hex($proof->from), bin2hex($hash)); 31 | is(bin2hex($proof->to), $proof_step_data[0]); 32 | is(bin2hex($proof->perform), $proof_step_data[0]); 33 | is($proof->verify, 1); 34 | 35 | my @prooflist = ($proof); 36 | 37 | my $proof_bin = $proof->dump; 38 | is(bin2hex($proof_bin), '000000000000000000000000000000000000000000000000313370000000140062bec4f577596e44ea8361ac937e86ddd138c70af1499e3af6d00fdd4b1ef2300200000020ad176a9ba046ef19b44999bed63d090401a1148bdb8ac5c5ce76b2e0ad48938000000000'); 39 | 40 | my $proof2 = ChronoBit::Proof->new_from_binary($proof_bin); 41 | is($proof2->dump, $proof_bin); 42 | 43 | $proof = ChronoBit::Proof->new_coinbase2gentx($aux_pow->{coinbase_txn}); 44 | is(bin2hex($proof->from), $proof_step_data[1]); 45 | is(bin2hex($proof->to), $proof_step_data[2]); 46 | is(bin2hex($proof->perform), $proof_step_data[2]); 47 | is($proof->verify, 1); 48 | is(length $proof->dump, 7238); 49 | 50 | push @prooflist, $proof; 51 | 52 | $proof = ChronoBit::Proof->new_gentx2mrklroot($aux_pow); 53 | is(bin2hex($proof->from), $proof_step_data[2]); 54 | is(bin2hex($proof->to), $proof_step_data[3]); 55 | is(bin2hex($proof->perform), $proof_step_data[3]); 56 | is($proof->verify, 1); 57 | 58 | push @prooflist, $proof; 59 | 60 | $proof = ChronoBit::Proof->new_mrklroot2block($aux_pow->{parent_block}); 61 | is(bin2hex($proof->from), $proof_step_data[3]); 62 | is(bin2hex($proof->to), $proof_step_data[4]); 63 | is(bin2hex($proof->perform), $proof_step_data[4]); 64 | is($proof->verify, 1); 65 | 66 | push @prooflist, $proof; 67 | 68 | $proof = ChronoBit::Proof->new_merged(@prooflist); 69 | is(bin2hex($proof->from), bin2hex($hash)); 70 | is(bin2hex($proof->to), $proof_step_data[4]); 71 | is($proof->verify, 1); 72 | 73 | $proof_bin = $proof->dump; 74 | undef $proof; 75 | $proof2 = ChronoBit::Proof->new_from_binary($proof_bin); 76 | is(bin2hex($proof2->to), $proof_step_data[4]); 77 | is($proof2->verify, 1); 78 | 79 | # another set of tests for p2pool shares 80 | my $share = share->parse($p2pool_share); 81 | 82 | $proof = ChronoBit::Proof->new_from_share($share, hex2bin($proof_step_data[4])); 83 | is(bin2hex($proof->perform), $proof_step_data[4]); 84 | is($proof->verify, 1); 85 | 86 | done_testing; 87 | 88 | __DATA__ 89 | ["0014000000703331000000000000000000000000000000000000000000000000","01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff3803ea1c032cfabe6d6d30f21e4bdd0fd0f63a9e49f10ac738d1dd867e93ac6183ea446e5977f5c4be620200000000000000062f503253482fffffffffcf651d0600000000001976a91457a1c076e8ad604cb0a6b6461913b613fc59b90288ac33f00700000000001976a914d5ef733f4597ba24433f32d0cb0c54d6745f5d1c88ace84c0800000000001976a9146c320cd789a75f6d2d1cd0a12613d5bc8b532a9888ac465e0800000000001976a914a8bbcfd4a76ec02cd2e058ae2aa8e7810680a3d688ac5f9b0800000000001976a9141ce56bfc90d55db0f1dc88a3bf3e8fd4d4d9db5388acd4d40800000000001976a914a706d281e94d9966cf11ad2f252c744ad8e36dd488ac94e40800000000001976a914bf7a9d0ec051a1199bafed03b14929e9af572e3a88acc6090900000000001976a9147424ba2dd930b11a9fd53a230eeb99bf2c640e5588ac403f0f00000000001976a9140edc735b11ecadc37d62cf946915af886b10c38988acda011000000000001976a9146a1be2a3aa6758fbbac4573bd07093eb4e65524888ac5bcf1000000000001976a9147f672196e5c450127bea0e838ef243e9a68252a588ac3d971100000000001976a914afe1cf14e758f59693870afb1730a4d91b7e23a688ac7bd81100000000001976a914c3a2f3551409af20a481ecfdb03fd2e3848343d588ac53ee1100000000001976a914dc9849ff11880ec24cabc2568dda903da0cdb2d588ac0ab01800000000001976a9144c1c48404cf93debc338ead63c46983606a6a82788acaed61800000000001976a9142ce4bc0302990935f84afca3ae1a0fc8877953a788acfbf61800000000001976a914eb24b0a111784ae67d465509cd852140ba66eb2888ac7cc51900000000001976a9144b47eb499f82d9c6927c93d63937332ca2cd602a88ac05c71900000000001976a914f38e8810c9b7cedcc2a7900a4269a9f10f3da0b088acefd31900000000001976a91458a08ccf0fb238718d3904714000b17a81f0060d88aca5411a00000000001976a914f5be4d5ec4957f26ee629b9a768598874a36ef1a88acc9921a00000000001976a914e8c1968b8e6cb664822a502ecd5e2a8c2288b39888aca0981a00000000001976a91454a22bab38b27589d32e2b9c8c2428905dc1702c88ac071d1b00000000001976a9141aedb9646b5e11b43685fb94ffed1726f913374088ac18241c00000000001976a914d184ec076ad44a02c8bcd646ffeb402bb363ab6088ac6f3a1f00000000001976a914ef1ab3953208cfe4d1acf002676a6c6f82c5d87788ac666e2000000000001976a9140a4f4dbf17aa053f327777c40e7827a6ed632ccb88ac5f7a2000000000001976a914adfc4367b204d75386c83775e97164b987d9297d88ac64de2000000000001976a91417ccf8dbbaa66812ce74373ca7dd2828b6949d2e88ac9f2d2100000000001976a9140ce91af8203e9e69b2e1668160910e59c437ea5188ac8fbf2100000000001976a91432ab0fdb8fd30638f3c0189f058f20e6d26a17b088acc7422200000000001976a914069c0fe194b28e2dcb5d259fe358e7ed93ef723c88ac415a2200000000001976a914eae66d02fc7bb070d5f5a727318272dbc874050b88ac7d0f2300000000001976a91481f4f5d4d4ea2476f376bcb96037bcefa04c880d88ac5b522300000000001976a9140929d7db8745a9f2dc06017d00c74439c3def21c88ac6d962300000000001976a914cfbb9930ac973bee3c2972770c61efad9f23598788ac558c2800000000001976a91449c85ec220eec894e63b705e889b0932ce49001c88ac2d9e2800000000001976a9145f949967ef7aebebb3bb84c6abbf8aeca970ce5988acce2b2900000000001976a914ff85800ad6297e8ce459a04f6746477dd01f570b88ac52fc2900000000001976a9141dc79b2c61ba9e2381fedb4a63f54ea8cf950fc888ac82a42a00000000001976a914a96c0fce9077a28536c2ac46969930f75e0d05f488acfbe92a00000000001976a914677085ab0ad5edab1ae1609858a32b95d36c866488ac6b1e2b00000000001976a91450fc370c5d843e99fcdbe233f223d9ff61b2915688ac432f2b00000000001976a9144ff8472b4bf4482dd19dd530e8f6bae3c337241b88ac97332b00000000001976a914407c2ecd56a56c0b69ce9d7eb90cd5422756a2e088ac91f82b00000000001976a914161199f7bbed0222b94d03dcdd24b15a705f5f1188ac50782d00000000001976a914e295305eb7e0a8e86f79fd0c5125a1b5c44c6aa588ac24fa2f00000000001976a914a4b0a4195138269431018ce43a981d1d0cff5c7d88ac31553100000000001976a91407f021706161902974f6d62eec4612a77ceed20a88ac43ee3100000000001976a914a525a0aa2557bbf45abceb3bcb558c9f95de20e988ac9ffe3100000000001976a914f09506198accde339cc4575ca8350daf8458f9cd88ac16043300000000001976a914d26de0e9363cab9cb8df2a7647674bcc523d9d6788ac438a3300000000001976a914a3a2a4bc1336de8b087cc4900ca48c8afb0e671488ac2cd43300000000001976a914711081cae27af99f99373efa25ae4f64c6ef6ba788ac21f13300000000001976a91491827adef9de1adf76225769dbffd946893fa33188ac85183400000000001976a914244298ec7404b20e5715ed8ed9df1f346080399a88ac17643400000000001976a9141083ba341f2e7894d1d5f012503cd5729ba64d9488acc9583600000000001976a914c52c18005c5773e5b513aadc31c8a1fed3fe7ad588ac0b1a3900000000001976a91415f98d3a70ce32f1c8e31719bee0357c7cf3278888ac10373a00000000001976a9140676d03b8b826effc748a062241fd861f4fab58388ac5dbd3a00000000001976a91491c64c844611e19a145ff07b88ecb699c0b41b1488ac8dd03b00000000001976a91405fd5e0a51b81b2b9ffb63230c8737ca8bdc0f7e88ac82673c00000000001976a914f19595088875fe2c80a118e4c7e24a82370cfd8e88acefb13d00000000001976a914e349adcc7bab6e87ef16b7980c052c893c40e98588ac21f64000000000001976a9145dbab6e7fdd76aa648670863a770fd100e5bbd8d88acdf484300000000001976a9140a57e95b1bf862cf3c03b1c12e602f0442ba71fb88ac7b4f4300000000001976a914e12535c90ad15a1b2a50ae43a93746603cbad6bb88ac78a94400000000001976a914db4f804a2cb320b676b09bea170a0f2a51aa3e4d88ac85b14400000000001976a914181ef6a86b05fb565fababe3be4600747e530da088ac48764500000000001976a914dced5af0a68dd47868205ad2067e92d98ea404de88ac057c4800000000001976a9144a4a1b04353b90b947b453949c0ca042d279345988ac11434900000000001976a9147487fe51c0a6a2188317835d21ada968ffb2e35688ac9c794b00000000001976a9149d1f7e94a069768d1a400cd008eb9bfef87eace688acee884b00000000001976a914bc75b9a719d0330cfd9bb37b4f785aaf06504c6c88ac45fa5100000000001976a91408d0008497c7d48e222699e1b38b663e9531849e88ac82685200000000001976a914775e5a64eb13041a3b1191ceac7cd192a61fc9fc88ac37ce5400000000001976a9147f76ed0f250d98df17ddcb127a6f68e62e9e626e88acf7315500000000001976a914767a4052763b100c9e1695631f3a88e08b6e4fbf88acf44b5500000000001976a9148b4ab71f83da31251c1507b7d189661db6dbf80e88ac24745500000000001976a9144d050fa8ad63ffbe59fe12bd5620fda906f031fc88acc68c5500000000001976a914a1d012ac07c72828483fdec153a77e3ab308d82788ac05e45500000000001976a9148c9360e25a76046c63816a38476253821850035588aca31b5600000000001976a914e9b71ac3599a3c431414b9554587d7d87dfa2fe488ace8ad5b00000000001976a914ae84e741f3242a9e211bc36ceebcecff23aaea8c88ac6bfb5c00000000001976a914d906849f8e0988d44fd341ccb518c61e8a25288888aca3576000000000001976a914c2cb7f1fbe7b2da598096e4162ad3c92c772335988ac48586000000000001976a91469f5f2387bcb3fd8d3c2767cafa2cd129f334f3588ac7bb76000000000001976a91480c11f87be6639eff86bb781e392cc7833871bc988ac394a6100000000001976a9146f8c32f2c4147e0df5341d5adc58aa3cea1197f588acdffe6400000000001976a914e69f755fcbb511cfc0d12722c3186e18f3ce589688ac0e346600000000001976a914cf2013b84b2fdae45d89554268635a76a4f0e8b988acf0436700000000001976a9143e9e24b602b382961357ed807eda5445d080678488ac169f6700000000001976a914168ad174ee6a24b9792dd7d46d941b076d16929488ac350e6900000000001976a91483aa26f9c40165c65a7087157ce153ee063a295788accb386900000000001976a9141dfd861550dc47711a83a8ae2149df95be229e5688ac724c6b00000000001976a91421bd2c39039c8d2fbee1bd069105de8599d9c26f88acfed76c00000000001976a914e2004e457f79d0a4e9b8bee08b56915db1eaab7588aca42b7000000000001976a914ea1355e1845632cae5d4e6cf0e3c24898d0fbbe888ac7a2d7600000000001976a914e65c26086dfa3de84ed6929b777cc939983975d188acd0c57700000000001976a914f9565f446f52721b7ca9699235717671cf2b356888ac1c677900000000001976a9144a3e7faebd1b0ae53bff159046b645eebc52b14088ac5a2f7c00000000001976a91436a5289cb68303ef16c92eff57170af92baf4e7088acb1927c00000000001976a9141fcca5d999a2d92b0a512f33dabee81af91af8a288ac56847e00000000001976a914f0a15633d394661e619f6c954b5141e88e4bc76688acbe858200000000001976a914c75d434db1a14fdedcb57d0b0470c71289e837ad88ac71288400000000001976a914053d3c3663207dcefe19823a9a8f3201cf9a8bce88ace50e8700000000001976a914792f9205154a6b2afd42b0515f5795e470b4b3f688ac625b8800000000001976a91406593f15f2e79c5bbad835e21741d07370925b1588ac63089400000000001976a9140cb6f1c0e7e968a543379bb5ce61d388c127a94488aca59d9400000000001976a9149ff7f1f0f6f28af5a32f36a53bd9d93064f0984788ac17d29800000000001976a9142e0eb65711b9401b6812f18a8e7d9a7dc385d3f488acf2679a00000000001976a914e205b664ff00fd8be0a78cbee242d60f83af69e188ac172c9c00000000001976a9143dcdb58f98e0eb22894b177cb0d566d4eed437bc88ac52549d00000000001976a914f770bd8837733b0e33eb0817ccc087ced11901ca88ac9ce5a000000000001976a9145479d3a0114c8cddf9db7a9968c2080310099b5188ac2024ac00000000001976a914a0939f3effe7b5646fd86db8715558467b328e9a88ac9eebac00000000001976a914dd7a879a2330eaddbff7ca726c4f35442e9ba3fd88ac08a7b000000000001976a9148e293259013c3071fe03b64e55b8545aad6cd5e488ac8641b600000000001976a914669a712c3073b70b009357f239d32c99e79a431d88ac56dfbb00000000001976a914f5464758c5a05fab37beef1f3bff9b2a2a8388dc88acf174bd00000000001976a9147e3b4eeccdaf87bd2243204a3ccc31eb65873fea88ac4da2c100000000001976a91404a64323ddc9c0385aaeebe53eea5c8f2eed6cf588acbfd7c200000000001976a914e73203a76ecb13a763b9396ee1d15a0c4c6a201288ac20f7cc00000000001976a914015dbc353e51ced0794cd834666e715ff649ee6988ac0c53cf00000000001976a91471c705116c9ce239d949903949f90561b470477988ac2521d600000000001976a914c4ccb62dfe223631f2e86c47c3fd6663dd49d4a288ac1b11d700000000001976a9147f92bc474f4d80ac06c8f02d57915bf550c8447b88ac2dcede00000000001976a914eabe80ff2219adf238cee601eb86296760534d7a88accd7ee100000000001976a9140c550772c131a6771929a4130c79c0307a28dcd288acc56de300000000001976a91470458bbd2167bd43f5780b7bab65aa42fa1eab5b88ac851ae400000000001976a914055dd083a5db9bae3771c7b59443ff65f3bcac3588ace9f2e900000000001976a914bd36b03bde2750dbf410c77f417664ff057ba1e888acdef5f000000000001976a914ee3b1fd4dcea91460a2c55ae8193d6e4836717b688ac113ff300000000001976a9144ed72d734ce7080b17203f07263646b81c5f747488aca558f500000000001976a914e526853a5b91ad63cad3fcfeebed314f15474def88acd0d6f500000000001976a914a90e0284ff5985943e1d8635b06b3a067cdca71888acba63f800000000001976a91427c7ee54b36f4470e14aec859544f7f6ae7dddb688ac8650fe00000000001976a914aefe856bbf3082f969f18f45ddc0ef40d6d6e22988ace3e60101000000001976a91410519f2852d61880aa241691187df0a2fab8631388ac857c0301000000001976a914345281ac54380e98ec5001ecfaea019600da68ba88acd5100501000000001976a914ce913f3d4d7d5cad6759c907ee1fca56d164f60588ac29360601000000001976a9146f7b51c376fd6dea8edb2007d049f60bb6071a1488ac023d0d01000000001976a9146ce0ad4a7c9a08d602a346f17b1ce5e64b339ab288ace29f1501000000001976a914c98b52b481116b4e2d2277754e315dee32a832f188ac227d1701000000001976a914d2236f9f3440b372ff6b82adf163497207544a6d88ac81212701000000001976a91485a837db1cfb5e0c0ac07b6deab52f96e2aadc9288ac21d02701000000001976a914c0d73c61fc15d89f04595cefcbeeec809ebe939788ac3aac2801000000001976a91433c1b0a94ee653f820adc8a0ebb46f3e03b9787c88ac34172a01000000001976a914a739fc4a3078bded68ca37a8f51aab017565eb7c88acfe8b3101000000001976a9146f0af2e9a45331e4c98c6b706fdac7a142b4e33d88ac57ee4c01000000001976a914509341b5913426c95a82c45522d723bd0994b17688ac51905301000000001976a914d4e2b8073c3d2b244547574afde509e7f6db9dd788ac324a5d01000000001976a9147f2843d94041127a4090120367ba88fd1158b79088ac34355e01000000001976a914bcf82a713a320942ce47e073787b48e73ed21bc388ac39a25e01000000001976a914093064e56638d7d2b7f122d073f36f2adbddae3988ac27ef6001000000001976a914d60a86e3722e05fc1edde4b3f18bf37c133169ec88ac79096e01000000001976a914a2555d2d1a9702a9c550c09e61d6573c510cbd4d88acb74a7701000000001976a914044ce4661a426460ee298a4fc0be56d9531cab3688ac227a8101000000001976a914465726c2fd42218e0f4efa15f9ca23607fa3aefe88acaf918501000000001976a9148788d4489e1a43578a6c0968b0d8f280be6ff16c88ac85a19201000000001976a914c2b2be2b6c0ad98b6b9661a1450465e52268288588ac18cf9301000000001976a9140af27cf6a67f19572ab58189994866937284e13f88ac4d42c001000000001976a91495ab2e374619aad24375d0e374ee697e9075cb5488ac3feec301000000001976a914bc589b3115f57c322c367f9e044e69e67934cf4588ac694bcb01000000001976a9141e527bb6f49a30b15d6e8a628c69eb086009db5388ac4a72d101000000001976a91481721c0ef7136b22fca8ba5386850e53479b53aa88ac80add101000000001976a914f025c7c67f6b5abbfd852906b6abea1f557ff75088ac3837da01000000001976a914c168323170c52e9a28c4b069da735bffe8d651ab88ac6719fe01000000001976a9149e964bfd4d25ad4e168b50f86ed2a2f32b5203fe88accc081002000000001976a9144a2a964281e5392567f12514e1721e2dbd6c9fa688ac14d31202000000001976a91477d07e5e8923c38e7f1c76b3096cc1cad2f1e48c88ac21852502000000001976a914626cfbd1437fb8d623b339c908dd2f966bc51ec988accf0f3602000000001976a91490a2c9d586ccda2226665990253a4c2303794e5388ac45cf4702000000001976a914e75c0a4d431629abd09a64ef76739510e560c75288acd56a7d02000000001976a9142e28efc5cd25c238ca4e77d2e33f0fd1e90d3e7188ac7ce87e02000000001976a9140e395d4568e071968db0e8e775f891021d4c82f088acfc267f02000000001976a914d766fbabc1881c81a87c32b2aef4053f0039603488accec39002000000001976a914160767ea477550a19b9fbb7d91cc3047e8adac3588ac8bf6a702000000001976a91418a99959bce205725051f5ead31c4b88379a4fcb88ac3699be02000000001976a9141b616c13634d2e4bef0fa408413f47111ffbd35788acaf53e802000000001976a914d9f4097a319c5c7d7ca9024776e84ac482fa127988ac27530003000000001976a914047e424ed150be3936648a4ec80b08a3927e5d5d88aca1960703000000001976a914c843ef9d518f2da51ebbafb1e3590c32f45e1d0788ace4df3903000000001976a914f2938370bf588930a231c5def93ab4cf3154575588aced4ada03000000001976a9149b0551defdcbf45fd256b40557bcfb90d39ba73688ac9c96fd03000000001976a9149ef0d190d4e5ebb2f153ba2035cdb65b6ad3a62c88aceab40504000000001976a91480207c9f445b47ec5e2a4607861ea2d8fd87718188ac2b772704000000001976a914e5dacd78be3e6780a0ca60f5613e4e9da28e65b988ac2b422d04000000001976a914de845847f9853f4bdb99753be0457e47e0863bc888ac545a7804000000001976a91405069093c8a37b3fa9d3a396a4f8c631aa79cfbc88ac783b9904000000001976a914391ecba1418302c1822c7c65f9aeb647795ed81c88ac91e5f404000000001976a91452fc55d0d02cd0a08dab37e09d587e4b8548c90888ac8570fb04000000001976a9142b05887a83c7fc883917757cb7843388990e38ae88acded07f05000000001976a914ba0b189cd808746a1efc9921665dfcfe301222e288ac504ad205000000001976a914b530c7bd1058dc9dcb7a29d5fd3ecefd5cd8e57988accb551706000000001976a914730f40ca59fa6c61a140ca07db33f33c143a649488acbace4b06000000001976a914fa183499bcf8cc1bae1763cf50fd61f9601ec83088ac03d96f06000000001976a9141c887da50ed886a6e68a3b01f0b9dde5f807ca6888ac1c609706000000001976a9143dbb1f0660fa3cc5b4fbe3bd916113794571f1a988ac617e0808000000001976a9149c7a3ddca3446a6e36160495a78317fe1cb8f1cc88ac06539108000000001976a91466d60d45b8aa75b88fd1bb4d8b8a7950950dc6e588ac98f3a708000000001976a91427cc7e0def9fb434d51d98ee523bcc1e7514390688ac0fdaa109000000001976a914e5145dd1908a5cd08ece0a7b7b1bf57133b39f1088ac65ead90d000000001976a91473bdb794942fba888b0d76d418e9d946b8ad4afa88ac95237d2a000000001976a9147db536ce753378064c58ccc9cffdc222626fd0f788acb53e0b0100000000434104ffd03de44a6e11b9917f3a29f9443283d9871c9d743ef30d5eddcd37094b64d1b3d8090496b53256786bf5c82932ec23c3b74d9f05a6f95a8b5529352656664bac000000000000000021200057a0494930b014ad2c8bfd74fbb6c8d22b8fc80b040698e249f48651f0a219000000000cf21aa00ed012fa9c963ec38062027c8d2d1fe194e508d937ee45000000000007d213ee1172fe8c4db63ef042509342c3aab34acf0f8f952bc588debb8c799c8d8c909848d0bfcb0caf36c55a101ba101f5f581f0b7383d7a2786ad2b0089042ccbb202d8cf953f945833c84189b707e0db2707474d25dce3c77f70b22d7ba204e1af622f5c266b00b6f2178be447e00b6e28d5448e2c46cf9089d939d9bdae8d48dfb6f6bc237a5e5fac3f464de8681ef530777bbe24ce477f13cdc4fdd81d47092544df014a9297b3edf37d984e880bbc7ce0cf87a66c9c1ca8d144efa29448404cc8d9a00bccdc80d40dbce7a8fb68ead50483b2bc3f4c520cb616049f90340000000001ad176a9ba046ef19b44999bed63d090401a1148bdb8ac5c5ce76b2e0ad4893800000000002000000a4a46ae7468a4b7036a00477bdaa9036d4f9e660a575b914c502000000000000535c7202a304b93f5b4e71dbb0ce1e2f7505664ba693174ff70a82f2913205617d678150ef75051a114287dc"] 90 | 04fddc0102a4a46ae7468a4b7036a00477bdaa9036d4f9e660a575b914c5020000000000007d678150ef75051a114287dc34d5b2500c94266520ba60cbaf94a030a47a14a6813a23b46f8f2500000000003803ea1c032cfabe6d6d30f21e4bdd0fd0f63a9e49f10ac738d1dd867e93ac6183ea446e5977f5c4be620200000000000000062f503253482f05e40bcd9c7a3ddca3446a6e36160495a78317fe1cb8f1cca020692a010000004801000513dceb70f26e94c3c5f46a605100e1bb54a082abc1d3e7a0591d4a00000000004a5c561b4a5c561b5e628150000006926898e2a06f0b7c4364cf4db5060121d544ec58d0ba363b941ab9a44a94d4fdf71b07d213ee1172fe8c4db63ef042509342c3aab34acf0f8f952bc588debb8c799c8d8c909848d0bfcb0caf36c55a101ba101f5f581f0b7383d7a2786ad2b0089042ccbb202d8cf953f945833c84189b707e0db2707474d25dce3c77f70b22d7ba204e1af622f5c266b00b6f2178be447e00b6e28d5448e2c46cf9089d939d9bdae8d48dfb6f6bc237a5e5fac3f464de8681ef530777bbe24ce477f13cdc4fdd81d47092544df014a9297b3edf37d984e880bbc7ce0cf87a66c9c1ca8d144efa29448404cc8d9a00bccdc80d40dbce7a8fb68ead50483b2bc3f4c520cb616049f9034 91 | -------------------------------------------------------------------------------- /t/proofstep.t: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | use Test::More; 5 | 6 | use ChronoBit::Bitcoin; 7 | use ChronoBit::Util; 8 | use ChronoBit::SHAState; 9 | 10 | BEGIN { use_ok('ChronoBit::ProofStep'); } 11 | 12 | my $test_msg1 = ; 13 | my $known_serialization = ; 14 | chomp $known_serialization; 15 | 16 | my $msg1 = substr($test_msg1, 0, 113); 17 | my $msg2 = substr($test_msg1, 113, 90); 18 | my $msg3 = substr($test_msg1, 203); 19 | 20 | my $ps = ChronoBit::ProofStep->new( 21 | normal => { 22 | state => ChronoBit::SHAState->new(len => 0, state => ''), 23 | prefix => $msg1, 24 | suffix => $msg3, 25 | }, 26 | ); 27 | 28 | is(bin2hex($ps->perform($msg2)), 29 | '35314b8ce740af950adbf892d62886f8e1ec5d5c197fdc9577479832bb5825a0'); 30 | 31 | my $ps1_bin = $ps->dump; 32 | is(bin2hex($ps1_bin), $known_serialization); 33 | 34 | my $ps2 = ChronoBit::ProofStep->new_from_binary($ps1_bin); 35 | is($ps2->dump, $ps1_bin); 36 | 37 | done_testing; 38 | 39 | # the data is long enough to exceed 255 bytes in var_ints 40 | 41 | __DATA__ 42 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sit amet enim ipsum, sit amet elementum justo. Vivamus sed felis erat, ac convallis eros. Quisque nisi felis, dignissim a pulvinar id, sagittis ut ante. Aliquam erat volutpat. Fusce dolor lectus, porttitor nec tincidunt ut, adipiscing id magna. Nulla vel massa aliquam augue luctus suscipit non eu sapien. Pellentesque nulla nulla, varius a venenatis vitae, mattis ac odio. Vestibulum vitae nibh sit amet ipsum sodales cursus. Vivamus id lacus dolor. Donec vel quam enim. Ut vel dui non lectus lacinia iaculis. Curabitur ullamcorper malesuada metus eget molestie. Nunc vitae nisi eu mauris pellentesque tempor. Suspendisse tempor lobortis justo, sit amet bibendum augue feugiat eget. Curabitur faucibus sollicitudin arcu quis sodales. Nam blandit facilisis orci ut scelerisque. Aenean consectetur velit eget leo viverra in sollicitudin tortor placerat. Aliquam auctor diam dapibus sem bibendum eu posuere dui gravida. Ut vestibulum luctus laoreet. Donec et sollicitudin est. Suspendisse potenti. Nullam lorem odio, gravida vel egestas sit amet, accumsan non nulla. Etiam risus metus, venenatis id dictum eu, ultrices id nibh. Phasellus eu neque non ante malesuada congue. Praesent pharetra eleifend diam. Ut quis vehicula odio. Vestibulum lacinia leo at nisl tincidunt nec viverra arcu laoreet. Aenean ullamcorper hendrerit lobortis. Fusce sodales massa id nibh mattis luctus. Pellentesque non libero vel neque bibendum fermentum sed at justo. Aenean porta, erat et lobortis fermentum, felis massa mattis ligula, nec consectetur nibh ante at mi. Donec at massa dui. Integer vitae nunc a nulla condimentum faucibus. Donec nec est turpis, nec vulputate magna. Morbi semper elit et leo vehicula suscipit. Sed fringilla, mauris sit amet dictum porta, libero elit bibendum magna, cursus aliquet sapien arcu vel nisi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla eu dolor eget arcu luctus elementum. Proin vel lorem tellus, eget eleifend enim. Fusce sem dui, lacinia ut vulputate at, tempor aliquet lectus. Duis non diam vel eros tristique convallis. Phasellus quam ipsum, congue nec interdum in, sagittis ut est. Aenean pharetra fringilla mi, in molestie tellus laoreet semper. Proin a odio turpis, non lobortis justo. Mauris faucibus tortor sed arcu ullamcorper varius. Suspendisse potenti. Pellentesque pharetra posuere congue. Donec id nulla justo, ut tempus erat. Etiam eget placerat libero. Cras sit amet magna a velit pharetra mattis. Praesent dui mi, scelerisque vitae tincidunt vitae, bibendum eu sem. In hac habitasse platea dictumst. Morbi at consectetur est. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Mauris nulla massa, viverra non faucibus nec, ornare vel lectus. Etiam non neque ut diam iaculis consectetur. Nulla vitae erat dapibus nunc dapibus hendrerit. Nullam tempus lorem ut elit consequat in faucibus massa tincidunt. Ut nec auctor nulla. Mauris cursus adipiscing dignissim. Aenean pretium, eros egestas rutrum sollicitudin, turpis libero lobortis felis, quis fringilla ligula eros sit amet turpis. Nulla dapibus urna ac metus volutpat sed tristique nisi volutpat. 43 | 0000714c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e20517569737175652073697420616d657420656e696d20697073756d2c2073697420616d657420656c656d656e74756d206a7573746f2e2056fd1c0c697474697320757420616e74652e20416c697175616d206572617420766f6c75747061742e20467573636520646f6c6f72206c65637475732c20706f72747469746f72206e65632074696e636964756e742075742c2061646970697363696e67206964206d61676e612e204e756c6c612076656c206d6173736120616c697175616d206175677565206c7563747573207375736369706974206e6f6e2065752073617069656e2e2050656c6c656e746573717565206e756c6c61206e756c6c612c2076617269757320612076656e656e617469732076697461652c206d6174746973206163206f64696f2e20566573746962756c756d207669746165206e6962682073697420616d657420697073756d20736f64616c6573206375727375732e20566976616d7573206964206c6163757320646f6c6f722e20446f6e65632076656c207175616d20656e696d2e2055742076656c20647569206e6f6e206c6563747573206c6163696e696120696163756c69732e202043757261626974757220756c6c616d636f72706572206d616c657375616461206d657475732065676574206d6f6c65737469652e204e756e63207669746165206e697369206575206d61757269732070656c6c656e7465737175652074656d706f722e2053757370656e64697373652074656d706f72206c6f626f72746973206a7573746f2c2073697420616d657420626962656e64756d206175677565206665756769617420656765742e2043757261626974757220666175636962757320736f6c6c696369747564696e2061726375207175697320736f64616c65732e204e616d20626c616e64697420666163696c69736973206f726369207574207363656c657269737175652e2041656e65616e20636f6e73656374657475722076656c69742065676574206c656f207669766572726120696e20736f6c6c696369747564696e20746f72746f7220706c6163657261742e20416c697175616d20617563746f72206469616d20646170696275732073656d20626962656e64756d20657520706f73756572652064756920677261766964612e20557420766573746962756c756d206c7563747573206c616f726565742e20446f6e656320657420736f6c6c696369747564696e206573742e2053757370656e646973736520706f74656e74692e204e756c6c616d206c6f72656d206f64696f2c20677261766964612076656c20656765737461732073697420616d65742c20616363756d73616e206e6f6e206e756c6c612e20457469616d207269737573206d657475732c2076656e656e617469732069642064696374756d2065752c20756c747269636573206964206e6962682e2050686173656c6c7573206575206e65717565206e6f6e20616e7465206d616c65737561646120636f6e6775652e205072616573656e7420706861726574726120656c656966656e64206469616d2e202055742071756973207665686963756c61206f64696f2e20566573746962756c756d206c6163696e6961206c656f206174206e69736c2074696e636964756e74206e656320766976657272612061726375206c616f726565742e2041656e65616e20756c6c616d636f727065722068656e647265726974206c6f626f727469732e20467573636520736f64616c6573206d61737361206964206e696268206d6174746973206c75637475732e2050656c6c656e746573717565206e6f6e206c696265726f2076656c206e6571756520626962656e64756d206665726d656e74756d20736564206174206a7573746f2e2041656e65616e20706f7274612c2065726174206574206c6f626f72746973206665726d656e74756d2c2066656c6973206d61737361206d6174746973206c6967756c612c206e656320636f6e7365637465747572206e69626820616e7465206174206d692e20446f6e6563206174206d61737361206475692e20496e7465676572207669746165206e756e632061206e756c6c6120636f6e64696d656e74756d2066617563696275732e20446f6e6563206e656320657374207475727069732c206e65632076756c707574617465206d61676e612e204d6f7262692073656d70657220656c6974206574206c656f207665686963756c612073757363697069742e20536564206672696e67696c6c612c206d61757269732073697420616d65742064696374756d20706f7274612c206c696265726f20656c697420626962656e64756d206d61676e612c2063757273757320616c69717565742073617069656e20617263752076656c206e6973692e20436c61737320617074656e742074616369746920736f63696f737175206164206c69746f726120746f727175656e742070657220636f6e75626961206e6f737472612c2070657220696e636570746f732068696d656e61656f732e204c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e20204e756c6c6120657520646f6c6f7220656765742061726375206c756374757320656c656d656e74756d2e2050726f696e2076656c206c6f72656d2074656c6c75732c206567657420656c656966656e6420656e696d2e2046757363652073656d206475692c206c6163696e69612075742076756c7075746174652061742c2074656d706f7220616c6971756574206c65637475732e2044756973206e6f6e206469616d2076656c2065726f732074726973746971756520636f6e76616c6c69732e2050686173656c6c7573207175616d20697073756d2c20636f6e677565206e656320696e74657264756d20696e2c207361676974746973207574206573742e2041656e65616e207068617265747261206672696e67696c6c61206d692c20696e206d6f6c65737469652074656c6c7573206c616f726565742073656d7065722e2050726f696e2061206f64696f207475727069732c206e6f6e206c6f626f72746973206a7573746f2e204d617572697320666175636962757320746f72746f7220736564206172637520756c6c616d636f72706572207661726975732e2053757370656e646973736520706f74656e74692e2050656c6c656e74657371756520706861726574726120706f737565726520636f6e6775652e20446f6e6563206964206e756c6c61206a7573746f2c2075742074656d70757320657261742e20457469616d206567657420706c616365726174206c696265726f2e20437261732073697420616d6574206d61676e6120612076656c6974207068617265747261206d61747469732e20205072616573656e7420647569206d692c207363656c657269737175652076697461652074696e636964756e742076697461652c20626962656e64756d2065752073656d2e20496e206861632068616269746173736520706c617465612064696374756d73742e204d6f72626920617420636f6e7365637465747572206573742e2043756d20736f63696973206e61746f7175652070656e617469627573206574206d61676e6973206469732070617274757269656e74206d6f6e7465732c206e61736365747572207269646963756c7573206d75732e204d6175726973206e756c6c61206d617373612c2076697665727261206e6f6e206661756369627573206e65632c206f726e6172652076656c206c65637475732e20457469616d206e6f6e206e65717565207574206469616d20696163756c697320636f6e73656374657475722e204e756c6c6120766974616520657261742064617069627573206e756e6320646170696275732068656e6472657269742e204e756c6c616d2074656d707573206c6f72656d20757420656c697420636f6e73657175617420696e206661756369627573206d617373612074696e636964756e742e205574206e656320617563746f72206e756c6c612e204d6175726973206375727375732061646970697363696e67206469676e697373696d2e2041656e65616e207072657469756d2c2065726f7320656765737461732072757472756d20736f6c6c696369747564696e2c20747572706973206c696265726f206c6f626f727469732066656c69732c2071756973206672696e67696c6c61206c6967756c612065726f732073697420616d6574207475727069732e204e756c6c6120646170696275732075726e61206163206d6574757320766f6c75747061742073656420747269737469717565206e69736920766f6c75747061742e0a 44 | -------------------------------------------------------------------------------- /t/sha.t: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | use Test::More; 5 | 6 | use ChronoBit::Util; 7 | 8 | BEGIN { use_ok('ChronoBit::SHA'); } 9 | BEGIN { use_ok('ChronoBit::SHAState'); } 10 | 11 | my $test_msg1 = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum'; 12 | 13 | my $sha = ChronoBit::SHA->new(256); 14 | $sha->add($test_msg1); 15 | is($sha->digest, hex2bin('bfe8ee358697cbd746acd482c37891dca980bd0401d596dabf5551857b6b53a2')); 16 | 17 | $sha = ChronoBit::SHA->new(256); 18 | $sha->add(substr $test_msg1, 0, 133); 19 | $sha->add(substr $test_msg1, 133); 20 | is($sha->digest, hex2bin('bfe8ee358697cbd746acd482c37891dca980bd0401d596dabf5551857b6b53a2')); 21 | 22 | $sha = ChronoBit::SHA->new(256); 23 | $sha->add(substr $test_msg1, 0, 133); 24 | my $state = $sha->get_state; 25 | undef $sha; 26 | $sha = ChronoBit::SHA->new_from_state($state); 27 | $sha->add(substr $test_msg1, 133); 28 | is($sha->digest, hex2bin('bfe8ee358697cbd746acd482c37891dca980bd0401d596dabf5551857b6b53a2')); 29 | 30 | done_testing; 31 | -------------------------------------------------------------------------------- /t/sha_state.t: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | use Test::More; 5 | 6 | use ChronoBit::Util; 7 | BEGIN { use_ok('ChronoBit::SHA'); } 8 | BEGIN { use_ok('ChronoBit::SHAState'); } 9 | 10 | # OK, here's what p2pool gives: 11 | my $state = ChronoBit::SHAState->new( 12 | state => hex2bin( 13 | 'a1405e36d6b21fe6287e18765b5140590b7e34d6f52d8fbcd1d56dab1dcf9ad5'), 14 | len => 7494, 15 | extra_data => hex2bin('000000002120'), 16 | ); 17 | my $sha = ChronoBit::SHA->new_from_state($state); 18 | $sha->add(hex2bin( 19 | '0b08c84e31867549f9189cb9c696d61916d3ffa9ac8fec4a1812deb7f10dac4200000000' 20 | )); 21 | is(bin2hex($sha->digest), 22 | '58ba6c61a3700085304d1cb5461a6237e43730745d04cf55f4a9b33da6132ac9'); 23 | 24 | done_testing; 25 | -------------------------------------------------------------------------------- /t/util.t: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | use Test::More; 5 | 6 | BEGIN { use_ok('ChronoBit::Util'); } 7 | 8 | my $test_msg1 = 'Lorem ipsum dolor sit amet'; 9 | my $msg1_hex = '4c6f72656d20697073756d20646f6c6f722073697420616d6574'; 10 | 11 | is(hex2bin($msg1_hex), $test_msg1); 12 | is(bin2hex($test_msg1), $msg1_hex); 13 | 14 | done_testing; 15 | -------------------------------------------------------------------------------- /t/var_len.t: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | 4 | use Test::More; 5 | 6 | use ChronoBit::Util; 7 | BEGIN { use_ok('ChronoBit::Bitcoin'); } 8 | 9 | is(bin2hex(var_int->build(3)), '03'); 10 | is(bin2hex(var_int->build(0xfc)), 'fc'); 11 | is(bin2hex(var_int->build(0xfd)), 'fdfd00'); 12 | is(bin2hex(var_int->build(0xfe)), 'fdfe00'); 13 | is(bin2hex(var_int->build(0xffff)), 'fdffff'); 14 | is(bin2hex(var_int->build(0x10000)), 'fe00000100'); 15 | is(bin2hex(var_int->build(0xffffffff)), 'feffffffff'); 16 | is(bin2hex(var_int->build(0xffffffff + 1)), 'ff0000000001000000'); 17 | 18 | is(var_int->parse(hex2bin('03')), 3); 19 | is(var_int->parse(hex2bin('fc')), 0xfc); 20 | is(var_int->parse(hex2bin('fdfd00')), 0xfd); 21 | is(var_int->parse(hex2bin('fdfe00')), 0xfe); 22 | is(var_int->parse(hex2bin('fdffff')), 0xffff); 23 | is(var_int->parse(hex2bin('fe00000100')), 0x10000); 24 | is(var_int->parse(hex2bin('feffffffff')), 0xffffffff); 25 | is(var_int->parse(hex2bin('ff0000000001000000')), 0xffffffff + 1); 26 | 27 | is(bin2hex(var_str->build('dupa jeza')), '0964757061206a657a61'); 28 | is(bin2hex(var_bytes->build('dupa jeza')), '0964757061206a657a61'); 29 | 30 | is(var_str->parse(hex2bin('0964757061206a657a61')), 'dupa jeza'); 31 | is(var_bytes->parse(hex2bin('0964757061206a657a61')), 'dupa jeza'); 32 | 33 | done_testing; 34 | 35 | -------------------------------------------------------------------------------- /traverse_shares.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | 3 | # $ ./traverse_shares.pl [] 4 | 5 | # goes backwards from a later share's hash down to an earlier 6 | # share's hash 7 | # 8 | # creates a proof from to . 9 | # 10 | # if is not given, defaults to current best share hash. 11 | # byte order doesn't matter, script will reverse as necessary 12 | 13 | use strict; 14 | use warnings; 15 | 16 | use YAML::Syck; 17 | use JSON::XS; 18 | use LWP::UserAgent; 19 | 20 | use ChronoBit::P2Pool; 21 | use ChronoBit::Proof; 22 | use ChronoBit::ProofStore; 23 | use ChronoBit::Util; 24 | 25 | $| = 1; 26 | my $cfg = LoadFile('chronobit.conf'); 27 | my $addr = $cfg->{p2pool}; 28 | my $ua = LWP::UserAgent->new; 29 | $ua->timeout(5); 30 | my $json = JSON::XS->new->allow_nonref; 31 | 32 | my $cnt = 0; 33 | sub get { 34 | my $what = shift; 35 | 36 | print "[$cnt] getting $what...\n"; 37 | my $res = $ua->get("$addr/$what"); 38 | if($res->is_success) { 39 | return $res->decoded_content; 40 | } else { 41 | die $res->status_line; 42 | } 43 | } 44 | 45 | die "need argument" unless $ARGV[0]; 46 | 47 | my $from; 48 | my $target; 49 | if($ARGV[1]) { 50 | $from = $ARGV[0]; 51 | # reverse if needed (can safely assume the share will have a bunch 52 | # of zeroes, as it needs to be at least difficulty 1) 53 | # XXX: will fail once in a blue moon if it also has zeroes on the other side 54 | if(substr($from, 0, 8) ne '00000000') { 55 | $from = bin2hex(scalar reverse hex2bin($from)); 56 | } 57 | $target = $ARGV[1]; 58 | } else { 59 | $from = $json->decode(get("web/best_share_hash")); 60 | $target = $ARGV[0]; 61 | } 62 | 63 | $target = hex2bin(lc $target); 64 | 65 | sub target { 66 | my $what = shift; 67 | 68 | return ($what eq $target) || ($what eq (scalar reverse $target)); 69 | } 70 | 71 | my $cur_hash = $from; 72 | my $proof; 73 | 74 | while(!target(hex2bin($cur_hash))) { 75 | my $share = share->parse(get("web/share_data/$cur_hash")); 76 | my $cur_proof = ChronoBit::Proof->new_from_share($share, 77 | scalar reverse hex2bin($cur_hash) 78 | ); 79 | 80 | if(defined $proof) { 81 | # printf "merging proof from %s to %s\n", bin2hex($cur_proof->from), 82 | # bin2hex($cur_proof->to); 83 | # printf " with from %s to %s\n", bin2hex($proof->from), 84 | # bin2hex($proof->to); 85 | $proof = ChronoBit::Proof->new_merged($cur_proof, $proof); 86 | } else { 87 | $proof = $cur_proof; 88 | } 89 | 90 | $cur_hash = bin2hex(scalar reverse $share->{contents}->{common}-> 91 | {share_info}->{share_data}->{previous_share_hash}); 92 | $cnt++; 93 | } 94 | 95 | print "Finished search, saving proof...\n"; 96 | 97 | my $ps = ChronoBit::ProofStore->new(outdir => $cfg->{proofs}); 98 | my $filename = $ps->save($proof); 99 | 100 | print "Saved proof to $filename\n"; 101 | -------------------------------------------------------------------------------- /verify_proof.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl 2 | 3 | use strict; 4 | use warnings; 5 | 6 | use IO::All; 7 | use Digest::SHA qw/sha256/; 8 | use Data::ParseBinary; 9 | 10 | use ChronoBit::Bitcoin; 11 | use ChronoBit::ProofFile; 12 | use ChronoBit::Proof; 13 | use ChronoBit::Util; 14 | 15 | my $data = io('-')->slurp; 16 | my $proof_file = ChronoBit::ProofFile->struct->parse($data); 17 | 18 | # XXX: haxx 19 | my $proof = ChronoBit::Proof->new_from_binary( 20 | ChronoBit::Proof->struct->build($proof_file->{proof}) 21 | ); 22 | 23 | print $proof->explain if $ARGV[0]; 24 | printf "proof from %s\n to %s\n", bin2hex($proof->from), 25 | bin2hex($proof->to); 26 | print 'data: <' . $proof_file->{data} . ">\n"; 27 | print '(data ' . ((sha256($proof_file->{data}) eq $proof->from) ? 'does' : 28 | 'DOES NOT') . " map to proof's start)\n"; 29 | print '(data+timestamp ' . ((sha256($proof_file->{data} . 30 | var_int->build($proof_file->{timestamp}) . 31 | ULInt32->build($proof_file->{timestamp_usec} 32 | )) eq $proof->from) ? 'does' : 'DOES NOT') . " map to proof's start)\n"; 33 | printf "claims to be made on %s %06d usec GMT\n", 34 | scalar(gmtime($proof_file->{timestamp})), 35 | $proof_file->{timestamp_usec}; 36 | 37 | my $res = $proof->verify; 38 | print $res ? "proof ok\n" : "PROOF INVALID\n"; 39 | 40 | exit $res; 41 | 42 | --------------------------------------------------------------------------------