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

fix: cairo1-run array argument's length can not be less than 2 #1737

Merged
merged 9 commits into from
May 9, 2024
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* fix: add support for arrays shorter than 2 as arguments for cairo1-run [#1737](https://github.com/lambdaclass/cairo-vm/pull/1737)

* Serialize directly into writer in `CairoPie::write_zip_file`[#1736](https://github.com/lambdaclass/cairo-vm/pull/1736)

* feat: Add support for cairo1 run with segements arena validation.
Expand Down
42 changes: 27 additions & 15 deletions cairo1-run/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,36 @@ fn process_args(value: &str) -> Result<FuncArgs, String> {
while let Some(value) = input.next() {
// First argument in an array
if value.starts_with('[') {
let mut array_arg =
vec![Felt252::from_dec_str(value.strip_prefix('[').unwrap()).unwrap()];
// Process following args in array
let mut array_end = false;
while !array_end {
if let Some(value) = input.next() {
// Last arg in array
if value.ends_with(']') {
array_arg
.push(Felt252::from_dec_str(value.strip_suffix(']').unwrap()).unwrap());
array_end = true;
} else {
array_arg.push(Felt252::from_dec_str(value).unwrap())
if value.ends_with(']') {
if value.len() == 2 {
args.push(FuncArg::Array(Vec::new()));
} else {
args.push(FuncArg::Array(vec![Felt252::from_dec_str(
value.strip_prefix('[').unwrap().strip_suffix(']').unwrap(),
)
.unwrap()]));
}
} else {
let mut array_arg =
vec![Felt252::from_dec_str(value.strip_prefix('[').unwrap()).unwrap()];
// Process following args in array
let mut array_end = false;
while !array_end {
if let Some(value) = input.next() {
// Last arg in array
if value.ends_with(']') {
array_arg.push(
Felt252::from_dec_str(value.strip_suffix(']').unwrap()).unwrap(),
);
array_end = true;
} else {
array_arg.push(Felt252::from_dec_str(value).unwrap())
}
}
}
// Finalize array
args.push(FuncArg::Array(array_arg))
}
// Finalize array
args.push(FuncArg::Array(array_arg))
} else {
// Single argument
args.push(FuncArg::Single(Felt252::from_dec_str(value).unwrap()))
Expand Down
Loading