{"id":21352100,"url":"https://github.com/avras/btc-nova-lc","last_synced_at":"2025-04-15T06:24:33.620Z","repository":{"id":252777589,"uuid":"832661708","full_name":"avras/btc-nova-lc","owner":"avras","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-12T10:36:33.000Z","size":10145,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-22T03:12:30.775Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/avras.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-23T13:21:33.000Z","updated_at":"2024-10-25T03:59:51.000Z","dependencies_parsed_at":"2024-08-12T13:08:16.501Z","dependency_job_id":"8f7afbf4-7727-4fd8-a0ba-e267d673c66e","html_url":"https://github.com/avras/btc-nova-lc","commit_stats":null,"previous_names":["avras/btc-nova-lc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avras%2Fbtc-nova-lc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avras%2Fbtc-nova-lc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avras%2Fbtc-nova-lc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avras%2Fbtc-nova-lc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avras","download_url":"https://codeload.github.com/avras/btc-nova-lc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235152336,"owners_count":18944168,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T03:12:34.945Z","updated_at":"2025-01-22T17:14:46.064Z","avatar_url":"https://github.com/avras.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bitcoin Header Validation using Nova\n \nThis repo contains circuits for validating Bitcoin headers using [Nova](https://github.com/microsoft/Nova). At each step, it allows validating multiple headers. For each header, the following checks are performed:\n\n- The current header contains the hash of the previous block header.\n- The current header hash falls below the PoW target threshold. The 32-bit `nBits` field is converted to a target with 224 significant bits before this check.\n- The `nBits` field has been updated correctly if the block height is a multiple of 2016.\n- The current header timestamp is greater than or equal to the median of the previous 11 block timestamps.\n\nIn addition to the above checks, the circuit also accumulates the chainwork of each block.\n\n**Acknowledgement**: This implementation is heavily inspired by the techniques used by the [ZeroSync](https://github.com/ZeroSync/ZeroSync) project to validate Bitcoin headers.\n\n\u003e [!WARNING]\n\u003e This code has not been audited. Use with care.\n\n## Running the examples\n\nThere are two examples which demonstrate the header validation.\n\n- `validate_btc_headers` validates one header per Nova step. It takes a file containing the headers as the first argument and the number of headers to validate (starting from the genesis block) as the second argument. It can be run as follows.\n    ```\n    cargo run -r --example validate_btc_header_batch scripts/headers_100000.txt 10\n    ```\n- `validate_btc_header_batch` validates multiple headers per Nova step. It takes a file containing the headers as the first argument, the number of headers to validate per step as the second argument, and the number of steps as the third argument.\n    ```\n    cargo run -r --example validate_btc_header_batch scripts/headers_100000.txt 2 5\n    ```\n\n\n## Generating logs\nThis repository has three shell scripts to measure peak memory usage and to log the output of the two examples to text files. Build the examples using `cargo build -r --examples` before running these scripts.  The scripts have been tested only on Debian/Ubuntu. The logs will be creates in the `logs` directory.\n\n- `genlog.sh` runs the `validate_btc_headers` example. It takes the number of headers to validate as an argument. This number can be at most 100k since the file containing the headers in the `scripts` directory only has 100k headers. For example, to validate the first 10 headers you can run the following command.\n  ```bash\n  ./genlog.sh 10\n  ```\n  The above command will create files `logs/output_10.txt` and `logs/time_output_10.txt`.\n- `genlog_batch.sh` runs the `validate_btc_header_batch` example. It takes the number of headers to validate per step as the first argument and the number of steps as the second argument. The product of these arguments can be at most 100k. For example, to validate the first 10 headers in 5 steps with 2 headers validated per step you can run the following command.\n\n  ```bash\n  ./genlog_batch.sh 2 5\n  ```\n  The above command will create files `logs/output_2_5.txt` and `logs/time_output_2_5.txt`.\n- `genlog_1024.sh` runs the `validate_btc_header_batch` example 8 times. In each iteration, it validates 1024 headers but varies the number of headers validated per step in the set `{1,2,4,8,16,32,64,128}`. The goal is to study the change in proving time, memory usage, and public parameters size as the number of headers per step increases. The script does not take any parameters and can be run as follows.\n  ```bash\n  ./genlog_1024.sh\n  ```\n\n  \u003e [!NOTE]\n  \u003e This repository has a branch called `arecibo` which uses Argument Computer's [fork](https://github.com/argumentcomputer/arecibo) of Nova to perform the Bitcoin header validation. This fork has an implementation of [CycleFold](https://eprint.iacr.org/2023/1192). The shell scripts  files in the `arecibo` branch will create files in the `logs` directory with a prefix `arecibo_` in their filenames.\n\n## Existing benchmarks\nThe existing files in the `logs` directory were generated on a Dell Precision 3260 desktop with a [13th Gen Intel i7-13700 CPU](https://www.intel.com/content/www/us/en/products/sku/230490/intel-core-i713700-processor-30m-cache-up-to-5-20-ghz/specifications.html) and 32 GB of RAM. The CPU has 16 performance cores and 8 efficient cores (24 threads).\n\n### Validating 100K block headers\nTo validate 100,000 headers, the results when the number of headers per step is 1, 10, and 100 are given below. The following results are for version 0.37.0 of the [Nova](https://github.com/microsoft/Nova) library.\n\n| Number of\u003cbr\u003eheaders\u003cbr\u003eper step | Number\u003cbr\u003eof\u003cbr\u003esteps | Total\u003cbr\u003eproving\u003cbr\u003etime | Compressed\u003cbr\u003eSNARK\u003cbr\u003eproving\u003cbr\u003etime | Recursive\u003cbr\u003eSNARK\u003cbr\u003eproving\u003cbr\u003etime | Compressed\u003cbr\u003eSNARK\u003cbr\u003everify\u003cbr\u003etime | Proof\u003cbr\u003esize \u003cbr\u003e(bytes) | Peak\u003cbr\u003ememory\u003cbr\u003eusage | Public\u003cbr\u003eparameters\u003cbr\u003esize | Public\u003cbr\u003eparameters\u003cbr\u003egeneration\u003cbr\u003etime |\n|---------------------------------:|----------------------:|--------------------------|---------------------------------------:|---------------------------------------|--------------------------------------:|---------------------------|------------------------:|-----------------------------:|-------------------------------------------:|\n|                                1 |                100000 | 4.18 hours               |                                   1.0s | 4.18 hours                            |                                29.1ms | 12608                     |                0.50 GiB |                    40.89 MiB |                                       2.3s |\n|                               10 |                 10000 | 1.87 hours               |                                   4.1s | 1.87 hours                            |                                52.9ms | 13736                     |                2.64 GiB |                   254.66 MiB |                                      14.2s |\n|                              100 |                  1000 | 1.46 hours               |                                  36.3s | 1.46 hours                            |                               532.7ms | 15240                     |               19.23 GiB |                     2.53 GiB |                                     210.5s |\n\nThe following results are for commit [3ff41aca](https://github.com/argumentcomputer/arecibo/tree/3ff41acaaddf82abe00926ae353c26ad84d726c4) (July 1, 2024) of the [arecibo](https://github.com/argumentcomputer/arecibo) library. The proving times and peak memory usage are smaller when the number of headers per step is 1 and 10. When the number of headers per step is 100, the Nova library has smaller values. The public parameter sizes are smaller for the Nova library in all three cases.\n\n| Number of\u003cbr\u003eheaders\u003cbr\u003eper step | Number\u003cbr\u003eof\u003cbr\u003esteps | Total\u003cbr\u003eproving\u003cbr\u003etime | Compressed\u003cbr\u003eSNARK\u003cbr\u003eproving\u003cbr\u003etime | Recursive\u003cbr\u003eSNARK\u003cbr\u003eproving\u003cbr\u003etime | Compressed\u003cbr\u003eSNARK\u003cbr\u003everify\u003cbr\u003etime | Proof\u003cbr\u003esize \u003cbr\u003e(bytes) | Peak\u003cbr\u003ememory\u003cbr\u003eusage | Public\u003cbr\u003eparameters\u003cbr\u003esize | Public\u003cbr\u003eparameters\u003cbr\u003egeneration\u003cbr\u003etime |\n|---------------------------------:|----------------------:|--------------------------|---------------------------------------:|---------------------------------------|--------------------------------------:|---------------------------|------------------------:|-----------------------------:|-------------------------------------------:|\n| 1                                | 100000                | 3.19 hours               | 0.8s                                   | 3.19 hours                            | 21.2ms                                | 12672                     | 0.44 GiB                | 48.89 MiB                    | 1.3s                                       |\n| 10                               | 10000                 | 1.77 hours               | 3.4s                                   | 1.77 hours                            | 52.7ms                                | 13800                     | 2.41 GiB                | 318.66 MiB                   | 5.1s                                       |\n| 100                              | 1000                  | 1.78 hours               | 31.5s                                  | 1.78 hours                            | 566.1ms                               | 15304                     | 24.78 GiB               | 3.53 GiB                     | 55.2s                                      |\n\n### Validating 1024 block headers\nTo validate 1024 headers, the results when the number of headers per step is in the set {1,2,4,8,16,32,64,128} are given below. The following results are for version 0.37.0 of the [Nova](https://github.com/microsoft/Nova) library.\n\n| Number of\u003cbr\u003eheaders\u003cbr\u003eper step | Number\u003cbr\u003eof\u003cbr\u003esteps | Total\u003cbr\u003eproving\u003cbr\u003etime | Compressed\u003cbr\u003eSNARK\u003cbr\u003eproving\u003cbr\u003etime | Recursive\u003cbr\u003eSNARK\u003cbr\u003eproving\u003cbr\u003etime | Compressed\u003cbr\u003eSNARK\u003cbr\u003everify\u003cbr\u003etime | Proof\u003cbr\u003esize \u003cbr\u003e(bytes) | Peak\u003cbr\u003ememory\u003cbr\u003eusage | Public\u003cbr\u003eparameters\u003cbr\u003esize | Public\u003cbr\u003eparameters\u003cbr\u003egeneration\u003cbr\u003etime |\n|---------------------------------:|----------------------:|-------------------------:|---------------------------------------:|--------------------------------------:|--------------------------------------:|---------------------------|------------------------:|-----------------------------:|-------------------------------------------:|\n| 1                                | 1024                  | 153.1s                   | 0.9s                                   | 152.1s                                | 26.1ms                                | 12608                     | 0.42 GiB                | 40.89 MiB                    | 2.3s                                       |\n| 2                                | 512                   | 110.8s                   | 1.3s                                   | 109.4s                                | 30.6ms                                | 12984                     | 0.66 GiB                | 65.53 MiB                    | 4.0s                                       |\n| 4                                | 256                   | 87.1s                    | 2.1s                                   | 84.8s                                 | 37.4ms                                | 13360                     | 1.23 GiB                | 114.81 MiB                   | 7.4s                                       |\n| 8                                | 128                   | 74.9s                    | 3.7s                                   | 71.0s                                 | 45.7ms                                | 13736                     | 2.12 GiB                | 213.38 MiB                   | 14.0s                                      |\n| 16                               | 64                    | 69.0s                    | 6.5s                                   | 62.2s                                 | 75.3ms                                | 14112                     | 2.89 GiB                | 410.50 MiB                   | 27.3s                                      |\n| 32                               | 32                    | 67.5s                    | 11.5s                                  | 55.4s                                 | 142.7ms                               | 14488                     | 5.67 GiB                | 804.76 MiB                   | 54.6s                                      |\n| 64                               | 16                    | 72.7s                    | 22.2s                                  | 49.5s                                 | 292.6ms                               | 14864                     | 11.16 GiB               | 1.56 GiB                     | 105.9s                                     |\n| 128                              | 8                     | 91.5s                    | 44.7s                                  | 44.7s                                 | 573.8ms                               | 15240                     | 22.22 GiB               | 3.10 GiB                     | 215.9s                                     |\n\n\nThe following results are for commit [3ff41aca](https://github.com/argumentcomputer/arecibo/tree/3ff41acaaddf82abe00926ae353c26ad84d726c4) (July 1, 2024) of the [arecibo](https://github.com/argumentcomputer/arecibo) library. The proving times and peak memory usage are smaller when the number of headers per step is 1, 2, 4, or 8. When the number of headers per step is 16, 32, 64, or 128, the Nova library has smaller values. The public parameter sizes are smaller for the Nova library in all eight cases.\n\n| Number of\u003cbr\u003eheaders\u003cbr\u003eper step | Number\u003cbr\u003eof\u003cbr\u003esteps | Total\u003cbr\u003eproving\u003cbr\u003etime | Compressed\u003cbr\u003eSNARK\u003cbr\u003eproving\u003cbr\u003etime | Recursive\u003cbr\u003eSNARK\u003cbr\u003eproving\u003cbr\u003etime | Compressed\u003cbr\u003eSNARK\u003cbr\u003everify\u003cbr\u003etime | Proof\u003cbr\u003esize \u003cbr\u003e(bytes) | Peak\u003cbr\u003ememory\u003cbr\u003eusage | Public\u003cbr\u003eparameters\u003cbr\u003esize | Public\u003cbr\u003eparameters\u003cbr\u003egeneration\u003cbr\u003etime |\n|---------------------------------:|----------------------:|-------------------------:|---------------------------------------:|--------------------------------------:|--------------------------------------:|---------------------------|------------------------:|-----------------------------:|-------------------------------------------:|\n| 1                                | 1024                  |                   116.0s |                                   0.8s |                                114.9s |                                21.4ms | 12672                     |                0.37 GiB |                    48.89 MiB |                                       1.3s |\n| 2                                | 512                   |                    87.3s |                                   1.1s |                                 85.7s |                                23.3ms | 13048                     |                0.63 GiB |                    81.53 MiB |                                       1.8s |\n| 4                                | 256                   |                    74.2s |                                   1.7s |                                 71.7s |                                28.1ms | 13424                     |                1.06 GiB |                   146.81 MiB |                                       2.8s |\n| 8                                | 128                   |                    70.0s |                                   2.9s |                                 65.6s |                                47.5ms | 13800                     |                2.03 GiB |                   277.38 MiB |                                       4.8s |\n| 16                               | 64                    |                    72.6s |                                   5.2s |                                 64.5s |                                88.6ms | 14176                     |                3.80 GiB |                   538.50 MiB |                                       8.3s |\n| 32                               | 32                    |                    73.9s |                                   9.9s |                                 58.2s |                               151.9ms | 14552                     |                7.46 GiB |                     1.04 GiB |                                      15.3s |\n| 64                               | 16                    |                    81.0s |                                  19.2s |                                 50.5s |                               306.4ms | 14928                     |               14.33 GiB |                     2.06 GiB |                                      30.1s |\n| 128                              | 8                     |                   106.8s |                                  37.6s |                                 46.7s |                               631.8ms | 15304                     |               27.62 GiB |                     4.10 GiB |                                      54.6s |\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0\n   ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license\n   ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favras%2Fbtc-nova-lc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favras%2Fbtc-nova-lc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favras%2Fbtc-nova-lc/lists"}