Skip to content

Commit 6acfab3

Browse files
committed
feat: add Plinth factorial submission
- Create complete factorial submission for Plinth 1.52.0.0 - factorial.uplc program computing factorial(10) = 3628800 - Performance metrics: 5.86M CPU units, 21.7K memory units - All validation checks pass - Source code included in submission
1 parent 664dbcd commit 6acfab3

7 files changed

Lines changed: 155 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Benchmark Implementation Notes
2+
3+
**Scenario**: `factorial`
4+
5+
**Submission ID**: `Plinth_1.52.0.0_Unisay` (Format: `Language_Version_GitHubHandle`)
6+
7+
## Implementation Details
8+
9+
- **Compiler**: `Plinth 1.52.0.0`
10+
- **Implementation Approach**: `recursive`
11+
- **Compilation Flags**: Standard Plinth (PlutusTx) optimization flags
12+
13+
## Performance Results
14+
15+
- See [metrics.json](metrics.json) for detailed performance measurements
16+
- **Result**: `factorial(10) = 3628800`
17+
- **CPU Units**: 5,859,917
18+
- **Memory Units**: 21,751
19+
- **Script Size**: 37 bytes
20+
21+
## Reproducibility
22+
23+
- **Source Available**: `true`
24+
- **Source Repository**: https://github.com/IntersectMBO/UPLC-CAPE
25+
- **Compilation Config**: Targeting Plutus Core 1.1.0 with standard PlutusTx plugin configuration
26+
27+
## Notes
28+
29+
- Uses recursive factorial implementation: `factorial(n) = if n <= 0 then 1 else n * factorial(n-1)`
30+
- Much more efficient than fibonacci due to linear recursion vs exponential
31+
- Compiled with PlutusTx plugin targeting Plutus Core 1.1.0
32+
- Source code available in the `plinth/src/Factorial.hs` module
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"comment": "Optional: Include compilation parameters that affect UPLC output",
3+
"optimization_flags": [],
4+
"compiler_settings": {},
5+
"build_environment": {}
6+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(program
2+
1.1.0
3+
[
4+
[
5+
(lam s-0 [ s-0 s-0 ])
6+
(lam
7+
s-1
8+
(lam
9+
n-2
10+
(case
11+
[ [ (builtin lessThanEqualsInteger) n-2 ] (con integer 0) ]
12+
[
13+
[ (builtin multiplyInteger) n-2 ]
14+
[
15+
[ s-1 s-1 ]
16+
[ [ (builtin subtractInteger) n-2 ] (con integer 1) ]
17+
]
18+
]
19+
(con integer 1)
20+
)
21+
)
22+
)
23+
]
24+
(con integer 10)
25+
]
26+
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"compiler": {
3+
"name": "Plinth",
4+
"version": "1.52.0.0",
5+
"commit_hash": "800c67d38d01177fd0a36d01aa23ff7fea7bd1ba"
6+
},
7+
"compilation_config": {
8+
"optimization_level": "Plinth",
9+
"target": "uplc",
10+
"flags": ["Plinth"],
11+
"environment": {
12+
"dependencies": {
13+
"plutus-tx": "1.52.0.0",
14+
"plutus-core": "1.52.0.0",
15+
"plutus-ledger-api": "1.52.0.0"
16+
}
17+
}
18+
},
19+
"contributor": {
20+
"name": "Unisay",
21+
"organization": "UPLC-CAPE Project"
22+
},
23+
"submission": {
24+
"date": "2025-08-18T08:00:00Z",
25+
"source_available": true,
26+
"source_repository": "https://github.com/IntersectMBO/UPLC-CAPE",
27+
"implementation_notes": "Factorial implementation using Plinth (PlutusTx) with parameter 10, targeting Plutus Core 1.1.0. Recursive approach computing factorial(10) = 3628800."
28+
}
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"execution_environment": {
3+
"evaluator": "PlutusTx.Eval-1.52.0.0"
4+
},
5+
"measurements": {
6+
"cpu_units": 5859917,
7+
"memory_units": 21751,
8+
"script_size_bytes": 37,
9+
"term_size": 29
10+
},
11+
"notes": "<optional notes>",
12+
"scenario": "factorial",
13+
"timestamp": "2025-08-18T08:00:10Z",
14+
"version": "1.0.0"
15+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Optional: Place your source code files here
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{-# LANGUAGE BangPatterns #-}
2+
{-# LANGUAGE BlockArguments #-}
3+
{-# LANGUAGE DataKinds #-}
4+
{-# LANGUAGE LambdaCase #-}
5+
{-# LANGUAGE MultiParamTypeClasses #-}
6+
{-# LANGUAGE MultiWayIf #-}
7+
{-# LANGUAGE NamedFieldPuns #-}
8+
{-# LANGUAGE OverloadedStrings #-}
9+
{-# LANGUAGE PatternSynonyms #-}
10+
{-# LANGUAGE Strict #-}
11+
{-# LANGUAGE TemplateHaskell #-}
12+
{-# LANGUAGE ViewPatterns #-}
13+
{-# LANGUAGE NoImplicitPrelude #-}
14+
--
15+
{-# OPTIONS_GHC -fno-full-laziness #-}
16+
{-# OPTIONS_GHC -fno-ignore-interface-pragmas #-}
17+
{-# OPTIONS_GHC -fno-omit-interface-pragmas #-}
18+
{-# OPTIONS_GHC -fno-spec-constr #-}
19+
{-# OPTIONS_GHC -fno-specialise #-}
20+
{-# OPTIONS_GHC -fno-strictness #-}
21+
{-# OPTIONS_GHC -fno-unbox-small-strict-fields #-}
22+
{-# OPTIONS_GHC -fno-unbox-strict-fields #-}
23+
{-# OPTIONS_GHC -fplugin PlutusTx.Plugin #-}
24+
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:no-conservative-optimisation #-}
25+
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:no-preserve-logging #-}
26+
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:remove-trace #-}
27+
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:target-version=1.1.0 #-}
28+
29+
module Factorial (factorialCode, factorial10Code) where
30+
31+
import PlutusTx
32+
import PlutusTx.Prelude
33+
34+
-- | Compiled validator script
35+
factorialCode :: CompiledCode (Integer -> Integer)
36+
factorialCode = $$(PlutusTx.compile [||factorial||])
37+
38+
-- | The compiled factorial validator for n=10
39+
factorial10Code :: CompiledCode Integer
40+
factorial10Code = factorialCode `unsafeApplyCode` liftCodeDef (10 :: Integer)
41+
42+
{-# INLINEABLE factorial #-}
43+
factorial :: Integer -> Integer
44+
factorial n
45+
| n <= 0 = 1
46+
| otherwise = n * factorial (n - 1)

0 commit comments

Comments
 (0)