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

CantWriteReturnFp error when using Gas and Poseidon builtins together #1870

Open
m-kus opened this issue Nov 6, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@m-kus
Copy link
Contributor

m-kus commented Nov 6, 2024

Describe the bug

I'm running a simple program (see listing below) using cairo1-run and get a runtime error Error: VirtualMachine(CantWriteReturnFp((Int(9999999999999), RelocatableValue(Relocatable { segment_index: 1, offset: 3 }))))

To Reproduce

  1. Copy minimal reproducible program (see below) to a file test.cairo
  2. Run cairo1-run test.cairo --layout all_cairo
  3. See error

Expected behavior

Runner should exit without errors.

What version/commit are you on?

e5c079c

Additional context

Minimal program

use core::poseidon::PoseidonTrait;
use core::hash::{HashStateTrait, HashStateExTrait};
use core::testing::get_available_gas;

fn main() {
    let a: u128 = get_available_gas();
    let b = PoseidonTrait::new().update_with(a).finalize();
    assert(b != 0, '');
}

The problem is likely in create_entry_code function, which produces the following:

ap += 1
[ap + -1] = [fp + -3]
call rel 4
[ap + 0] = [ap + -4], ap++
ret
@m-kus m-kus added the bug Something isn't working label Nov 6, 2024
@gabrielbosio
Copy link
Collaborator

gabrielbosio commented Nov 11, 2024

Hi! I'm debugging this issue. It seems that calling get_availiable_gas and HashState::update_with independently will cause the same error.

For example:

use core::poseidon::PoseidonTrait;
use core::hash::{HashStateTrait, HashStateExTrait};
use core::testing::get_available_gas;

fn main() {
    println!("{}", get_available_gas());
    println!("{:?}", PoseidonTrait::new().update_with(100));
}

Also fails with

Error: VirtualMachine(CantWriteReturnFp((Int(9999999999999), RelocatableValue(Relocatable { segment_index: 1, offset: 4 }))))

and

use core::poseidon::PoseidonTrait;
use core::hash::{HashStateTrait, HashStateExTrait};
use core::testing::get_available_gas;

fn main() {
    println!("{}", get_available_gas());
    println!("{:?}", PoseidonTrait::new());
}

Works without errors.

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

No branches or pull requests

2 participants