cairo_native: bug: error in `secp256k1_add` when adding point at infinity

thread 'stPreCompiledContracts2::test_CallEcrecover_Overflow_d4g0v0_Cancun' panicked at /Users/msaug/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ark-ec-0.4.2/src/models/short_weierstrass/affine.rs:77:9:
assertion failed: point.is_on_curve()

thread 'stPreCompiledContracts2::test_CallEcrecover_Overflow_d4g0v0_Cancun' panicked at library/core/src/panicking.rs:221:5:
panic in a function that cannot unwind
stack backtrace:
   0:        0x10e82e74c - std::backtrace_rs::backtrace::libunwind::trace::hbebc8679d47bdc2c
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:        0x10e82e74c - std::backtrace_rs::backtrace::trace_unsynchronized::h3a2e9637943241aa
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x10e82e74c - std::sys::backtrace::_print_fmt::he430849680584674
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:65:5
   3:        0x10e82e74c - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h243268f17d714c7f
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:40:26
   4:        0x10e84b5ec - core::fmt::rt::Argument::fmt::h0d339881c25f3c31
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/fmt/rt.rs:173:76
   5:        0x10e84b5ec - core::fmt::write::hb3cfb8a30e72d7ff
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/fmt/mod.rs:1182:21
   6:        0x10e82b9e4 - std::io::Write::write_fmt::hfb2314975de9ecf1
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/io/mod.rs:1827:15
   7:        0x10e82fc74 - std::sys::backtrace::BacktraceLock::print::he14461129ccbfef5
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:43:9
   8:        0x10e82fc74 - std::panicking::default_hook::{{closure}}::h14c7718ccf39d316
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:269:22
   9:        0x10e82f898 - std::panicking::default_hook::hc62e60da3be2f352
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:296:9
  10:        0x10e830738 - std::panicking::rust_panic_with_hook::h09e8a656f11e82b2
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:800:13
  11:        0x10e830060 - std::panicking::begin_panic_handler::{{closure}}::h1230eb3cc91b241c
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:667:13
  12:        0x10e82ebd8 - std::sys::backtrace::__rust_end_short_backtrace::hc3491307aceda2c2
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/sys/backtrace.rs:168:18
  13:        0x10e82fd50 - rust_begin_unwind
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
  14:        0x10ece17ac - core::panicking::panic_nounwind_fmt::runtime::h5290ab2b4897aadc
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:112:18
  15:        0x10ece17ac - core::panicking::panic_nounwind_fmt::h91ee161184879b56
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:122:5
  16:        0x10ece1824 - core::panicking::panic_nounwind::heab7ebe7a6cd845c
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:221:5
  17:        0x10ece1954 - core::panicking::panic_cannot_unwind::hedc43d82620205bf
                               at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/panicking.rs:309:5
  18:        0x104943108 - cairo_native::starknet::handler::StarknetSyscallHandlerCallbacks<T>::wrap_secp256k1_add::hc2142a54f1359a37
                               at /Users/msaug/.cargo/git/checkouts/cairo_native-0bad8506281b7281/f3f6ba2/src/starknet.rs:1476:9
  19:        0x12f7eeebc - _impl$core::starknet::secp256_trait::recover_public_key::<core::starknet::secp256k1::Secp256k1Point, core::starknet::secp256k1::Secp256k1PointDrop, core::starknet::secp256k1::Secp256k1Impl, core::starknet::secp256k1::Secp256k1PointImpl>(f276)
  20:        0x12f7be184 - _impl$evm::precompiles::ec_recover::EcRecover::exec(f240)
  21:        0x12f3eaa04 - _impl$evm::precompiles::PrecompilesImpl::exec_precompile(f134)
  22:        0x12f216f90 - _impl$evm::interpreter::EVMImpl::execute_code(f109)
  23:        0x12f1def10 - _impl$evm::interpreter::EVMImpl::process_message(f79)
  24:        0x12f7d344c - _impl$evm::call_helpers::CallHelpersImpl::generic_call(f254)
  25:        0x12f4d3314 - _impl$evm::instructions::system_operations::SystemOperations::exec_call(f152)
  26:        0x12f346610 - _impl$evm::interpreter::EVMImpl::execute_opcode(f133)
  27:        0x12f210978 - _impl$evm::interpreter::EVMImpl::execute_code(f109)
  28:        0x12f1def10 - _impl$evm::interpreter::EVMImpl::process_message(f79)
  29:        0x12f1babfc - _impl$evm::interpreter::EVMImpl::process_message_call(f61)
  30:        0x12f1a1288 - _impl$evm::interpreter::EVMImpl::process_transaction(f47)
  31:        0x12f18ba04 - _impl$contracts::kakarot_core::eth_rpc::EthRPC::<contracts::kakarot_core::kakarot::KakarotCore::ContractState, contracts::kakarot_core::kakarot::KakarotCore::_KakarotCoreState, contracts::kakarot_core::kakarot::KakarotCore::ContractStateDrop>::eth_send_transaction(f38)
  32:        0x12f180b5c - _impl$contracts::kakarot_core::eth_rpc::__wrapper__EthRPC__eth_send_transaction::<contracts::kakarot_core::kakarot::KakarotCore::ContractState, contracts::kakarot_core::kakarot::KakarotCore::_KakarotCoreState, contracts::kakarot_core::kakarot::KakarotCore::ContractStateDrop, contracts::kakarot_core::kakarot::KakarotCore::ContractStateEthRPC>(f23)
  33:        0x12f181388 - __mlir_ciface_f23
thread caused non-unwinding panic. aborting.

Repro: scarb 2.8.3 clone https://github.com/kkrt-labs/kakarot-ssj on main scarb build -p contracts - builds the required contract with some debug print logs

clone https://github.com/kkrt-labs/ef-tests ensure correct branch git checkout feat/cairo-native make make setup-kakarot copy the contracts built previously:cp ../kakarot-ssj/target/dev/contracts_* build/v1 cargo test test_CallEcrecover_Overflow_d0g0v0_Cancun --features v1,native -- --nocapture

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (1 by maintainers)

Most upvoted comments

@xrvdg yes, here’s the relevant code: https://github.com/starkware-libs/cairo/blob/main/corelib/src/starknet/secp256_trait.cairo#L93-L124

Here, because we give s = N we have let u2 = u256_mul_mod_n(s, r_inv, n_nz); = 0, thus: let point2 = r_point.mul(u2).unwrap_syscall() = r_point * 0 = identity

and in secp256k1_add, we pass these two secp256k1 points, one of them being the point at infinity

the add function is defined here: https://github.com/kkrt-labs/sequencer/blob/7c8bd351ecf0c0375d7030466500523a9a924273/crates/blockifier/src/execution/native/syscall_handler.rs#L931-L938

when executing let rhs: Affine<Curve> = p1.into(); we are using the From implementation here: https://github.com/kkrt-labs/sequencer/blob/7c8bd351ecf0c0375d7030466500523a9a924273/crates/blockifier/src/execution/native/syscall_handler.rs#L1034-L1044

this from implementation calls new: https://github.com/nethermindeth/sequencer/blob/native2.8.x/crates/blockifier/src/execution/native/syscall_handler.rs#L1034-L1041

Which fails because x,y = 0 => identity point is not on the curve