starkware-libs / cairo

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

bug: `Missing path::to::function[expr60]` #6264

Closed enitrat closed 2 weeks ago

enitrat commented 2 weeks ago

Bug Report

Cairo version: 2.7.1

I mistakenly imported a trait from the parent module, without this trait existing in the parent module. The following error followed when trying to compile:

stack trace:

❯ RUST_BACKTRACE=1 scarb build -p contracts
   Compiling lib(contracts) contracts v0.1.0 (/Users/msaug/kkrt-labs/kakarot-ssj/crates/contracts/Scarb.toml)
thread 'main' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cairo-lang-sierra-generator-2.7.1/src/utils.rs:331:13:
Missing function evm::backend::starknet_backend::internals::commit_accounts[expr60]
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: cairo_lang_sierra_generator::utils::get_libfunc_signature
   3: cairo_lang_sierra_generator::local_variables::FindLocalsContext::analyze_call
   4: cairo_lang_lowering::borrow_check::analysis::BackAnalysis<TAnalyzer>::get_root_info
   5: cairo_lang_sierra_generator::function_generator::priv_function_with_body_sierra_data
   6: salsa::derived::slot::Slot<Q,MP>::read_upgrade
   7: <DB as cairo_lang_sierra_generator::db::SierraGenGroup>::priv_function_with_body_sierra_data::__shim
   8: salsa::derived::slot::Slot<Q,MP>::read_upgrade
   9: <DB as cairo_lang_sierra_generator::db::SierraGenGroup>::function_with_body_sierra::__shim
  10: cairo_lang_sierra_generator::program_generator::get_sierra_program_for_functions
  11: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  12: <DB as cairo_lang_sierra_generator::db::SierraGenGroup>::get_sierra_program_for_functions::__shim
  13: salsa::derived::slot::Slot<Q,MP>::read_upgrade
  14: <DB as cairo_lang_sierra_generator::db::SierraGenGroup>::get_sierra_program::__shim
  15: <scarb::compiler::compilers::lib::LibCompiler as scarb::compiler::Compiler>::compile
  16: scarb::ops::compile::compile_unit
  17: scarb::ops::compile::process
  18: scarb::ops::compile::compile
  19: scarb::commands::run
  20: scarb::main

Related code:

https://github.com/kkrt-labs/kakarot-ssj/blob/bug-repro/crates/evm/src/backend/starknet_backend.cairo#L127-L161

wrongly importing use super::{State, StateTrait, deploy, StateChangeLogTrait}; when StateChangeLogTrait is not defined in the parent module and using it with

              let account = StateChangeLogTrait::<
                Account
            >::read(state.accounts, (*evm_address).into());

triggered the error

orizi commented 2 weeks ago

The issue is that a dependency doesn't compile.

we need to make sure that scarb gives an error on failing dependencies when doing scarb build. (in your case for example scarb test works)

maciektr commented 2 weeks ago

Fixed on Scarb main (as demonstrated with https://github.com/maciektr/cairo-test-run/actions/runs/10563264433/job/29263096711)