-
-
Notifications
You must be signed in to change notification settings - Fork 811
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d6c0e1d
commit 1a2fa0d
Showing
2 changed files
with
238 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,237 @@ | ||
.. index:: function, built-in; | ||
|
||
.. _built_in_functions: | ||
|
||
*********************** | ||
Built in Functions | ||
*********************** | ||
|
||
Viper contains a set amount of built in functions that would be timely and/or unachievable to write in Viper. | ||
|
||
.. _functions: | ||
|
||
Functions | ||
========= | ||
The first list dictates each argument and the second sublist lists the types allowed as input. | ||
|
||
* **floor** | ||
:: | ||
|
||
def floor(a) -> b: | ||
""" | ||
:param a: value to round down | ||
:type a: either decimal or num | ||
|
||
:output b: interger | ||
""" | ||
Rounds a decimal down to the nearest integer. | ||
|
||
* **decimal** | ||
:: | ||
|
||
def decimal(a) -> b: | ||
""" | ||
:param a: value to turn into decimal | ||
:type a: either decimal or num | ||
|
||
:output b: decimal | ||
""" | ||
Turns a number into a decimal. | ||
|
||
* **as_unitless_number** | ||
:: | ||
|
||
def as_unitless_number(a) -> b: | ||
""" | ||
:param a: value to remove units from | ||
:type a: either decimal or num | ||
|
||
:output b: either decimal or num | ||
""" | ||
Turns a ``num`` or ``decimal`` with units into one without units (used for assignment and math). | ||
|
||
* **as_num128** | ||
:: | ||
|
||
def as_num128(a) -> b: | ||
""" | ||
:param a: value to turn into int128 | ||
:type a: either num, bytes32, num256, or bytes | ||
|
||
:output b: num | ||
""" | ||
Turns input into a ``num`` (int128). | ||
|
||
* **as_num256** | ||
:: | ||
|
||
def as_num256(a) -> b: | ||
""" | ||
:param a: value to turn into num256 | ||
:type a: either num_literal, num, bytes32, or address | ||
|
||
:output b: num256 | ||
""" | ||
Turns input into a ``num256`` (uint256). | ||
|
||
* **as_bytes32** | ||
:: | ||
|
||
def as_bytes32(a) -> b: | ||
""" | ||
:param a: value to turn into bytes32 | ||
:type a: either num, num256, address | ||
|
||
:output b: bytes32 | ||
""" | ||
Turns input into a ``bytes32``. | ||
|
||
* **slice** | ||
:: | ||
|
||
def slice(a, start=b, length=c) -> d: | ||
""" | ||
:param a: bytes to be sliced | ||
:type a: either bytes or bytes32 | ||
:param b: start position of the slice | ||
:type b: num | ||
:param c: length of the slice | ||
:type c: num | ||
|
||
:output d: bytes | ||
""" | ||
Takes a a list of bytes, the start bytes to take and the length to take and returns the associated chunk. | ||
|
||
* **len** | ||
:: | ||
|
||
def len(a) -> b: | ||
""" | ||
:param a: value to get the length of | ||
:type a: bytes | ||
|
||
:output b: num | ||
""" | ||
Returns the length of a given list of bytes. | ||
|
||
* **concat** | ||
:: | ||
|
||
def concat(a, b, ...) -> c: | ||
""" | ||
:param a: value to combine | ||
:type a: bytes | ||
:param b: value to combine | ||
:type b: bytes | ||
|
||
:output b: bytes | ||
""" | ||
Takes multiple bytes arrays and turns them into one. | ||
|
||
* **keccak256 (sha3)** | ||
:: | ||
|
||
def keccak256(a) -> b: | ||
""" | ||
:param a: value to hash | ||
:type a: either str_literal, bytes, bytes32 | ||
|
||
:output b: bytes32 | ||
""" | ||
Returns ``keccak_256`` (Ethereums sha3) hash of input. | ||
|
||
* **method_id** | ||
:: | ||
|
||
def method_id(a) -> b: | ||
""" | ||
:param a: method declaration | ||
:type a: str_literal | ||
|
||
:output b: bytes | ||
""" | ||
**Name:** ``method_id`` | ||
Takes a function declaration and returns its method_id (used in data field to call it). | ||
|
||
|
||
* **ecrecover** | ||
:: | ||
|
||
def ecrecover(hash, v, r, s) -> b: | ||
""" | ||
:param hash: a signed hash | ||
:type hash: bytes32 | ||
:param v: | ||
:type v: num256 | ||
:param r: elliptic curve point | ||
:type r: num256 | ||
:param s: elliptic curve point | ||
:type s: num256 | ||
|
||
:output b: address | ||
|
||
Takes a signed hash and vrs and returns the public key of the signer. | ||
|
||
|
||
* **ecadd** | ||
:: | ||
|
||
def ecadd(a, b) -> sum: | ||
""" | ||
:param a: pair to be added | ||
:type a: num252[2] | ||
:param b: pair to be added | ||
:type b: num252[2] | ||
|
||
:output sum: num256[2] | ||
""" | ||
|
||
Takes two elliptical curves and adds them together. | ||
|
||
|
||
* **ecadd** | ||
:: | ||
|
||
def ecadd(a, b) -> product: | ||
""" | ||
:param a: pair to be multipled | ||
:type a: num252[2] | ||
:param b: pair to be multipled | ||
:type b: num252[2] | ||
|
||
:output product: num256[2] | ||
""" | ||
|
||
Takes two elliptical curves and mupltiples them together. | ||
|
||
|
||
* **extract32** | ||
:: | ||
|
||
def extract32(a, b, type=c) -> d: | ||
""" | ||
:param a: where 32 bytes are extacted from | ||
:type a: bytes | ||
:param b: start point of bytes to be extracted | ||
:type b: num | ||
:param c: type of output | ||
:type c: either bytes32, num128, or address | ||
|
||
:output d: either bytes32, num128, or address | ||
""" | ||
|
||
Takes a byte array and extracts 32 bytes from it. | ||
|
||
|
||
* **bytes_to_num** | ||
:: | ||
|
||
def bytes_to_num(a) -> b: | ||
""" | ||
:param a: bytes to be transformed | ||
:type a: bytes | ||
|
||
:output d: num | ||
""" | ||
|
||
Transforms bytes to num. |
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