bitcoin-window-mul

Windowed big integer multiplication implementation on Bitcoin Script

https://github.com/distributed-lab/bitcoin-window-mul

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.8%) to scientific vocabulary

Keywords

bigint bitcoin-script bitvm rust
Last synced: 9 months ago · JSON representation ·

Repository

Windowed big integer multiplication implementation on Bitcoin Script

Basic Info
Statistics
  • Stars: 12
  • Watchers: 3
  • Forks: 2
  • Open Issues: 0
  • Releases: 1
Topics
bigint bitcoin-script bitvm rust
Created almost 2 years ago · Last pushed over 1 year ago
Metadata Files
Readme Citation

README.md

:heavymultiplicationx: Fast Windowed Multiplication implementation in Bitcoin

This repository contains the implementation of the Fast Multiplication algorithm in Bitcoin for two 254-bit numbers using $w$-window multiplication.

:interrobang: How to test?

You can run all the tests by simply writing:

bash cargo test

However, more concretely, to verify the performance and the number of operations, you can run the following command. We also specify where you can find the corresponding unit test in the project.

| Command | Description | Location | | --- | --- | --- | | cargo test -- --nocapture test_254_bit_windowed_widening_optimized_mul | Test our widening multiplication algorithm | test.rs | | cargo test -- --nocapture test_254_bit_narrow_mul_w_width | Test our narrow multiplication algorithm | test.rs | | cargo test -- --nocapture test_254_bit_windowed_lazy_widening_mul | Test BitVM's widening multiplication algorithm (extended by us) | test.rs | | cargo test -- --nocapture test_254_bit_naive_widening_mul | Test BitVM's narrow multiplication algorithm (a bit optimized by us) | test.rs | | cargo test -- --nocapture test_255_bit_cmpeq_widening_mul | Test cmpeq's widening multiplication algorithm | test.rs | | cargo test -- --nocapture --ignored debug_mul_performance_comparison | Compare the performance of several multiplication algorithms used | test.rs |

:zap: A few words about optimization

The two primary optimizations used are:

  • Using the windowed method with w=4 for multiplication.
  • Improving the doubling step.

The windowed method is a well-known optimization for multiplication. It reduces the number of additions with an additional cost to generate the lookup table. Namely, we use the base 1<<w for the windowed method and based on the decomposition coefficient d at each step, we add the corresponding value from the lookup table. The lookup table is generated by precomputing the values of d*z for all d in the range {0, 1, ..., 1<<w-1} and given integer z. This way, we only have roughly b/(1<<w) additions, where b is the number of bits in the number, while the number of doubling steps remains the same.

The doubling step was easy to optimize, though: we noticed that the original implementation was not optimal since it implemented double(a) as add(a, a). However, we can do better by not zipping the same number with itself, but simply duplicating the limb at each step and carrying the overflow. This way, we can significantly reduce the number of operations since the doubling step is used 254 times in the multiplication algorithm.

How to cite?

bibtex @misc{cryptoeprint:2024/1236, author = {Dmytro Zakharov and Oleksandr Kurbatov and Manish Bista and Belove Bist}, title = {Optimizing Big Integer Multiplication on Bitcoin: Introducing w-windowed Approach}, howpublished = {Cryptology ePrint Archive, Paper 2024/1236}, year = {2024}, note = {\url{https://eprint.iacr.org/2024/1236}}, url = {https://eprint.iacr.org/2024/1236} }

Owner

  • Name: Distributed Lab
  • Login: distributed-lab
  • Kind: organization
  • Email: contact@distributedlab.com
  • Location: Ukraine

Connecting business to Financial Internet

Citation (CITATION.cff)

cff-version: 1.2.0
title: >-
  Optimizing Big Integer Multiplication on Bitcoin:
  Introducing w-windowed Approach
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: misc
authors:
  - given-names: Dmytro
    family-names: Zakharov
    email: dmytro.zakharov@distributedlab.com
    affiliation: Distributed Lab
    orcid: 'https://orcid.org/0000-0001-9519-2444'
  - given-names: Oleksandr
    family-names: Kurbatov
    email: ok@distributedlab.com
    affiliation: Distributed Lab
    orcid: 'https://orcid.org/0000-0002-8237-4377'
  - given-names: Manish
    family-names: Bista
    affiliation: Alpen Labs
    email: manish@alpenlabs.io
  - given-names: Belove
    family-names: Bist
    email: belove@alpenlabs.io
    affiliation: Alpen Labs
identifiers:
  - type: url
    value: 'https://eprint.iacr.org/2024/1236'
    description: 'Cryptology ePrint Archive, Paper 2024/1236'
repository-code: 'https://github.com/distributed-lab/bitcoin-window-mul'
abstract: >-
  A crucial component of any zero-knowledge system is
  operations with finite fields. This, in turn, leads to the
  implementation of the fundamental operation: multiplying
  two big integers. In the realm of Bitcoin, this problem
  gets revisited, as Bitcoin utilizes its own stack-based
  and not Turing-complete scripting system called Bitcoin
  Script. Inspired by Elliptic Curve scalar multiplication,
  this paper introduces the w-windowed method for multiplying
  two numbers. We outperform state-of-the-art approaches,
  including BitVMs implementation. Finally, we also show
  how the windowed method can lead to optimizations not only
  in big integer arithmetic solely but in more general
  arithmetic problems.
keywords:
  - Bitcoin
  - Bitcoin Script
  - Fast Multiplication
  - Elliptic Curves
  - Scalar Multiplication
  - BitVM
license: CC-BY-4.0

GitHub Events

Total
  • Watch event: 2
  • Delete event: 1
  • Issue comment event: 3
  • Push event: 2
  • Pull request review event: 1
  • Pull request event: 4
  • Fork event: 1
  • Create event: 1
Last Year
  • Watch event: 2
  • Delete event: 1
  • Issue comment event: 3
  • Push event: 2
  • Pull request review event: 1
  • Pull request event: 4
  • Fork event: 1
  • Create event: 1

Issues and Pull Requests

Last synced: over 1 year ago

All Time
  • Total issues: 0
  • Total pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: 8 minutes
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: 8 minutes
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • ZamDimon (2)
  • Velnbur (1)
Top Labels
Issue Labels
Pull Request Labels
enhancement (3)

Dependencies

Cargo.lock cargo
  • 246 dependencies
Cargo.toml cargo
  • ark-std 0.4.0 development
  • konst 0.3.9 development
  • num-bigint 0.4.4 development
  • rand 0.8.5 development
  • rand_chacha 0.3.1 development
  • ark-bn254 0.4.0
  • ark-ec 0.4.0
  • ark-ff 0.4.0
  • hex 0.4.3
  • lazy_static 1.4.0
  • num-bigint 0.4.4
  • num-traits 0.2.18
  • paste 1.0
  • prettytable-rs 0.10.0
  • seq-macro 0.3.5
  • serde 1.0.197
  • serde_json 1.0.116
  • sha2 0.10.8
  • strum 0.26
  • strum_macros 0.26
  • tokio 1.37.0
.github/workflows/rust.yaml actions
  • Swatinem/rust-cache v2 composite
  • actions/checkout v4 composite
  • dtolnay/rust-toolchain stable composite
  • taiki-e/install-action v2 composite