{"id":20109974,"url":"https://github.com/distributed-lab/bitcoin-window-mul","last_synced_at":"2025-05-06T10:31:39.656Z","repository":{"id":251424826,"uuid":"837102425","full_name":"distributed-lab/bitcoin-window-mul","owner":"distributed-lab","description":"Windowed big integer multiplication implementation on Bitcoin Script","archived":false,"fork":false,"pushed_at":"2024-09-16T11:52:11.000Z","size":1556,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-17T11:05:09.139Z","etag":null,"topics":["bigint","bitcoin-script","bitvm","rust"],"latest_commit_sha":null,"homepage":"https://eprint.iacr.org/2024/1236","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/distributed-lab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-02T08:08:38.000Z","updated_at":"2024-09-16T11:52:15.000Z","dependencies_parsed_at":"2024-10-25T21:08:23.850Z","dependency_job_id":"2dbd8fcf-27b7-42fd-8fa6-0b78f6005987","html_url":"https://github.com/distributed-lab/bitcoin-window-mul","commit_stats":null,"previous_names":["distributed-lab/bitcoin-window-mul"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/distributed-lab%2Fbitcoin-window-mul","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/distributed-lab%2Fbitcoin-window-mul/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/distributed-lab%2Fbitcoin-window-mul/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/distributed-lab%2Fbitcoin-window-mul/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/distributed-lab","download_url":"https://codeload.github.com/distributed-lab/bitcoin-window-mul/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224499924,"owners_count":17321605,"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":["bigint","bitcoin-script","bitvm","rust"],"created_at":"2024-11-13T18:09:57.714Z","updated_at":"2024-11-13T18:09:58.221Z","avatar_url":"https://github.com/distributed-lab.png","language":"Rust","readme":"# :heavy_multiplication_x: Fast Windowed Multiplication implementation in Bitcoin\n\nThis repository contains the implementation of the Fast Multiplication algorithm in _Bitcoin_ for two 254-bit numbers using $w$-window multiplication.\n\n## :interrobang: How to test?\n\nYou can run all the tests by simply writing:\n\n```bash\ncargo test\n```\n\nHowever, more concretely, to verify the performance and the number of operations, you can run the following command. We also\nspecify where you can find the corresponding unit test in the project.\n\n| Command | Description | Location |\n| --- | --- | --- |\n| `cargo test -- --nocapture test_254_bit_windowed_widening_optimized_mul` | Test our widening multiplication algorithm | [`test.rs`](src/bigint/arithmetics/test.rs#L641) |\n| `cargo test -- --nocapture test_254_bit_narrow_mul_w_width` | Test our narrow multiplication algorithm | [`test.rs`](src/bigint/arithmetics/test.rs#L489) |\n| `cargo test -- --nocapture test_254_bit_windowed_lazy_widening_mul` | Test _BitVM_'s widening multiplication algorithm (extended by us) | [`test.rs`](src/bigint/arithmetics/test.rs#L519) |\n| `cargo test -- --nocapture test_254_bit_naive_widening_mul` | Test _BitVM_'s narrow multiplication algorithm (a bit optimized by us) | [`test.rs`](src/bigint/arithmetics/test.rs#L459) |\n| `cargo test -- --nocapture test_255_bit_cmpeq_widening_mul` | Test [`cmpeq`](https://bitcointalk.org/index.php?topic=5477449.0)'s widening multiplication algorithm | [`test.rs`](src/bigint/cmpeq/test.rs#L56) |\n| `cargo test -- --nocapture --ignored debug_mul_performance_comparison` | Compare the performance of several multiplication algorithms used | [`test.rs`](src/bigint/performance.rs#L14) |\n\n## :zap: A few words about optimization\n\nThe two primary optimizations used are:\n\n- Using the windowed method with `w=4` for multiplication.\n- Improving the doubling step.\n\nThe windowed method is a well-known optimization for multiplication. It reduces the number of additions with an additional\ncost to generate the lookup table. Namely, we use the base `1\u003c\u003cw` for the windowed method and based on the decomposition\ncoefficient `d` at each step, we add the corresponding value from the lookup table. The lookup table is generated by\nprecomputing the values of `d*z` for all `d` in the range `{0, 1, ..., 1\u003c\u003cw-1}` and given integer `z`. This way, we only have roughly\n`b/(1\u003c\u003cw)` additions, where `b` is the number of bits in the number, while the number of doubling steps remains the same.\n\nThe doubling step was easy to optimize, though: we noticed that the original implementation was not optimal since\nit implemented `double(a)` as `add(a, a)`. However, we can do better by not zipping the same number with itself, but\nsimply duplicating the limb at each step and carrying the overflow. This way, we can significantly reduce the number of operations\nsince the doubling step is used 254 times in the multiplication algorithm.\n\n## How to cite?\n\n```bibtex\n@misc{cryptoeprint:2024/1236,\n    author = {Dmytro Zakharov and Oleksandr Kurbatov and Manish Bista and Belove Bist},\n    title = {Optimizing Big Integer Multiplication on Bitcoin: Introducing w-windowed Approach},\n    howpublished = {Cryptology ePrint Archive, Paper 2024/1236},\n    year = {2024},\n    note = {\\url{https://eprint.iacr.org/2024/1236}},\n    url = {https://eprint.iacr.org/2024/1236}\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdistributed-lab%2Fbitcoin-window-mul","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdistributed-lab%2Fbitcoin-window-mul","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdistributed-lab%2Fbitcoin-window-mul/lists"}