Repository: lambdaclass/cairo-vm (language: rust)

Issue:
FailedToComputeOperands error when running cairo1-run
**Describe the bug**

I get `Error: VirtualMachine(FailedToComputeOperands(("op1", Relocatable { segment_index: 0, offset: 5271 })))` when executing a Cairo1 program using `cairo1-run`.

**To Reproduce**
Steps to reproduce the behavior:

1. Download attached lib.cairo file
2. Link corelib (e.g. `ln -s  $HOME/Library/Caches/com.swmansion.scarb/registry/std/v2.8.2/core corelib`)
3. Run `cairo1-run lib.cairo --layout recursive --args '[8 0 0 0 0 0 0 0 0 1718123181 4167220599 1821360523 2392821280 144118917 1860318131 2418694429 224340261]'`
4. See error

**Expected behavior**
The program should exit without errors (observed behavior with cairo-lang-runner)

**What version/commit are you on?**
3fb0344ce038b3a68cae897c403d1f561cfe8da7

**Additional context**
[lib.cairo.txt](https://github.com/user-attachments/files/17369386/lib.cairo.txt)

**UPD**
Minimal reproducible program (by @maciejka)
```cairo
fn main() {
    let h: [u32; 1] = [1];
    let mut s = h.span();
    assert(s.pop_front().is_some(), '');
}
```

Error: 
```
Error: VirtualMachine(FailedToComputeOperands(("op1", Relocatable { segment_index: 0, offset: 47 })))
```

On the most recent commit 159f67da19964cc54a95423a69470a26e534a13d I got another error:
```
thread 'main' panicked at cairo-lang-lowering-2.9.0-dev.0/src/optimizations/const_folding.rs:555:13:
`bounded_int_is_zero` not found in `core::internal::bounded_int`.
```

**UPD2**
That was mismatched `corelib` version, should be `2.9.0`


Discussion / hints:
Entry code generated by `cairo1-run` vs `cairo-lang-runner`:

```diff
+ ap += 0
call rel 3
ret
```

Program instructions match (aside from the entry):
```diff
+ ap += 0
call rel 3
ret
call rel 43
[ap + 0] = [ap + -1] + 42, ap++
[ap + 0] = [ap + -1], ap++
[ap + 0] = [ap + -2] + 1, ap++
[ap + -1] = [ap + 0] + [ap + -2], ap++
jmp rel 4 if [ap + -1] != 0
jmp rel 7
[ap + 0] = 0, ap++
[ap + 0] = [[ap + -4] + 0], ap++
jmp rel 6
[ap + 0] = 1, ap++
[ap + 0] = 0, ap++
jmp rel 11 if [ap + -2] != 0
ap += 2
[ap + 0] = 0, ap++
[ap + 0] = 0, ap++
[ap + 0] = 0, ap++
ret
%{ memory[ap + 0] = segments.add() %}
ap += 1
[ap + 0] = 0, ap++
[ap + -1] = [[ap + -2] + 0]
[ap + 0] = 1, ap++
[ap + 0] = [ap + -3], ap++
[ap + 0] = [ap + -4] + 1, ap++
ret
ret

```


However assemblies differ a bit (seems to be a missing ret):

`cairo1-run` vs `cairo-lang-runner`
```diff
[
+ 290341444919459839, 0, 
1226245742482522112, 3, 
2345108766317314046, 
1226245742482522112, 43, 
5198420613823168512, 42,
5193354055652442112, 
5198420613823102976, 1, 
5201798300658860031, 
145944781866893311, 4, 
74168662805676031, 7, 
5189976364521848832, 0, 
5188287510366420992, 
74168662805676031, 6, 
5189976364521848832, 1, 
5189976364521848832, 0, 
145944781866893310, 11, 
290341444919459839, 2, 
5189976364521848832, 0,
5189976364521848832, 0, 
5189976364521848832, 0, 
2345108766317314046, 
290341444919459839, 1, 
5189976364521848832, 0, 
4611826758063128575, 
5189976364521848832, 1, 
5193354047062507520, 
5198420613822971904, 1, 
2345108766317314046, 
+ 2345108766317314046, 1, 
2345108766317314046
]
```

The missing felts seem to be the problem: if I add them manually to the assembly everything works fine. It looks to be related to the constant segments.

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 806d9da4d6..9c3abb2a6a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,9 @@
 
 #### [2.0.0-rc0] - 2024-10-22
 
+* fix: [#1864](https://github.com/lambdaclass/cairo-vm/pull/1864):
+    * Runner: include data from constants segment to the bytecode when assembling program
+
 * chore: bump `cairo-lang-` dependencies to 2.9.0-dev.0 [#1858](https://github.com/lambdaclass/cairo-vm/pull/1858/files)
 
 * chore: update Rust required version to 1.81.0 [#1857](https://github.com/lambdaclass/cairo-vm/pull/1857)
diff --git a/cairo1-run/src/cairo_run.rs b/cairo1-run/src/cairo_run.rs
index f22a6edd9a..8a293c680e 100644
--- a/cairo1-run/src/cairo_run.rs
+++ b/cairo1-run/src/cairo_run.rs
@@ -204,10 +204,14 @@ pub fn cairo_run_program(
         cairo_run_config.copy_to_output(),
     );
 
-    let data: Vec<MaybeRelocatable> = instructions
-        .flat_map(|inst| inst.assemble().encode())
-        .map(|x| Felt252::from(&x))
-        .map(MaybeRelocatable::from)
+    // The bytecode includes all program instructions plus entry/footer,
+    // plus data from the constants segments.
+    let data: Vec<MaybeRelocatable> = casm_program
+        .assemble_ex(&entry_code.instructions, &libfunc_footer)
+        .bytecode
+        .into_iter()
+        .map(Into::<Felt252>::into)
+        .map(Into::<MaybeRelocatable>::into)
         .collect();
 
     let program = if cairo_run_config.proof_mode {


Test patch: