Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FailedToComputeOperands error when running cairo1-run #1852

Closed
m-kus opened this issue Oct 14, 2024 · 1 comment · Fixed by #1864
Closed

FailedToComputeOperands error when running cairo1-run #1852

m-kus opened this issue Oct 14, 2024 · 1 comment · Fixed by #1864
Labels
bug Something isn't working

Comments

@m-kus
Copy link
Contributor

m-kus commented Oct 14, 2024

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?
3fb0344

Additional context
lib.cairo.txt

UPD
Minimal reproducible program (by @maciejka)

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 159f67d 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

@m-kus m-kus added the bug Something isn't working label Oct 14, 2024
@m-kus
Copy link
Contributor Author

m-kus commented Oct 30, 2024

Entry code generated by cairo1-run vs cairo-lang-runner:

+ ap += 0
call rel 3
ret

Program instructions match (aside from the entry):

+ 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

[
+ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant