Skip to content

Commit

Permalink
Don't validate CairoPie memory values. (#1783)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alon-Ti committed Jun 19, 2024
1 parent 5d11811 commit 8b5d1c6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
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: Remove validation of CairoPie memory values [#1783](https://github.com/lambdaclass/cairo-vm/pull/1783)

* fix: Handle `GasBuiltin` in cairo1-run crate [#1789](https://github.com/lambdaclass/cairo-vm/pull/1789)
* Load `initial_gas` into vm instead of creating it via instructions.
* Fix bug affecting programs with input arguments and gas builtin.
Expand Down
12 changes: 12 additions & 0 deletions cairo_programs/value_beyond_segment.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from starkware.cairo.common.segments import relocate_segment
from starkware.cairo.common.alloc import alloc

func main() {
// Create a new segment
let (segment: felt*) = alloc();
// Insert a value into the segment beyond the end of the segment.
assert segment[0] = cast(segment, felt) + 100;
return ();
}
1 change: 1 addition & 0 deletions vm/src/cairo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ mod tests {
#[case(include_bytes!("../../cairo_programs/relocate_segments.json"))]
#[case(include_bytes!("../../cairo_programs/ec_op.json"))]
#[case(include_bytes!("../../cairo_programs/bitwise_output.json"))]
#[case(include_bytes!("../../cairo_programs/value_beyond_segment.json"))]
fn get_and_run_cairo_pie(#[case] program_content: &[u8]) {
let cairo_run_config = CairoRunConfig {
layout: LayoutName::starknet_with_keccak,
Expand Down
7 changes: 7 additions & 0 deletions vm/src/tests/cairo_run_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,13 @@ fn fibonacci_proof_mode_disable_trace_padding() {
assert!(runner.get_memory_holes().unwrap().is_zero());
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn value_beyond_segment() {
let program_data = include_bytes!("../../../cairo_programs/value_beyond_segment.json");
run_program_simple(program_data.as_slice());
}

#[test]
fn cairo_run_overflowing_dict() {
let program_data =
Expand Down
6 changes: 2 additions & 4 deletions vm/src/vm/runners/cairo_pie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,8 @@ impl CairoPie {
Ok(())
};

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

0 comments on commit 8b5d1c6

Please sign in to comment.