HerodotusDev / integrity

Apache License 2.0
61 stars 18 forks source link

Cairo 1 example? #128

Closed delaaxe closed 3 months ago

delaaxe commented 3 months ago

Is cairo 1 currently supported? If so can you show an example for verifying a proof obtained here?

https://github.com/starkware-libs/stone-prover/blob/main/README.md?plain=1#L72-L77 https://github.com/starkware-libs/stone-prover/blob/main/e2e_test/Cairo/fibonacci.cairo

Using small layout, error in verifier:

Currently trying to verify such proof panics with:

thread 'main' panicked at runner/src/main.rs:78:13:
[155785504329508738615720351733824384887]

Where 155785504329508738615720351733824384887 = u32_sub Overflow

Using recursive layout

thread 'main' panicked at runner/src/main.rs:78:13:
[97607197389754475647955493984074166371]

97607197389754475647955493984074166371 = Invalid final_pc

Verification command:

./integrity/target/release/runner integrity/target/dev/cairo_verifier.sierra.json < result/proof.json

Okm165 commented 3 months ago

@delaaxe Regarding proving recursive layout pls change the cpu_air_params.json and cpu_air_prover_config.json into following one:

{
    "cached_lde_config": {
        "store_full_lde": false,
        "use_fft_for_eval": false
    },
    "constraint_polynomial_task_size": 256,
    "n_out_of_memory_merkle_layers": 0,
    "table_prover_n_tasks_per_segment": 32
}
{
    "field": "PrimeField0",
    "channel_hash": "poseidon3",
    "commitment_hash": "keccak256_masked160_lsb",
    "n_verifier_friendly_commitment_layers": 9999,
    "pow_hash": "keccak256",
    "statement": {
        "page_hash": "pedersen"
    },
    "stark": {
        "fri": {
            "fri_step_list": [
                0,
                4,
                4,
                3
            ],
            "last_layer_degree_bound": 128,
            "n_queries": 10,
            "proof_of_work_bits": 30
        },
        "log_n_cosets": 2
    },

    "use_extension_field": false,
    "verifier_friendly_channel_updates": true,
    "verifier_friendly_commitment_hash": "poseidon3"
}

There is more detail regarding verification of cairo1-run generated trace The trace generated by cairo1-run has a different fingerprint ( changes in bytecode CASM instructions ) so in order to run it in integrity u need to do changes in public_input.verify() https://github.com/HerodotusDev/integrity/blob/a29acce9aa3b3f52c8fdabdcb7008dc5db364816/src/lib.cairo#L54 onchain

Doing it the cairo1-cairo0bootloader way is compatible coz it will have expected cairo0 CASM bytecode fingerprint.