fix(emulated): pad a constant custom modulus to the full number of limbs - #1854
Open
FlashWayne wants to merge 1 commit into
Open
FlashWayne wants to merge 1 commit into
FlashWayne wants to merge 1 commit into
Conversation
The variable-modulus methods document that the modulus may be a constant, but NewElement stores a constant on the minimal number of limbs while the hints (mulHint, computeSubPaddingHint) read NbLimbs modulus limbs from their inputs. With a small constant modulus they read the wrong inputs: ModMul fails its check and ModAdd/ModExp/ModAssertIsEqual fail with "input length mismatch". Pad the modulus with zero limbs in checkModulus.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
ModMul,ModAdd,ModExpandModAssertIsEqualsay the modulus can be a witness or a constant, but a small constant modulus doesn't work:Before:
After: all four work with a constant modulus (test engine, r1cs, scs).
NewElementstores a constant on the minimal number of limbs (1 limb for 7), whilecallMulHint/mulHintandcomputeSubPaddingHintalways readNbLimbs()modulus limbs from their inputs, so they either pick up the wrong inputs or get the wrong input count.checkModulusnow returns the modulus padded with zero limbs up toNbLimbs(), and the four methods use that. A witness modulus already has all its limbs and is returned unchanged.Added
TestConstantModulus(Secp256k1Fp and Mod1e512, ModMulCanonical / ModAdd / ModAssertIsEqual / ModExp with a 20-bit constant modulus). It fails on master.std/math/emulated, the MODEXP precompile tests andinternal/stats(no change) pass.