starkware-libs / cairo-lang

Apache License 2.0
1.35k stars 264 forks source link

Assertion Failure in `cairo_verifier` When Verifying `stone-prover` zkSTARK Proofs #180

Closed Okm165 closed 10 months ago

Okm165 commented 11 months ago

Description:

Issue Summary:

I'm experiencing issues with running the cairo_verifier in the cairo-lang repository, version v0.12.3, using Python 3.9.0, specifically when verifying proofs generated by the stone-prover. Although the stone-prover generates zkSTARK proofs successfully, the cairo_verifier fails to verify these proofs, resulting in an error.

Steps to Reproduce:

  1. Generate a zkSTARK proof using the stone-prover from this repository, following the provided README instructions.
  2. Set up the cairo_verifier environment by cloning the cairo-lang repository from this branch, which includes a manually fixed bazel build as described in this related issue.
  3. Compile cairo_verifier with the following command:
    cairo-compile --cairo_path=./src src/starkware/cairo/cairo_verifier/layouts/starknet_with_keccak/cairo_verifier.cairo --output cairo_verifier.json

    This step takes about 8 minutes and 10GiB of RAM, resulting in a 12GiB cairo_verifier.json file.

  4. Run cairo_verifier using:
    cairo-run \
      --program=cairo_verifier.json \
      --layout=starknet_with_keccak \
      --program_input=cairo_verifier_input-stone.json \
      --trace_file=cairo_verifier_trace.json \
      --memory_file=cairo_verifier_memory.json \
      --print_output

    This step takes about 18 minutes requires about 96GiB of RAM.

Expected Result:

The cairo_verifier should successfully verify the zkSTARK proof generated by stone-prover without any errors.

Actual Result:

The verification process fails with an assertion error in the verify_oods function within stark.cairo. The specific error message is:

/home/bartosz/workshop/herodotusdev/cairo-lang-v0.13/src/starkware/cairo/stark_verifier/core/stark.cairo:322:5: Error at pc=0:31534:
An ASSERT_EQ instruction failed: 2418258407644728539863773216315436708774059961165242426841968140264143419574 != 3469875586945248988307846395884043418606990072452279991114910527692266491651.
Cairo traceback (most recent call last):
src/starkware/cairo/cairo_verifier/layouts/starknet_with_keccak/cairo_verifier.cairo:199:39: (pc=0:31899)
    let (program_hash, output_hash) = verify_cairo_proof(proof);
                                      ^***********************^
src/starkware/cairo/cairo_verifier/layouts/starknet_with_keccak/cairo_verifier.cairo:51:5: (pc=0:31706)
    verify_proof(proof=proof, security_bits=SECURITY_BITS);
    ^****************************************************^
/home/bartosz/workshop/herodotusdev/cairo-lang-v0.13/src/starkware/cairo/stark_verifier/air/layouts/starknet_with_keccak/verify.cairo:77:12: (pc=0:31675)
/home/bartosz/workshop/herodotusdev/cairo-lang-v0.13/src/starkware/cairo/stark_verifier/core/stark.cairo:172:34: (pc=0:31291)
/home/bartosz/workshop/herodotusdev/cairo-lang-v0.13/src/starkware/cairo/stark_verifier/core/stark.cairo:257:5: (pc=0:31433)

Additional Information:

Questions:

Okm165 commented 10 months ago

I created repository that has this issue solved https://github.com/Okm165/stone-prover-cairo0-verifier