Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,249
    • Issues 5,249
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 581
    • Merge requests 581
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #18515
Closed
Open
Issue created Jul 30, 2020 by ocheron@trac-ocheron

Incorrect result with bigNatPowMod

Summary

When trying to use bigNatPowMod to replace powModInteger I notice the function sometimes returns incorrect result.

In the GMP backend, bignat_powmod ignores the result of integer_gmp_powm#, so does not set the size of the output, possibly leaving uninitialized limbs in the word array.

Steps to reproduce

The following program:

{-# LANGUAGE MagicHash #-}

import GHC.Num.BigNat
import GHC.Num.Integer

main :: IO ()
main =
    let b = integerToBigNatClamp# 251943445928310882947152017889649234
        e = integerToBigNatClamp# 503886891856621765894304035779298468
        m = integerToBigNatClamp# 503886891856621765894304035779298469
        r = integerFromBigNat# (bigNatPowMod b e m)
     in print r

when executed with runghc displays a non-constant result like 85639447066539974357520744449.

Expected behavior

Result displayed should be always 1.

Environment

  • GHC version used: branch master, commit e1dc3d7b89ea79aea158ee487234d3730e857f04.

Optional:

  • Operating System: macOS
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking