Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions std/math/emulated/field_mul.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,12 @@ func (f *Field[T]) callMulHint(a, b *Element[T], isMulMod bool, customMod *Eleme
if customMod != nil {
modulusLimbs = customMod.Limbs
}
hintInputs := make([]frontend.Variable, 0, 4+len(modulusLimbs)+len(a.Limbs)+len(b.Limbs))
hintInputs = append(hintInputs, nbBits, nbLimbs, len(a.Limbs), nbQuoLimbs)
isCheckZero := 0
if !isMulMod {
isCheckZero = 1
}
hintInputs := make([]frontend.Variable, 0, 5+len(modulusLimbs)+len(a.Limbs)+len(b.Limbs))
hintInputs = append(hintInputs, nbBits, nbLimbs, len(a.Limbs), nbQuoLimbs, isCheckZero)
hintInputs = append(hintInputs, modulusLimbs...)
hintInputs = append(hintInputs, a.Limbs...)
hintInputs = append(hintInputs, b.Limbs...)
Expand Down Expand Up @@ -566,8 +570,9 @@ func mulHint(field *big.Int, inputs, outputs []*big.Int) error {
nbLimbs := int(inputs[1].Int64())
nbALen := int(inputs[2].Int64())
nbQuoLen := int(inputs[3].Int64())
nbBLen := len(inputs) - 4 - nbLimbs - nbALen
ptr := 4
isCheckZero := inputs[4].Int64() == 1
nbBLen := len(inputs) - 5 - nbLimbs - nbALen
ptr := 5
plimbs := inputs[ptr : ptr+nbLimbs]
ptr += nbLimbs
alimbs := inputs[ptr : ptr+nbALen]
Expand Down Expand Up @@ -611,6 +616,10 @@ func mulHint(field *big.Int, inputs, outputs []*big.Int) error {
if p.Sign() != 0 {
quo.QuoRem(ab, p, rem)
}
if isCheckZero && rem.Sign() != 0 {
// we expect the remainder to be zero
return fmt.Errorf("unexpected non-zero remainder for checkZero")
}
if err := limbs.Decompose(quo, uint(nbBits), quoLimbs); err != nil {
return fmt.Errorf("decompose quo: %w", err)
}
Expand Down