Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,392
    • Issues 4,392
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 374
    • Merge Requests 374
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #18515

Closed
Open
Opened 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
Assignee
Assign to
9.0.1
Milestone
9.0.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#18515