diff --git a/cairo1-run/README.md b/cairo1-run/README.md index 9271d860bb..61c60193d5 100644 --- a/cairo1-run/README.md +++ b/cairo1-run/README.md @@ -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: @@ -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 @@ -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 @@ -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` 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: @@ -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 diff --git a/cairo1-run/program.cairo b/cairo1-run/program.cairo new file mode 100644 index 0000000000..139c8d039e --- /dev/null +++ b/cairo1-run/program.cairo @@ -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, +) { + let in1 = CircuitElement::> {}; + let in2 = CircuitElement::> {}; + 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 +} diff --git a/cairo1-run/trace b/cairo1-run/trace deleted file mode 100644 index 338056a5a3..0000000000 Binary files a/cairo1-run/trace and /dev/null differ