Skip to content

Commit

Permalink
update readme cairo1
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoGiachetta committed Dec 9, 2024
1 parent d2c056e commit 1aefc24
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cairo1-run/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Once you are inside the `./cairo1-run` folder, use the CLI with the following co
To install the required dependencies(cairo corelib) run

```bash
make deps
make deps
```

Now that you have the dependencies necessary to run the tests, you can run:
Expand All @@ -19,7 +19,7 @@ make test
To execute a Cairo 1 program (either as Cairo 1 source file or Sierra)

```bash
cargo run ../cairo_programs/cairo-1-programs/fibonacci.cairo
cargo run ../cairo_programs/cairo-1-programs/fibonacci.cairo
```

Arguments to generate the trace and memory files
Expand All @@ -44,7 +44,7 @@ cargo run ../cairo_programs/cairo-1-programs/with_input/array_input_sum.cairo --
To execute all the cairo 1 programs inside `../cairo_programs/cairo-1-programs/` and generate the corresponding trace and the memory files

```bash
make run
make run
```

## CLI argument list
Expand All @@ -71,6 +71,10 @@ The cairo1-run cli supports the following optional arguments:

* `--append_return_values`: Adds extra instructions to the program in order to append the return and input values to the output builtin's segment. This is the default behaviour for proof_mode. Only allows `Array<felt252>` as return and input value.

## Running circuits

Circuits in cairo 1 requiere the ´mod_builtin´ feature to be active in order for the ´AddMod´, ´MulMod´ and ´RangeCheck96´ builtins to be taken into account.

# Running scarb projects

As cairo1-run skips gas checks when running, you will need to add the following to your Scarb.toml to ensure that compilation is done without adding gas checks:
Expand All @@ -86,7 +90,7 @@ Then run the compiled project's sierra file located at `project_name/target/proj

Example:
```bash
cargo run path-to-project/target/project_name.sierra.json
cargo run path-to-project/target/project_name.sierra.json
```

# Known bugs & issues
Expand Down
37 changes: 37 additions & 0 deletions cairo1-run/program.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use core::circuit::{
RangeCheck96, AddMod, MulMod, u96, CircuitElement, CircuitInput, circuit_add,
circuit_sub, circuit_mul, circuit_inverse, EvalCircuitTrait, u384,
CircuitOutputsTrait, CircuitModulus, AddInputResultTrait, CircuitInputs,
};

fn main(
raw_inputs: Array<felt252>,
) {
let in1 = CircuitElement::<CircuitInput<0>> {};
let in2 = CircuitElement::<CircuitInput<1>> {};
let add = circuit_add(in1, in2);
let inv = circuit_inverse(add);
let sub = circuit_sub(inv, in2);
let mul = circuit_mul(inv, sub);

let modulus = TryInto::<_, CircuitModulus>::try_into([7, 0, 0, 0]).unwrap();
let outputs = (mul, add, inv)
.new_inputs()
.next([3, 0, 0, 0])
.next([6, 0, 0, 0])
.done()
.eval(modulus)
.unwrap();

assert!(outputs.get_output(add) == u384 { limb0: 2, limb1: 0, limb2: 0, limb3: 0 });
assert!(outputs.get_output(inv) == u384 { limb0: 4, limb1: 0, limb2: 0, limb3: 0 });
assert!(outputs.get_output(sub) == u384 { limb0: 5, limb1: 0, limb2: 0, limb3: 0 });
assert!(outputs.get_output(mul) == u384 { limb0: 6, limb1: 0, limb2: 0, limb3: 0 });

let inputs: Inputs = {
let mut inputs_ref = raw_inputs.span();
Serde::deserialize(ref inputs_ref).expect('bad program arguments')
};

// Do things
}
Binary file removed cairo1-run/trace
Binary file not shown.

0 comments on commit 1aefc24

Please sign in to comment.