keep-starknet-strange / garaga

State-of-the-art Elliptic Curve operations and SNARKS verification for Cairo & Starknet 🐺.
https://felt.gitbook.io/garaga
MIT License
188 stars 47 forks source link

dev: RiscZero contract should take journal instead of journal Digest as input #209

Open feltroidprime opened 6 days ago

feltroidprime commented 6 days ago

Change the struct in src/src/utils/calldata.cairo

from

#[derive(Serde, Drop)]
struct FullProofWithHintsRisc0 {
    groth16_proof: Groth16ProofRaw,
    image_id: Span<u32>,
    journal_digest: Span<u32>,
    mpcheck_hint: MPCheckHintBN254,
    small_Q: E12DMulQuotient<u288>,
    msm_hint: Array<felt252>,
}

to

#[derive(Serde, Drop)]
struct FullProofWithHintsRisc0 {
    groth16_proof: Groth16ProofRaw,
    image_id: Span<u32>,
    journal: Span<u8>,
    mpcheck_hint: MPCheckHintBN254,
    small_Q: E12DMulQuotient<u288>,
    msm_hint: Array<felt252>,
}

In particular : https://github.com/keep-starknet-strange/garaga/blob/fa27403e6aa2c968a369c6da6ddfbd8da36a42f3/hydra/garaga/starknet/groth16_contract_generator/parsing_utils.py#L446-L448

This should serialize the journal instead of the journal digest.

This should generate a contract compatible with the new struct above.

In particular :

https://github.com/keep-starknet-strange/garaga/blob/fa27403e6aa2c968a369c6da6ddfbd8da36a42f3/hydra/garaga/starknet/groth16_contract_generator/generator_risc0.py#L96

At this point the journal digest should be computed from journal using the sha256 syscall.

See https://github.com/starkware-libs/cairo/blob/main/corelib/src/sha256.cairo or https://github.com/keep-starknet-strange/garaga/blob/main/src/src/utils/risc0.cairo for examples of using the syscall.

(advice: work inside the real contract first then update the python template instead of the opposite)

In particular :

https://github.com/keep-starknet-strange/garaga/blob/fa27403e6aa2c968a369c6da6ddfbd8da36a42f3/src/src/utils/calldata.cairo#L120-L125

This should be updated with the changes in the python code above.

Slightly related : #207

stefanMadzharov commented 4 days ago

I will take it