cairo_native: bug: regressions introduced by latest main

main (commit hash to confirm again) introduced a few regressions.

clone https://github.com/kkrt-labs/ef-tests ensure correct branch git checkout dev/bump-native make make setup-kakarot cargo test --test tests stStack --no-fail-fast --features "v1,native,ci" -- --nocapture ^ this will run the full suite for the stStack family. The first issue is also reproducible when running a specific test, with e.g. cargo test test_sar_2_xor_255_256_d0g0v0_Cancun --features v1,native -- --nocapture

  1. Execution regressions

The execution is no longer the same. What used to pass, now fails with:

 WARN ef_testing::models::result: stStackTests::shallowStack_d10g0v0_Cancun reverted:
Transaction execution has failed:
0: Error in the called contract (contract address: 0x0000000000000000000000000000000000000000000000000000000000000003, class hash: 0x06153ccf69fd20f832c794df36e19135f0070d0576144f0b47f75a226e4be530, selector: 0x015d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad):
Error at pc=0:25:
Cairo traceback (most recent call last):
Unknown location (pc=0:731)
Unknown location (pc=0:677)
Unknown location (pc=0:291)
Unknown location (pc=0:314)

1: Error in the called contract (contract address: 0x04c15a3ff2822ca5b75a67a2ff0226b8b18a94c1c7d396b0073269c5b074d14f, class hash: 0x05b953b2f2ed1e6a4943dc934cc8a5fb12de801745a40857f4459bb375c0f04c, selector: 0x007ec457cd7ed1630225a8328f826a29a327b19486f6b2882b4176545ebdbe3d):
Native execution error: EOA: could not decode tx

thread 'stStackTests::stStackTests::test_shallowStack_d10g0v0_Cancun' panicked at crates/ef-testing/tests/stStackTests.rs:1379:24:
Error while running the test: Other(
gas used mismatch: expected 300000, got 0
nonce mismatch for 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b: expected                              0x1, got                              0x0
revert reason:
)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test stStackTests::stStackTests::test_shallowStack_d10g0v0_Cancun ... FAILED

^ This happens for practically all tests and highlights a difference somewhere during execution. Probably added by one of the latest commits un the last PR

 WARN ef_testing::models::result: stStackTests::shallowStack_d53g0v0_Cancun reverted:
Transaction execution has failed:
0: Error in the called contract (contract address: 0x0000000000000000000000000000000000000000000000000000000000000003, class hash: 0x06153ccf69fd20f832c794df36e19135f0070d0576144f0b47f75a226e4be530, selector: 0x015d40a3d6ca2ac30f4031e42be28da9b056fef9bb7357ac5e85627ee876e5ad):
Error at pc=0:25:
Cairo traceback (most recent call last):
Unknown location (pc=0:731)
Unknown location (pc=0:677)
Unknown location (pc=0:291)
Unknown location (pc=0:314)

1: Error in the called contract (contract address: 0x04c15a3ff2822ca5b75a67a2ff0226b8b18a94c1c7d396b0073269c5b074d14f, class hash: 0x05b953b2f2ed1e6a4943dc934cc8a5fb12de801745a40857f4459bb375c0f04c, selector: 0x007ec457cd7ed1630225a8328f826a29a327b19486f6b2882b4176545ebdbe3d):
Native execution error: Native execution error: Invalid chain id

thread 'stStackTests::stStackTests::test_shallowStack_d54g0v0_Cancun' panicked at crates/ef-testing/tests/stStackTests.rs:1955:24:
Error while running the test: Other(
gas used mismatch: expected 300000, got 0
nonce mismatch for 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b: expected                              0x1, got                              0x0
revert reason:
)
test stStackTests::stStackTests::test_shallowStack_d54g0v0_Cancun ... FAILED
  1. a weird SIGRAP issue that terminates the execution:
// ... logs above
error: test failed, to rerun pass `-p ef-testing --test tests`

Caused by:
  process didn't exit successfully: `/Users/msaug/kkrt-labs/ef-tests/target/debug/deps/tests-48dbd4207bfa156f stStack --nocapture` (signal: 5, SIGTRAP: trace/breakpoint trap)

^ This happens when running multiple tests at one - but i don’t know exactly which one triggers this

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 44

Most upvoted comments

ah, ok i will probably wait for it to be on main as i’m focused mainly on something else atm

I just hit an issue when running locally:

* thread #6, name = 'stStaticCall::test_static_ABAcalls0_d1g0v0_Cancun', stop reason = EXC_BAD_ACCESS (code=2, address=0x170633e80)
    frame #0: 0x000000017280212c 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::instructions::memory_operations::MemoryOperation::exec_pc(f179) + 18816
