Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notes for Powdr patched crypto-bigint #3

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Notes for Powdr patched crypto-bigint #3

wants to merge 1 commit into from

Conversation

qwang98
Copy link
Collaborator

@qwang98 qwang98 commented Jan 22, 2025

This is NOT a PR but just to show the diff and store the following notes on how this branch is created an tested.

Background
This is a fork of the latest main of Rust-Crypto/crypto-bigint as of 1/15/2025. Risc0 created another fork of a much earlier (and outdated) main of Rust-Crypto/crypto-bigint that we referenced.

Why the patch
The gist of the patch is to NOT use Montgomery form representations of bigints. Montgomery form is commonly used to speed up modular multiplication and inversion algorithms. However, PowdrVM acceleration computes bigint modular multiplication via lower level assembly and no longer requires using Montgomery forms. However, crates that depend on crypto-bigint still indirectly uses Montgomery form. Our patch doesn't remove these uses but instead removes the conversion from standard form to Montgomery form and vice versa.

Extent of the patch
Functions that need Powdr patch largely mirror what Risc0 patched an earlier version of crypto-bigint: risc0/RustCrypto-crypto-bigint@v0.5.5...v0.5.5-risczero.0. However, our patch and Risc0 patch are not fully comparable, because Rust-Crypto/crypto-bigint has changed a lot since Risc0 last patched it. We've incorporated these changes in our patch.

RustCrypto/crypto-bigint changes since Risc0 patch
Most changes involve a complete restructure of the files and types. Montgomery form types became ConstMontyForm, BoxedMontyForm, and MontyForm. These types wrap Uint and BoxedUint types, which are arbitrary length integers split to 32-bit limbs. The API/algorithms for computing inversions and multiplications have also been updated. Therefore, patching Powdr to the updated crypto-bigint requires understanding these changes.

Testing coverage
All powdr patch tests are under powdr_test folder, which is a separate Rust crate modified from the PowdrVM boilerplate code. main.rs from the guest program contains all unit tests. cargo run -r on the host crate should run the test. Unit tests cover all Powdr patched functions except Serde trait implementations. Test vectors are mostly manually generated, with a few directly taken from original tests from RustCrypto/crypto-bigint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant