-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[plinth][plc][api][agda] Draft of modExpInteger builtin (#6348)
[agda] Added builtin expModInteger Co-authored-by: Nikolaos Bezirgiannis <bezirg@users.noreply.github.com>
- Loading branch information
Showing
87 changed files
with
513 additions
and
221 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
1 change: 1 addition & 0 deletions
1
...evaluation/builtin/semantics/expModInteger/exp-neg-non-inverse1/exp-neg-non-inverse1.uplc
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 [ [ [ (builtin expModInteger) (con integer 2)] (con integer -3) ] (con integer -4)]) |
1 change: 1 addition & 0 deletions
1
...in/semantics/expModInteger/exp-neg-non-inverse1/exp-neg-non-inverse1.uplc.budget.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
evaluation failure |
1 change: 1 addition & 0 deletions
1
...n/builtin/semantics/expModInteger/exp-neg-non-inverse1/exp-neg-non-inverse1.uplc.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
evaluation failure |
1 change: 1 addition & 0 deletions
1
...evaluation/builtin/semantics/expModInteger/exp-neg-non-inverse2/exp-neg-non-inverse2.uplc
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 [ [ [ (builtin expModInteger) (con integer 500)] (con integer -5) ] (con integer 5)]) |
1 change: 1 addition & 0 deletions
1
...in/semantics/expModInteger/exp-neg-non-inverse2/exp-neg-non-inverse2.uplc.budget.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
evaluation failure |
1 change: 1 addition & 0 deletions
1
...n/builtin/semantics/expModInteger/exp-neg-non-inverse2/exp-neg-non-inverse2.uplc.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
evaluation failure |
1 change: 1 addition & 0 deletions
1
...nformance/test-cases/uplc/evaluation/builtin/semantics/expModInteger/expMod1/expMod1.uplc
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 [ [ [ (builtin expModInteger) (con integer 500)] (con integer 0) ] (con integer 500)]) |
2 changes: 2 additions & 0 deletions
2
...ases/uplc/evaluation/builtin/semantics/expModInteger/expMod1/expMod1.uplc.budget.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
({cpu: 100000112100 | ||
| mem: 100000000800}) |
1 change: 1 addition & 0 deletions
1
.../test-cases/uplc/evaluation/builtin/semantics/expModInteger/expMod1/expMod1.uplc.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 (con integer 1)) |
1 change: 1 addition & 0 deletions
1
...nformance/test-cases/uplc/evaluation/builtin/semantics/expModInteger/expMod2/expMod2.uplc
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 [ [ [ (builtin expModInteger) (con integer 500)] (con integer 5) ] (con integer 500)]) |
2 changes: 2 additions & 0 deletions
2
...ases/uplc/evaluation/builtin/semantics/expModInteger/expMod2/expMod2.uplc.budget.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
({cpu: 100000112100 | ||
| mem: 100000000800}) |
1 change: 1 addition & 0 deletions
1
.../test-cases/uplc/evaluation/builtin/semantics/expModInteger/expMod2/expMod2.uplc.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 (con integer 0)) |
1 change: 1 addition & 0 deletions
1
...nformance/test-cases/uplc/evaluation/builtin/semantics/expModInteger/expMod3/expMod3.uplc
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 [ [ [ (builtin expModInteger) (con integer 1)] (con integer -3) ] (con integer 4)]) |
2 changes: 2 additions & 0 deletions
2
...ases/uplc/evaluation/builtin/semantics/expModInteger/expMod3/expMod3.uplc.budget.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
({cpu: 100000112100 | ||
| mem: 100000000800}) |
1 change: 1 addition & 0 deletions
1
.../test-cases/uplc/evaluation/builtin/semantics/expModInteger/expMod3/expMod3.uplc.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 (con integer 1)) |
1 change: 1 addition & 0 deletions
1
...nformance/test-cases/uplc/evaluation/builtin/semantics/expModInteger/expMod4/expMod4.uplc
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 [ [ [ (builtin expModInteger) (con integer 2)] (con integer -3) ] (con integer 3)]) |
2 changes: 2 additions & 0 deletions
2
...ases/uplc/evaluation/builtin/semantics/expModInteger/expMod4/expMod4.uplc.budget.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
({cpu: 100000112100 | ||
| mem: 100000000800}) |
1 change: 1 addition & 0 deletions
1
.../test-cases/uplc/evaluation/builtin/semantics/expModInteger/expMod4/expMod4.uplc.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 (con integer 2)) |
1 change: 1 addition & 0 deletions
1
...nformance/test-cases/uplc/evaluation/builtin/semantics/expModInteger/expMod5/expMod5.uplc
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 [ [ [ (builtin expModInteger) (con integer 4)] (con integer -5) ] (con integer 9)]) |
2 changes: 2 additions & 0 deletions
2
...ases/uplc/evaluation/builtin/semantics/expModInteger/expMod5/expMod5.uplc.budget.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
({cpu: 100000112100 | ||
| mem: 100000000800}) |
1 change: 1 addition & 0 deletions
1
.../test-cases/uplc/evaluation/builtin/semantics/expModInteger/expMod5/expMod5.uplc.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 (con integer 4)) |
1 change: 1 addition & 0 deletions
1
...nformance/test-cases/uplc/evaluation/builtin/semantics/expModInteger/mod-neg/mod-neg.uplc
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 [ [ [ (builtin expModInteger) (con integer 1)] (con integer 1) ] (con integer -3)]) |
1 change: 1 addition & 0 deletions
1
...ases/uplc/evaluation/builtin/semantics/expModInteger/mod-neg/mod-neg.uplc.budget.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
evaluation failure |
1 change: 1 addition & 0 deletions
1
.../test-cases/uplc/evaluation/builtin/semantics/expModInteger/mod-neg/mod-neg.uplc.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
evaluation failure |
1 change: 1 addition & 0 deletions
1
...ormance/test-cases/uplc/evaluation/builtin/semantics/expModInteger/mod-zero/mod-zero.uplc
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(program 1.0.0 [ [ [ (builtin expModInteger) (con integer 1)] (con integer 1) ] (con integer 0)]) |
1 change: 1 addition & 0 deletions
1
...es/uplc/evaluation/builtin/semantics/expModInteger/mod-zero/mod-zero.uplc.budget.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
evaluation failure |
1 change: 1 addition & 0 deletions
1
...est-cases/uplc/evaluation/builtin/semantics/expModInteger/mod-zero/mod-zero.uplc.expected
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
evaluation failure |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Added | ||
|
||
- An initial DRAFT implementation of 'modularExponentiation' builtin |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE MagicHash #-} | ||
{-# LANGUAGE UnboxedSums #-} | ||
module PlutusCore.Crypto.ExpMod | ||
( expMod | ||
) where | ||
|
||
import PlutusCore.Builtin | ||
|
||
import GHC.Natural | ||
|
||
-- Ghc>=9 has this in base | ||
#if MIN_VERSION_base(4,15,0) | ||
import GHC.Num.Integer | ||
-- similar to `Default.Builtins.nonZeroSecondArg` | ||
-- We don't really need it because integerPowMod# returns `()` on zero mod, but we put | ||
-- in case of future implementation changes. | ||
expMod _ _ 0 = fail "Cannot divide by zero" | ||
expMod b e m = | ||
case integerPowMod# b e m of | ||
(# n | #) -> pure n | ||
(# | () #) -> fail "expMod: failure" | ||
#else | ||
-- FIXME: fugly stub implementation to make the various test-suites/CI pass for GHC8.10. | ||
-- This means that we cannot provide random testing for expMod at the moment. | ||
expMod _ _ 0 = fail "Cannot divide by zero" | ||
expMod 500 0 500 = pure 1 | ||
expMod 500 5 500 = pure 0 | ||
expMod 1 (-3) 4 = pure 1 | ||
expMod 2 (-3) 3 = pure 2 | ||
expMod 4 (-5) 9 = pure 4 | ||
expMod 2 (-3) 4 = fail "expMod: failure" | ||
expMod 500 (-5) 5 = fail "expMod: failure" | ||
-- FIXME: this has to be fixed either by deciding to stop supporting GHC8.10 | ||
-- or by backporting ghc-bignum's integerPowMod# implementation to old ghc8.10/integer-gmp<1.1 | ||
expMod _b _e _m = fail "expMod: FIXME: stub for GHC8.10, report to plutus developers" | ||
#endif | ||
|
||
expMod :: Integer -> Integer -> Natural -> BuiltinResult Natural | ||
{-# INLINE expMod #-} |
Oops, something went wrong.