Ola is a high-level programming language for developing OlaVM smart contracts. It is Turing complete and can be used to write arithmetic programs. The computing process is proven by the OlaVM back-end proof system, which verifies that the OlaVM processing is accurate. Most of the existing programming languages in the ZKP field require fundamental knowledge of the circuit field, which is not universal, or the execution process is difficult to be proven and verified by ZKP.
πππ Ola Language Documentation
The following shows a simple contract for calculating the Fibonacci function
contract Fibonacci {
fn fib_recursive(u32 n) -> (u32) {
if (n <= 2) {
return 1;
}
return fib_recursive(n -1) + fib_recursive(n -2);
}
fn fib_non_recursive(u32 n) -> (u32) {
u32 first = 0;
u32 second = 1;
u32 third = 1;
for (u32 i = 2; i <= n; i++) {
third = first + second;
first = second;
second = third;
}
return third;
}
}
- Simple Types: Includes
u32,field,bool,enum,address, andhashtypes. In Ola, all data types are internally represented as combinations of thefieldtype. The maximum value for thefieldtype is0xFFFFFFFF00000001. Theaddressandhashtypes are internally represented as arrays of fourfieldelements. - Complex Types: Includes static arrays, dynamic arrays,
string,fields, structures, and mappings. Thefieldstype is a dynamic array offieldelements. - Type Aliases: Support for type aliases is included.
- Different types support different operators. The
u32type supports the most operators, such as:+,-,*,/,%,**,==,!=, etc.
- Functions are supported in a manner similar to Solidity and Rust, with the keyword
fnused to declare functions.
- Control flow constructs include
ifstatements,if-elsestatements,whilestatements,do-whilestatements,forloops,continue, andbreak.
- The
prophetfunctions in Ola language are used for non-deterministic computations in specific scenarios, such asu32_sqrt,u32_quick_sort, etc.
- The ola language provides many core libraries, including
assert,printfileds_conct,encodedecode, and so on.
- The Ola language is processed by the front-end into a subset of LLVM IR for compilation.
The LLVM IR subset generated by the Olac compiler front-end is downgraded to OlaVM bytecode for execution by the OlaVM virtual machine.
voidtype- Function type
- Single-value types within the first-order type support
i64,i1,ptrtypes labelandtokentypes- Aggregate types such as arrays and structures
- Terminal instructions:
ret,br,switch - Unary operation:
neg - Binary operations:
add,sub,mul - Logical operations:
and,or,xor - Aggregate operations:
insertvalue,extractvalue - Memory access and addressing:
alloca,store,load,getelementptr - Conversion instruction:
trunc - Other operations:
icmp,phi,call
- Includes built-ins and prophets:
assert,rangecheck,u32_sqrt,div,mod,vec_new,poseidon_hash - Contract storage access operations:
set_storage,get_storage - Contract input/output access operations:
get_context_data,get_tape_data,set_tape_data - Debugging:
printf - Cross-contract calls:
contract_call
- The assembly language consists of the
programandprophetparts, executed directly by the VM and interpreted by the embedded interpreter, respectively. programpart: Defines the assembly output format, supporting the entire OlaVM custom instruction set.prophetpart: Refers to theprophetsset described in the IR libs extension.
- Introduction of a testing framework, more orderly language design, and robust compiler engineering implementation.
- Heap memory allocation and management reconstruction, more streamlined instruction generation.
- Optimization of code generation for front-end and back-end, higher efficiency in instruction generation and execution.
- Design of object-oriented syntax for contracts, enhancing the language's expressive power.
- Expansion of privacy features in contracts, supporting ZK privacy contract programming.
If you are having trouble installing and using Ola, please open an issue.
