Skip to content

Commit 8b5d1c6

Browse files
authored
Don't validate CairoPie memory values. (#1783)
1 parent 5d11811 commit 8b5d1c6

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#### Upcoming Changes
44

5+
* fix: Remove validation of CairoPie memory values [#1783](https://github.com/lambdaclass/cairo-vm/pull/1783)
6+
57
* fix: Handle `GasBuiltin` in cairo1-run crate [#1789](https://github.com/lambdaclass/cairo-vm/pull/1789)
68
* Load `initial_gas` into vm instead of creating it via instructions.
79
* Fix bug affecting programs with input arguments and gas builtin.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from starkware.cairo.common.segments import relocate_segment
2+
from starkware.cairo.common.alloc import alloc
3+
4+
func main() {
5+
// Create a new segment
6+
let (segment: felt*) = alloc();
7+
8+
// Insert a value into the segment beyond the end of the segment.
9+
assert segment[0] = cast(segment, felt) + 100;
10+
11+
return ();
12+
}

vm/src/cairo_run.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ mod tests {
470470
#[case(include_bytes!("../../cairo_programs/relocate_segments.json"))]
471471
#[case(include_bytes!("../../cairo_programs/ec_op.json"))]
472472
#[case(include_bytes!("../../cairo_programs/bitwise_output.json"))]
473+
#[case(include_bytes!("../../cairo_programs/value_beyond_segment.json"))]
473474
fn get_and_run_cairo_pie(#[case] program_content: &[u8]) {
474475
let cairo_run_config = CairoRunConfig {
475476
layout: LayoutName::starknet_with_keccak,

vm/src/tests/cairo_run_test.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,13 @@ fn fibonacci_proof_mode_disable_trace_padding() {
10151015
assert!(runner.get_memory_holes().unwrap().is_zero());
10161016
}
10171017

1018+
#[test]
1019+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
1020+
fn value_beyond_segment() {
1021+
let program_data = include_bytes!("../../../cairo_programs/value_beyond_segment.json");
1022+
run_program_simple(program_data.as_slice());
1023+
}
1024+
10181025
#[test]
10191026
fn cairo_run_overflowing_dict() {
10201027
let program_data =

vm/src/vm/runners/cairo_pie.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,8 @@ impl CairoPie {
264264
Ok(())
265265
};
266266

267-
for ((si, so), value) in self.memory.0.iter() {
267+
for ((si, so), _) in self.memory.0.iter() {
268268
validate_addr((*si as isize, *so).into())?;
269-
if let MaybeRelocatable::RelocatableValue(val) = value {
270-
validate_addr(*val)?;
271-
}
272269
}
273270
Ok(())
274271
}
@@ -847,6 +844,7 @@ mod test {
847844
#[case(include_bytes!("../../../../cairo_programs/relocate_segments.json"), "relocate")]
848845
#[case(include_bytes!("../../../../cairo_programs/ec_op.json"), "ec_op")]
849846
#[case(include_bytes!("../../../../cairo_programs/bitwise_output.json"), "bitwise")]
847+
#[case(include_bytes!("../../../../cairo_programs/value_beyond_segment.json"), "relocate_beyond")]
850848
fn read_write_pie_zip(#[case] program_content: &[u8], #[case] identifier: &str) {
851849
use crate::{
852850
cairo_run::CairoRunConfig,

0 commit comments

Comments
 (0)