-
Notifications
You must be signed in to change notification settings - Fork 76
Scilla Built Ins
Here we enumerate the built-in data types and their operations, as well as the standard library.
For built-in primitive data types and operations on them, check the following implementation.
-
eq s1 s1: IsString s1equal toString s2. ReturnsBool. -
concat s1 s2: ConcatenateString s1withString s2. ReturnsString. -
substr s1 i2 i2: Extract sub-string ofString s2starting from positionUint32 i1with lengthUint32 i2. ReturnsString. -
to_string x1: Convertx1to a string literal. Valid types ofx1areIntX,UintX,ByStrXandByStr.
Hash is represented by the data type ByStr32. In the below description, Any can be IntX, UintX, String, ByStrX or ByStr
-
eq h1 h2: IsByStr32 h1equal toByStr32 h2. ReturnsBool. -
to_uint256 b: Convertb : ByStrX when X <= 32intouint256. -
sha256hash x: The SHA256 hash of valueAny x. ReturnsByStr32. -
schnorr_gen_key_pair: Generate a private key / public key pair. ReturnsPair{ByStr32 ByStr33}. -
schnorr_sign privK pubK m: Signs a messageByStr musing the private and public keysByStr32 privKandByStr33 pubK. Returns theByStr64signature. -
schnorr_verify pubK m sig: Verifies that messageByStr mwas signed byByStr32 pubKwith signatureByStr64 sig. ReturnsBool. -
concat x1 x2: Concatenatex1 : ByStrX1andx2 : ByStrX2to result in aByStr(X1+X2)value.
Keys can have types IntX, UintX, String, ByStr32 or ByStr20. Values can be of any type.
-
put m k v: Insert keykand valuevintoMap m. Returns a newMap. -
get m k: InMap m, for keyk, return the associated value asOption v. The returned value isNoneifkis not in the mapm. -
remove k: Remove keykand it's associated valuevfrom the map. Returns a new updatedMap. -
contains k: Is keykand it's associated valuevpresent in the map? ReturnsBool. -
to_list m: ConvertMap minto aList (Pair ('A) ('B))where'Aand'Bare key and value types.
For most IntX and UintX operations, there are two integer inputs.
-
eq i1 i2: Isi1equal toi2. ReturnsBool. -
add i1 i2: Add integer valuesi1andi2. Returns an integer. -
sub i1 i2: Subtracti2fromi1. Returns an integer. -
mul i1 i2: Integer product ofi1andi2. Returns an integer. -
div i1 i2: Integer division ofi1divi2. Returns an integer. -
rem i1 i2: Integer remainder wheni1is divided byi2. Returns an integer. -
lt i1 i2: Isi1lesser thani2. ReturnsBool. -
pow i1 i2:i1raised to the poweri2. Returns an integer ofi1's type.i2isUint32. -
to_nat i1: ConvertUint32 i1value toNat. -
to_(u)int(32/64/128/256): Convert aUintX/IntXorString(that represents a number) value to anotherUintX/IntXvalue. ReturnsSome IntX/UintXif conversion succeeded,Noneotherwise.
Addition, subtraction, multiplication, pow, division and reminder operations may raise integer overflow, underflow and division_by_zero errors.
Addresses are represented by the data type ByStr20.
-
eq a1 a2: IsByStr20 a1equal toByStr20 a2. ReturnsBool.
-
eq b1 b2: IsBNum b1equal toBNum b2. ReturnsBool. -
blt b1 b2: IsBNum b1less thanBNum b2. ReturnsBool. -
badd b1 i1: AddUintX i1toBNum b1. ReturnsBNum. -
bsub b1 b2: SubtractBNum b2fromBNum b1. ReturnsInt256.
At the moment, Scilla features the following folding principles (structural recursion primitives) for Nats and Lists:
nat_fold : forall 'T, ('T -> Nat -> 'T) -> 'T -> Nat -> 'T
list_foldl: forall 'A . forall 'B . ('B -> 'A -> 'B) -> 'B -> (List 'A) -> 'B
list_foldr: forall 'A . forall 'B . ('A -> 'B -> 'B) -> 'B -> (List 'A) -> 'B
Check the Tutorial for more intuition and examples.
Here we enumerate a series of functions, which are implemented as a part of the standard library via the built-in functions and recursion primitives. Those are going to be verified and made available for any Scilla program, so the clients wouldn't have to reinvent a wheel every time.
-
list_map:('A -> 'B) -> List 'A -> : List 'B.Apply
f : 'A -> 'Bto every element ofl : List 'A. Linear complexity. -
list_filter:('A -> Bool) -> List 'A -> List 'A.Preserving the order of elements in
l : List 'A, return new list containing only those elements that satisfy the predicatef : 'A -> Bool. Linear complexity. -
list_head:(List 'A) -> (Option 'A).Return the head element of a list
l : List 'AasSome 'A,NoneiflisNil(the empty list). -
list_tail:(List 'A) -> (Option List 'A).For input list
l : List 'A, returnsSome l', wherel'islexcept for it's head; returnsSome Niliflhas only one element; returnsNoneiflis empty. -
list_append:(List 'A -> List 'A -> List 'A).Append the second list to the first one and return a new List. Linear complexity (on first list).
-
list_reverse:(List 'A -> List 'A).Return the reverse of the input list. Linear complexity.
-
list_flatten:(List List 'A) -> List 'A.Concatenate a list of lists. Each element (List 'A) of the input (List List 'A) are all concatenated together (in the same order) to give the result. linear complexity over the total number of elements in all of the lists.
-
list_length:List 'A -> Int32Number of elements in list. Linear complexity.
-
list_eq:('A -> 'A -> Bool) -> List 'A -> List 'A -> Bool.Takes a function
f : 'A -> 'A -> Boolto compare elements of listsl1 : List 'Aandl2 : List 'Aand returns True iff all elements of the lists compare equal. Linear complexity. -
list_mem:('A -> 'A -> Bool) -> 'A -> List 'A -> Bool.Checks whether an element
a : 'Ais in the listl : List'A.f : 'A -> 'A -> Boolshould be provided for equality comparison. Linear complexity. -
list_forall:('A -> Bool) -> List 'A -> Bool.Return True iff all elements of list
l : List 'Asatisfy predicatef : 'A -> Bool. Linear complexity. -
list_exists:('A -> Bool) -> List 'A -> Bool.Return True if at least one element of list
l : List 'Asatisfies predicatef : 'A -> Bool. Linear complexity. Linear complexity. -
list_sort:('A -> 'A -> Bool) -> List 'A -> List 'A.Stable sort the input list
l : List 'A. Functionflt : 'A -> 'A -> Boolprovided must return True iff its first argument is lesser-than its second argument. Linear complexity. -
list_find:('A -> Bool) -> 'A -> 'A.Return
Some a, whereais the first element ofl : List 'Athat satisfies the predicatef : 'A -> Bool. ReturnsNoneiff none of the elements inlsatisfyf. Linear complexity. -
list_zip:List 'A -> List 'B -> List (Pair 'A 'B).Combine corresponding elements of
m1 : List 'Aandm2 : List 'Binto aPairand return the resulting list. In case of different number of elements in the lists, the extra elements are ignored. -
list_zip_with:('A -> 'B -> 'C) -> List 'A -> List 'B -> List 'C *). Linear complexity.Combine corresponding elements of
m1 : List 'Aandm2 : List 'Busingf : 'A -> 'B -> 'Cand return the resulting list of'C. In case of different number of elements in the lists, the extra elements are ignored. -
list_unzip:List (Pair 'A 'B) -> Pair (List 'A) (List 'B).Convert a list
l : Pair 'A 'BofPairs into aPairof lists. Linear complexity. -
list_nth:Int32 -> List 'A -> Option 'A.Returns
Some 'Aif n'th element exists in list.Noneotherwise. Linear complexity. -
nat_eq:Nat -> Nat -> Bool.Compare two natural numbers (
Nat) for equality.
Conversions:
-
list_to_map:List (Pair 'A 'B) -> Map 'A 'BConvert a list (
l : Pair 'A 'B) of key-val pairs into a map (Map 'A 'B), overwriting duplicates. -
nat_to_int:Nat -> Uint32.Convert a natural number
n : Natinto an integer. -
to_uintXandto_intX:IntX/UintX -> Option IntX/UintX. Conversion between integer types. All these utilities returnSome IntX/UintXon success,Noneotherwise. A conversion is said to succeed if the source value can be represented in the destination type. -
intX_to_natanduintX_to_nat:IntX/UintX -> Option NatConvert signed and unsigned integers to
Nat. ReturnsSome Naton successful conversion,Noneotherwise. The built-into_natsupports only convertingUint32values toNat. Hence these wrappers succeed only if the input value can be represented inUint32.