Git Product home page Git Product logo

ola-lang's Introduction

Ola Logo

CI Project license Lines of Code Twitter

Introduction

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

Simple Example

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;
    }

}

Ola language features

Language Type

  • Simple Types: Includes u32, field, bool, enum, address, and hash types. In Ola, all data types are internally represented as combinations of the field type. The maximum value for the field type is 0xFFFFFFFF00000001. The address and hash types are internally represented as arrays of four field elements.
  • Complex Types: Includes static arrays, dynamic arrays, string, fields, structures, and mappings. The fields type is a dynamic array of field elements.
  • Type Aliases: Support for type aliases is included.

Operators

  • Different types support different operators. The u32 type supports the most operators, such as: +, -, *, /, %, **, ==, !=, etc.

Functions

  • Functions are supported in a manner similar to Solidity and Rust, with the keyword fn used to declare functions.

Control Flow

  • Control flow constructs include if statements, if-else statements, while statements, do-while statements, for loops, continue, and break.

Prophet Functions

  • The prophet functions in Ola language are used for non-deterministic computations in specific scenarios, such as u32_sqrt, u32_quick_sort, etc.

Core Lib Functions

  • The ola language provides many core libraries, including assert ,print fileds_conct, encode decode, and so on.

IR Generation

  • The Ola language is processed by the front-end into a subset of LLVM IR for compilation.

Olac Back-End

The LLVM IR subset generated by the Olac compiler front-end is downgraded to OlaVM bytecode for execution by the OlaVM virtual machine.

Supported LLVM IR Subset

Type System:

  • void type
  • Function type
  • Single-value types within the first-order type support i64, i1, ptr types
  • label and token types
  • Aggregate types such as arrays and structures

Instruction Set:

  • 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

Supported IR Libs Extensions

  • 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

OlaVM Assembly

  • The assembly language consists of the program and prophet parts, executed directly by the VM and interpreted by the embedded interpreter, respectively.
  • program part: Defines the assembly output format, supporting the entire OlaVM custom instruction set.
  • prophet part: Refers to the prophets set described in the IR libs extension.

Future Work

  • 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.

๐Ÿงฐ Troubleshooting

If you are having trouble installing and using Ola, please open an issue.

License

Apache 2.0

ola-lang's People

Contributors

bchyl avatar boomyl avatar cyimon avatar hongyuanyang-uu avatar peinlcy avatar restyled-commits avatar softcloud88 avatar sunchengzhu avatar yp945 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ola-lang's Issues

I have a problem with the format of the asm file I generated

my asm file:

{
"program": "main:\n.LBL7_0:\n add r8 r8 4\n mstore [r8,-2] r8\n mov r1 10\n call fib_non_recursive\n add r8 r8 -4\n end\nfib_recursive:\n.LBL8_0:\n add r8 r8 9\n mstore [r8,-2] r8\n mov r0 r1\n mstore [r8,-3] r0\n mload r0 [r8,-3]\n mov r7 2\n gte r0 r7 r0\n cjmp r0 .LBL8_1\n jmp .LBL8_2\n.LBL8_1:\n mov r0 1\n add r8 r8 -9\n ret\n.LBL8_2:\n mload r0 [r8,-3]\n not r7 1\n add r7 r7 1\n add r1 r0 r7\n range r1\n call fib_recursive\n mstore [r8,-7] r0\n mload r0 [r8,-3]\n not r7 2\n add r7 r7 1\n add r0 r0 r7\n mstore [r8,-5] r0\n mload r0 [r8,-5]\n range r0\n mload r1 [r8,-5]\n call fib_recursive\n mload r1 [r8,-7]\n add r0 r1 r0\n mstore [r8,-4] r0\n mload r0 [r8,-4]\n range r0\n mload r0 [r8,-4]\n add r8 r8 -9\n ret\nfib_non_recursive:\n.LBL9_0:\n add r8 r8 5\n mov r0 r1\n mstore [r8,-5] r0\n mov r0 0\n mstore [r8,-4] r0\n mov r0 1\n mstore [r8,-3] r0\n mov r0 1\n mstore [r8,-2] r0\n mov r0 2\n mstore [r8,-1] r0\n jmp .LBL9_1\n.LBL9_1:\n mload r0 [r8,-1]\n mload r1 [r8,-5]\n gte r0 r1 r0\n cjmp r0 .LBL9_2\n jmp .LBL9_4\n.LBL9_2:\n mload r1 [r8,-4]\n mload r2 [r8,-3]\n add r0 r1 r2\n range r0\n mstore [r8,-2] r0\n mload r0 [r8,-3]\n mstore [r8,-4] r0\n mload r0 [r8,-2]\n mstore [r8,-3] r0\n jmp .LBL9_3\n.LBL9_3:\n mload r1 [r8,-1]\n add r0 r1 1\n mstore [r8,-1] r0\n jmp .LBL9_1\n.LBL9_4:\n mload r0 [r8,-2]\n add r8 r8 -5\n ret\n",
"prophets": []
}

[enhance] codegen for CJMP and CompareOp to consistent with ISA improvements

CompareOp. instSel as:

{
Eq tmp a b;/neq tmp a b;/gte tmp a,b;
cjmp tmp label
}

a > b   ( a>=b && a!=b)=>  
{
gte tmp1 a b; neq tmp2 a b;
And tmp3 tmp1 tmp2;
cjmp tmp3 label
}

a < b  (b>=a && a!=b) =>  
{
gte tmp1 b a; neq tmp2 a b;
And tmp3 tmp1 tmp2;
cjmp tmp3 label
}

a <= b  (b>=a) =>  
{
gte tmp b,a;
cjmp tmp label
}

[feature] Field type support

We want to build a plonky2 domain based ola language where all the upper level type system will be encapsulated from the field types

[enhance] For-Loop support

The language front-end currently supports for loops and needs to be extended to support compilation to LLVM-IR

DEV SHOULD CONSIDER ADDING 'VIM' AS A CONDING ENVIRONMENT FOR OLA LANGUGAE ON LINUX/UBUNTU

DEV SHOULD CONSIDER ADDING 'VIM' AS A CONDING ENVIRONMENT FOR OLA LANGUGAE ON LINUX/UBUNTU
THIS WILL MAKE IT MUCH EASIER FRO DEVELOPERS TO DEPLOY SMART CONTRACTS ON OLA LANG AND ALSO INTERACT WITH THEM
What is vim in Ubuntu?

Vim is a powerful text editor that is preinstalled on most Linux distributions. Ubuntu includes Vim, vi, nano, Gedit (GUI), and numerous other text editors. Vim is an improvised version of the vi text editor. Ubuntu comes with Vim preinstalled. However, the preinstalled version is very basic

[enhance] Global variable support

Currently ola only supports variables defined inside functions, in the future global variables will need to be supported, and global variables will need to be designed with the storage model in mind

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.