CoreLib Functions
Cryptographic Primitives
The Ola team is progressively adding new cryptographic primitives to the standard library. Reach out for news or if you would be interested in adding more of these calculations in Ola.
poseidon_hash
Given an fields (array of fields) or string , returns the resulting poseidon hash.
example:
signature
Get the signature of this transaction.
check_ecdsa
Verifier for ECDSA Secp256k1 signatures
example:
Logging
The standard library provides two familiar statements you can use: println
and print
. Despite being a limited implementation of rust's print function , these constructs can be useful for debugging.
example:
Assert
ola provides an assertion function, which can ensure the correct execution of some statements. When the assert fails, the transaction will revert.
example:
BlockChain Context
Ola provides many functions to obtain the status of L2 blockchain. The implementation meaning of these functions is mostly consistent with Solidity, but there are differences in writing.
caller_address
contract caller address
address caller = caller_address()
origin_address
contract origin caller address
address origin = origin_address()
code_address
current execute code contract address
address code_addr = code_address()
current_address
current state write and read contract address
address state_addr = current_address()
chain_id
(u32) The future may be replaced by u256 data types.
u32 chainID = chain_id();
block_number
u32
u32 blocknumber = block_number()
block_timestamp
u32
u32 time = block_timestamp()
sequence_address
address
address sequencer = sequence_address()
tx_version
u32
u32 version = tx_version()
nonce
u32
u32 nonce_number = nonce();
tx_hash
hash
hash h = tx_hash()
Utils
Ola provides some utility functions, here is the list of available functions.
u32_array_sort
u32 array
sorted array
u32_array_sort([2, 1, 3, 4]);
get_selector
u32
u32 selector = get_selector("setVars(u32)");
fields_concat
fields a and fields b
new fields
fields ret = fields_concat(a, b);
string_concat
string a and string b
new string
string ret = string_concat(a, b);
abi.encode
various types of uncertain quantities
fields
fields encode_value = abi.encode(a, b);
abi.decode
fields data wtih various types
tuple with all type value
u32 result = abi.decode(data, (u32));
abi.encodeWithSignature
string function selector and params
fields
fields call_data = abi.encodeWithSignature("add(u32,u32)", a, b);
Last updated