Before writing an ola contract we recommend using vscode as an editor. You can download vscode from here https://code.visualstudio.com/
Ola supports writing on vscode, we have developed an extension to vscode to support ola syntax highlighting, and we will continue to improve the plugin in the future.
The extension can be found on the Visual Studio Marketplace.
The following shows a smart contract that calculates the tenth term of the Fibonacci number
contract Fibonacci {
fn main() {
fib_recursive(10);
}
fn fib_recursive(u32 n) -> (u32) {
if (n == 1) {
return 1;
}
if (n == 2) {
return 1;
}
return fib_recursive(n -1) + fib_recursive(n -2);
}
}
You can copy it to vscode, With the ola extension, the code in vscode looks like this
Note: We are not yet able to support too complex smart contract statements such as For Loop, global variables, etc. If you encounter a compilation error, relax. We will fix it in a later compiler update 😀 😀 .
Once you have finished writing the smart contract, you need to compile the smart contract source code into an assembly format that OlaVM can execute. So next you need to prepare the compilation environment
4.1.1 Installation Rust
You can install Rust by entering the following command in your terminal
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup toolchain install nightly
rustup default nightly
4.1.2 Installation LLVM
In order to build the ola-lang project, you need to have LLVM installed on your system.
For macos, installing llvm with brew is very easy.
You can install LLVM by entering the following command in your terminal
brew install llvm@14
echo 'export PATH="/usr/local/opt/llvm@14/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
You can check if llvm is installed successfully by typing llvm-config --version
in the terminal
You can download ola-lang repository by entering the following command in your terminal
git clone https://github.com/Sin7Y/ola-lang.git
cd ola-lang
cargo install --path .
The executable olac
will be install in you environment. You can check this by entering the olac --help
command
The olac compiler is run on the command line. The ola source file names are provided as command line arguments; the output is an ola asm.
You can compile ola contract by entering the following command in your terminal
olac compile ./examples/fib.ola --gen asm
After the above command is executed, a file named fib.asm
will be created in the current folder.
The OlaVM will read the fib.asm file in the current directory, execute the opcode contained in that file, and generate an execution trace to prove that the system generated the proof.
Before generating proofs, some preparatory work needs to be done
You can download olavm repository by entering the following command in your terminal
git clone https://github.com/Sin7Y/olavm.git
cd olavm/client/
cargo install --path .
The executable ola
will be install in you environment. You can check this by entering the ola --help
command
You can assembly ola contract asm format file by entering the following command in your terminal
ola asm --input fib.asm --output fib.code
After the above command is executed, a file named fib.code
will be created in the current folder.
You can execute ola contract code by entering the following command in your terminal
ola run --input fib.code --output fib_trace.json
After the above command is executed, a file named fib_trace.json
will be created in the current folder.
You can generate proof by entering the following command in your terminal
ola prove --input fib_trace.json --output fib.proof
After the above command is executed, a file named fib.proof
will be created in the current folder.
You can verify proof by entering the following command in your terminal
ola verify --input fib.proof
When you see output like the following, congratulations, it's all done
❯ ola verify --input fib.proof
Loading proof...nput fib.proof
Input file path: fib.proof
Verify succeed!