starkware-libs / cairo

Cairo is the first Turing-complete language for creating provable programs for general computation.
Apache License 2.0
1.47k stars 450 forks source link

bug: Sierra to CASM crashes on gas handling in Cairo 2.1.0 #3882

Closed mkaput closed 5 months ago

mkaput commented 11 months ago

Bug Report

Cairo version: 2.1.0 Scarb version: 0.6.0

Current behavior:

scarb build fails in this particular revision of this particular repository: https://github.com/Astraly-Labs/pragma-oracle/tree/b958cbcbaed547d904c7a2e7b1eb547f65f04c5e

With:

➜  pragma-oracle git:(main) ✗ RUST_BACKTRACE=1 scarb build
    Updating git repository https://github.com/keep-starknet-strange/alexandria
    Updating git repository https://github.com/influenceth/cubit
   Compiling lib(pragma) pragma v0.1.0 (/Users/mk/Developer/Temp/pragma-oracle/Scarb.toml)
thread 'main' panicked at 'Difference in (StatementIdx(13044), Pedersen): Some(19) != Some(0)', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cairo-lang-sierra-gas-2.1.0/src/gas_info.rs:61:13
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: cairo_lang_sierra_to_casm::metadata::calc_metadata
   3: <scarb::compiler::compilers::lib::LibCompiler as scarb::compiler::Compiler>::compile
   4: scarb::ops::compile::compile
   5: scarb::commands::run
   6: scarb::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

This is compiling non-Starknet Sierra to CASM. Removing [lib] casm=true from Scarb.toml stops this error to be triggered.

Expected behavior:

This code should successfully compile to CASM. Especially, as it's properly compiling as Starknet contract.

Steps to reproduce:

  1. asdf install scarb 0.6.0
  2. clone this commit https://github.com/Astraly-Labs/pragma-oracle/tree/b958cbcbaed547d904c7a2e7b1eb547f65f04c5e
  3. scarb build

I was unable to reproduce this using sierra-compile CLI, because textual Sierra generated for this code is unparseable 😢

➜  cairo git:(main) target/release/sierra-compile ~/Developer/Temp/pragma-oracle/target/dev/pragma.sierra foo.casm
Error: Failed calculating Sierra variables.

Caused by:
    0: error from the program registry
    1: used the same function id twice

Other information:

orizi commented 7 months ago

Does this still not work? It seems like it was something old.

mkaput commented 7 months ago

@EvolveArt can you confirm please?

orizi commented 5 months ago

I believe it is fixed - and it is stale for a long time. Closing.