PrismLang is a Contract Oriented statically typed programming language developed for the EncryCore blockchain protocol.
Primitive Data Types
Any
- a supertype of any other typeUnit
- a type with a single value()
Byte
- 8 bit signed integerInt
- 64 bit signed integerBool
- a type with two logical valuestrue
andfalse
String
- arbitrary sequence of chars
Containers
Array[T]
- arrays of arbitrary length with all values of typeT
Tuple
- tuple of possibly different data types supported in PrismLang
Built-in Complex Types
Signature25519
- is Edwards-curve Digital Signature Algorithm (EdDSA) over Curve25519Transaction
- EncryTransactionState
- Information about current height of the blockchain, timestamp of the last published blockBox
- EncryBoxAssetBox
- EncryAssetBoxDataBox
- EncryDataBox
Build-in functions
unixTime(time: String)
- convert String to Timestamp using yyyy-MM-dd hh:mm:ss formatcheckSig(signature: Signature25519, message: Array[Byte], key: Array[Byte])
- check message was signed with Key
Build-in base functions
encode16(input: Array[Byte]): String
- represents bytes using a base of 16 symbolsencode58(input: Array[Byte]): String
- represents bytes using a base of 58 symbolsbase16'String': Array[Byte]
- decode string to bytes using a base of 16 symbolsbase58'String': Array[Byte]
- decode string to bytes using a base of 58 symbols
Build-in cryptographic hash functions
blake2b256(input: Array[Byte]): Array[Byte]
blake2b512(input: Array[Byte]): Array[Byte]
keccak256(input: Array[Byte]): Array[Byte]
keccak512(input: Array[Byte]): Array[Byte]
sha256(input: Array[Byte]): Array[Byte]
// Constant definition
let a: Int = 10 // Explicit type annotation
let b = 100 // Type will be inferred automatically
let c = if (a > b) true else false // Conditional assignment
// Function definition
def sum(a: Int, b: Int): Int = {
a + b
}
// Lambda definition
lamb (a: Int, b: Int) = a + b
// If statement
let flag: Bool = if (10 < 100) {
true
} else {
false
}
// Type matching
let validProof: Bool = if (let sig: Signature25519 = poof) checkSig(sig, msg, pk) else false
// Base58 string
let pubKeyBytes: Array[Byte] = base58'75Gs7HHUNnoEzsPgRRVABzQaC3UZVcayw9NY457Kx5p'
// Byte
let byte: Byte = (127).toByte
// Collections
let ageList: Array[Int] = List(1, 2, 3, 4)
let ageDict: Dict[String, Int] = Dict('Alice' -> 4, 'Bob' -> 9, 'Tom' -> 17) [Scheduled for the next release]
// Collection subscription
let someonesAge = ageList[0] // Will result in `1`
// Lambda application
let doesExist: Bool = ageList.exists(lamb (i: Int) = i > 3) // true
let ageListDoubled: Array[Int] = ageList.map(lamb (i: Int) = i * 2) // Array(2, 4, 6, 8)
contract (signature: Signature25519) {
let ownerPubKey = base58"GtBn7qJwK1v1EbB6CZdgmkcvt849VKVfWoJBMEWsvTew"
checkSig(ctx.transaction.msg, ownerPubKey, signature)
}
Even more Contract Examples
PrismLang has the following design:
- Compiled
- Strong typed
- Static type-checking
PrismLang was developed in such way for a reason. For example in Ethereum, which is one of the biggest blockchain platforms nowadays, miners use gas as execution fee for every operation made on Ethereum to get paid exactly for the computational resources they spend on this operation. This sometimes leads to OutOfGasError: when the user didn't attach enough gas to execute his transaction, gas is paid to the miner, because he was spending computational power, but the transaction will not be sent to the blockchain.
PrismLang Structure is able to overcome this issue by statically analyzing the source code structure we can precisely estimate the computational cost of the operations. PrismLang does not support looping or recursion primitives for the end user, that leads to the fact, then in the compile time, we already know exactly how many operations we need to perform. Taking the previous statement into consideration, we can conclude that PrismLang can provide both end user and miner with precise Cost of the smart contract.
Furthermore, EncryCore protocol uses an Unspent Transaction Output(UTXO) model for the record keeping and smart contracts are used to lock the transaction output. Therefore, the main features kept in mind for PrismLang development were :
- The simplicity of usage.
- Clearness of the abstractions.
- Acceptable entry threshold.
- Ability to precisely estimate Cost of the operations in a convenient way for both end user and miner.
All contributions are made under the GNU General Public License v3. See LICENSE.