504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::instructions::memory_operations::MemoryOperation::exec_pc(f179):
->  0x17280212c <+18816>: str    x22, [x19, #0x20]
    0x172802130 <+18820>: ldr    x22, [sp, #0x1108]
    0x172802134 <+18824>: str    x22, [x19, #0x10]
    0x172802138 <+18828>: ldr    w22, [sp, #0x338]
(lldb) bt
* thread #6, name = 'stStaticCall::test_static_ABAcalls0_d1g0v0_Cancun', stop reason = EXC_BAD_ACCESS (code=2, address=0x170633e80)
  * frame #0: 0x000000017280212c 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::instructions::memory_operations::MemoryOperation::exec_pc(f179) + 18816
    frame #1: 0x000000017248f9c8 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::execute_opcode(f135) + 381252
    frame #2: 0x00000001723ec248 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::execute_code(f107) + 9600
    frame #3: 0x00000001723949a4 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::process_message(f78) + 24288
    frame #4: 0x0000000172ae167c 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::call_helpers::CallHelpersImpl::generic_call(f255) + 47004
    frame #5: 0x00000001726d5b90 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::instructions::system_operations::SystemOperations::exec_staticcall(f148) + 103480
    frame #6: 0x00000001725bb4f8 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::execute_opcode(f135) + 1608820
    frame #7: 0x00000001723ec248 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::execute_code(f107) + 9600
    frame #8: 0x00000001723949a4 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::process_message(f78) + 24288
    frame #9: 0x0000000172ae167c 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::call_helpers::CallHelpersImpl::generic_call(f255) + 47004
    frame #10: 0x00000001726d5b90 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::instructions::system_operations::SystemOperations::exec_staticcall(f148) + 103480
    frame #11: 0x00000001725bb4f8 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::execute_opcode(f135) + 1608820
    frame #12: 0x00000001723ec248 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::execute_code(f107) + 9600
    frame #13: 0x00000001723949a4 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::process_message(f78) + 24288
    frame #14: 0x0000000172ae167c 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::call_helpers::CallHelpersImpl::generic_call(f255) + 47004
    frame #15: 0x0000000172787ca8 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::instructions::system_operations::SystemOperations::exec_call(f154) + 139700
    frame #16: 0x000000017259f078 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::execute_opcode(f135) + 1492980
    frame #17: 0x00000001723ec248 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::execute_code(f107) + 9600
    frame #18: 0x00000001723949a4 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::process_message(f78) + 24288
    frame #19: 0x0000000172345fc0 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::process_message_call(f62) + 5284
    frame #20: 0x00000001722fa60c 504898746202199744673968940527932241844513528453156538068464172101734859290`impl$evm::interpreter::EVMImpl::process_transaction(f48) + 72040
    frame #21: 0x00000001722c18e0 504898746202199744673968940527932241844513528453156538068464172101734859290`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(f39) + 15028
    frame #22: 0x0000000172290f5c 504898746202199744673968940527932241844513528453156538068464172101734859290`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) + 4148
    frame #23: 0x00000001722921b0 504898746202199744673968940527932241844513528453156538068464172101734859290`_mlir_ciface_f23 + 84
    frame #24: 0x00000001007f2d94 stStaticCall-b270e27c5493ce0a`invoke_trampoline + 108
    frame #25: 0x00000001004c7d94 stStaticCall-b270e27c5493ce0a`blockifier::execution::native::utils::run_native_executor::hbc529b733575cb07(native_executor=0x00006000021cc010, function_id=0x0000000117015b00, call=<unavailable>, syscall_handler=<unavailable>) at utils.rs:45:28

will add instructions to repro from scratch (if I manage to)

Memory usage looks a lot better - perhaps a few persisting issues?:

image

I am starting a run on CI and will report back in ~1hr

I think everything’s fine now (secp256 point is on the blockifier side)

image looks good now !

Wait, don’t upgrade yet. I know for a fact we still have some memory leaks.

I’m working on a piece of code that’ll help me find them. I’ll let you know once I’ve fixed the ones I’ve found.

so, I confirm that the regression was actually added on c866fbf8417cfcf522fd809348a483c5daef2e45. Things work fine when using ae17dd370a7bbf6affeefb9fa6954965e8b52239 commit.

edit: mistake on my end, it comes with https://github.com/lambdaclass/cairo_native/commit/79a8dcffe1e562e80198425e7c9f3a328c783947

Is the write-after-free issue no longer reproducible?

So far (on https://github.com/lambdaclass/cairo_native/commit/79a8dcffe1e562e80198425e7c9f3a328c783947) I haven’t been able to repro. I’m not sure what conditions lead to it happening; perhaps because of parallel threads during test execution