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

bug: handle_main_return_value cannot return a ByteArray #6468

Open
enitrat opened this issue Oct 8, 2024 · 2 comments
Open

bug: handle_main_return_value cannot return a ByteArray #6468

enitrat opened this issue Oct 8, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@enitrat
Copy link
Contributor

enitrat commented Oct 8, 2024

Bug Report

Cairo version:
2.8.4

Current behavior:

/// Handling the main return value to create a `RunResultValue`.
pub fn handle_main_return_value(
inner_type_size: Option<i16>,
values: Vec<Felt252>,
cells: &[Option<Felt252>],
) -> RunResultValue {
if let Some(inner_type_size) = inner_type_size {
// The function includes a panic wrapper.
if values[0] == Felt252::from(0) {
// The run resulted successfully, returning the inner value.
let inner_ty_size = inner_type_size as usize;
let skip_size = values.len() - inner_ty_size;
RunResultValue::Success(values.into_iter().skip(skip_size).collect())
} else {
// The run resulted in a panic, returning the error data.
let err_data_start = values[values.len() - 2].to_usize().unwrap();
let err_data_end = values[values.len() - 1].to_usize().unwrap();
RunResultValue::Panic(
cells[err_data_start..err_data_end]
.iter()
.cloned()
.map(Option::unwrap)
.collect(),
)
}
} else {
// No panic wrap - so always successful.
RunResultValue::Success(values)
}
}

Where a println! would print: [1, 2, 3, 420], the returned values are [0x1e50, 0x1e50, 0x225b312c20322c20332c203432305d22, 0x10]

It seems that bytearrays, and in general, any pointer-based struct, cannot be returned.

Expected behavior:
This should return the serialized bytearray representation for the above, which would be [0, 0x225b312c20322c20332c203432305d22, 0x10]

@enitrat enitrat added the bug Something isn't working label Oct 8, 2024
@orizi
Copy link
Collaborator

orizi commented Oct 9, 2024

what are you trying to use it for?
note that this is a structure for only for debug and test runs for the time being - not for actual provable calculation.

@enitrat
Copy link
Contributor Author

enitrat commented Oct 9, 2024

A custom test runner. I use cairo-run to output JSON representations of my types as bytearrays. The goal is to use this test runner for property testing / diff testing

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