Notes for Powdr patched crypto-bigint #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
, andMontyForm
. These types wrapUint
andBoxedUint
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 fromRustCrypto/crypto-bigint
.