Skip to content

Commit a4c776d

Browse files
authored
Tests for expModInteger with modulus 1 (#6927)
* Tests for expModInteger with modulus zero * Extend 8.10 sub for modulus 1
1 parent d327541 commit a4c776d

File tree

2 files changed

+19
-10
lines changed
  • plutus-core

2 files changed

+19
-10
lines changed

plutus-core/plutus-core/src/PlutusCore/Crypto/ExpMod.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ expMod b e m =
2424
-- FIXME: fugly stub implementation to make the various test-suites/CI pass for GHC8.10.
2525
-- This means that we cannot provide random testing for expMod at the moment.
2626
expMod _ _ 0 = fail "Cannot divide by zero"
27+
expMod _ _ 1 = pure 0
2728
expMod 500 0 500 = pure 1
2829
expMod 500 5 500 = pure 0
2930
expMod 1 (-3) 4 = pure 1

plutus-core/untyped-plutus-core/test/Evaluation/Builtins/Definition.hs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -638,20 +638,28 @@ test_Integer = testNestedM "Integer" $ do
638638

639639
test_ExpModInteger :: TestNested
640640
test_ExpModInteger = testNestedM "ExpMod" $ do
641-
evals @Integer 1 b [] [cons @Integer 500, cons @Integer 0, cons @Integer 500] -- base:X, exp: zero, mod: X(strictpos)
642-
evals @Integer 0 b [] [cons @Integer 500, cons @Integer 5, cons @Integer 500] -- base:X, exp: strictpos, mod: X(strictpos)
643-
evals @Integer 1 b [] [one , cons @Integer (-3), cons @Integer 4] -- base:1, exp: * , mod: strictpos
644-
evals @Integer 2 b [] [cons @Integer 2, cons @Integer (-3), cons @Integer 3] -- base:*, exp: neg, mod: prime
641+
evals @Integer 1 b [] [int 500, zero, int 500] -- base:X, exp: zero, mod: X(strictpos)
642+
evals @Integer 0 b [] [int 500, int 5, int 500] -- base:X, exp: strictpos, mod: X(strictpos)
643+
evals @Integer 1 b [] [one , int (-3), int 4] -- base:1, exp: * , mod: strictpos
644+
evals @Integer 2 b [] [int 2, int (-3), int 3] -- base:*, exp: neg, mod: prime
645645
-- base is co-prime with mod and exponent is negative
646-
evals @Integer 4 b [] [cons @Integer 4, cons @Integer (-5), cons @Integer 9]
647-
fails "mod-zero" b [] [one, one, cons @Integer 0] -- base:*, exp:*, mod: 0
648-
fails "mod-neg" b [] [one, one, cons @Integer (-3)] -- base:*, exp:*, mod: neg
646+
evals @Integer 4 b [] [int 4, int (-5), int 9]
647+
-- Always return 0 when modulus is 1.
648+
evals @Integer 0 b [] [zero, zero, one] -- base:0, exp: zero, mod:1
649+
evals @Integer 0 b [] [zero, one, one] -- base:0, exp: 1, mod:1
650+
evals @Integer 0 b [] [zero, int (-1), one] -- base:0, exp: neg, mod:1
651+
evals @Integer 0 b [] [int 500, int 222, one] -- base:*, exp: strictpos, mod:1
652+
evals @Integer 0 b [] [int 500, int (-1777), one] -- base:*, exp: neg, mod:1
653+
fails "mod-zero" b [] [one, one, zero] -- base:*, exp:*, mod: 0
654+
fails "mod-neg" b [] [one, one, int (-3)] -- base:*, exp:*, mod: neg
649655
-- base and mod are not co-prime, negative exponent
650-
fails "exp-neg-non-inverse1" b [] [cons @Integer 2, cons @Integer (-3), cons @Integer 4]
656+
fails "exp-neg-non-inverse1" b [] [int 2, int (-3), int 4]
651657
-- mod is prime, but base&mod are not co-prime, negative exponent
652-
fails "exp-neg-non-inverse2" b [] [cons @Integer 500, cons @Integer (-5), cons @Integer 5]
658+
fails "exp-neg-non-inverse2" b [] [int 500, int (-5), int 5]
653659
where
654-
one = cons @Integer 1
660+
int = cons @Integer
661+
zero = int 0
662+
one = int 1
655663
b = ExpModInteger
656664

657665
-- | Test all string-like builtins

0 commit comments

Comments
 (0)