NethermindEth / warp-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Warp plugin

A modified version of Scarb which adds a new custom compiler that allows the use of custom implicits.

Features

The plugin allows the use of attributes to add parameters to functions that work the same as Cairo 0 custom implicits. For example:

mod Module{
    fn init_x() {
        let mut x = 100;
        increase_x(50);
        assert(x == 150, 'Error');
    }

    #[implicit(x: felt252)]
    fn increase_x(value: felt252) {
        x = x + value;
    }
}

Generates the following code:

mod Module {
    fn init_x() {
        let mut x = 100;
        increase_x(ref x, 50);
        assert(x == 150, 'Error');
    }

    fn increase_x(ref x: felt252, value: felt252) {
        x = x + value;
    }
}

Two important things to notice here:

  • In the init_x function, the call to increase_x gained x as an argument

  • The increase_x function gained an extra x parameter.

Note It is important that variable name remains similar in order to automatically infer the implicits, just like x in the previous example.

Installation

First clone the project in your local machine:

git clone https://github.com/NethermindEth/warp-plugin

Then enter the folder and compile using Cargo:

cd warp-plugin
cargo build --all --release

The building process can take a few minutes.

Use

warp comes with three compilers:

  • A Lib compiler, provided by Scarb

  • The normal Starknet compiler

  • Modified Starknet compiler which executes the plugin

In order to use the one with the plugin you should add the following line to Scarb.toml:

[[target.warp]]

Once the Scarb.toml is modified, from the warp-plugin folder execute the compiler using the following command:

target/release/warp build path/to/scarb/project

About

License:Apache License 2.0


Languages

Language:Cairo 78.6%Language:Rust 21.4%