From 02e17045c75c3b099b10bdbb9135133ff7fbe08b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1?= <47506558+MegaRedHand@users.noreply.github.com>
Date: Tue, 18 Jul 2023 15:58:03 -0300
Subject: [PATCH 01/10] Add test for failing program

---
 .../manually_compiled/hint_index_crash.json   | 32 +++++++++++++++++++
 vm/src/tests/cairo_run_test.rs                |  7 ++++
 2 files changed, 39 insertions(+)
 create mode 100644 cairo_programs/manually_compiled/hint_index_crash.json

diff --git a/cairo_programs/manually_compiled/hint_index_crash.json b/cairo_programs/manually_compiled/hint_index_crash.json
new file mode 100644
index 0000000000..19cd2a8287
--- /dev/null
+++ b/cairo_programs/manually_compiled/hint_index_crash.json
@@ -0,0 +1,32 @@
+{
+    "attributes": [],
+    "builtins": [],
+    "compiler_version": "0.11.0",
+    "data": [],
+    "debug_info": {
+    	"instruction_locations": {}
+    },
+    "hints": {
+        "18446744073709551615": [
+            {
+                "accessible_scopes": [],
+                "code": "",
+                "flow_tracking_data": {
+                    "ap_tracking": {
+                        "group": 0,
+                        "offset": 0
+                    },
+                    "reference_ids": {}
+                }
+            }
+        ]
+    },
+    "identifiers": {
+        "__main__.main": {}
+    },
+    "main_scope": "",
+    "prime": "0x800000000000011000000000000000000000000000000000000000000000001",
+    "reference_manager": {
+        "references": []
+    }
+}
diff --git a/vm/src/tests/cairo_run_test.rs b/vm/src/tests/cairo_run_test.rs
index b6e2286e93..99cffb52db 100644
--- a/vm/src/tests/cairo_run_test.rs
+++ b/vm/src/tests/cairo_run_test.rs
@@ -982,3 +982,10 @@ fn cairo_run_overflowing_dict() {
         include_bytes!("../../../cairo_programs/manually_compiled/overflowing_dict.json");
     run_program_with_error(program_data, "Unknown memory cell at address");
 }
+
+#[test]
+fn cairo_run_big_hint_pcs() {
+    let program_data =
+        include_bytes!("../../../cairo_programs/manually_compiled/hint_index_crash.json");
+    run_program_with_error(program_data, "TODO: update to actual error message");
+}

From ea07c53b3e2e5681c26a95a29982485aca69a255 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1?= <47506558+MegaRedHand@users.noreply.github.com>
Date: Tue, 18 Jul 2023 16:48:29 -0300
Subject: [PATCH 02/10] Return error when some hint's PC isn't valid

---
 vm/src/serde/deserialize_program.rs   |  3 ++-
 vm/src/tests/cairo_run_test.rs        |  5 ++++-
 vm/src/types/errors/program_errors.rs |  2 ++
 vm/src/types/program.rs               | 19 ++++++++++++-------
 vm/src/utils.rs                       |  3 ++-
 5 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/vm/src/serde/deserialize_program.rs b/vm/src/serde/deserialize_program.rs
index ca7b777fa0..f836ecca5f 100644
--- a/vm/src/serde/deserialize_program.rs
+++ b/vm/src/serde/deserialize_program.rs
@@ -441,7 +441,8 @@ pub fn parse_program_json(
         }
     }
 
-    let (hints, hints_ranges) = Program::flatten_hints(&program_json.hints);
+    let (hints, hints_ranges) =
+        Program::flatten_hints(&program_json.hints, program_json.data.len())?;
 
     let shared_program_data = SharedProgramData {
         data: program_json.data,
diff --git a/vm/src/tests/cairo_run_test.rs b/vm/src/tests/cairo_run_test.rs
index 99cffb52db..e87b2d77cd 100644
--- a/vm/src/tests/cairo_run_test.rs
+++ b/vm/src/tests/cairo_run_test.rs
@@ -987,5 +987,8 @@ fn cairo_run_overflowing_dict() {
 fn cairo_run_big_hint_pcs() {
     let program_data =
         include_bytes!("../../../cairo_programs/manually_compiled/hint_index_crash.json");
-    run_program_with_error(program_data, "TODO: update to actual error message");
+    run_program_with_error(
+        program_data,
+        "Hint PC (18446744073709551615) is greater or equal to program length (0)",
+    );
 }
diff --git a/vm/src/types/errors/program_errors.rs b/vm/src/types/errors/program_errors.rs
index 7748874f17..4a3d16c712 100644
--- a/vm/src/types/errors/program_errors.rs
+++ b/vm/src/types/errors/program_errors.rs
@@ -17,6 +17,8 @@ pub enum ProgramError {
     ConstWithoutValue(String),
     #[error("Expected prime {PRIME_STR}, got {0}")]
     PrimeDiffers(String),
+    #[error("Hint PC ({0}) is greater or equal to program length ({1})")]
+    InvalidHintPc(usize, usize),
 }
 
 #[cfg(test)]
diff --git a/vm/src/types/program.rs b/vm/src/types/program.rs
index d395f159fe..00ff7ae6fe 100644
--- a/vm/src/types/program.rs
+++ b/vm/src/types/program.rs
@@ -91,7 +91,7 @@ impl Program {
             }
         }
 
-        let (hints, hints_ranges) = Self::flatten_hints(&hints);
+        let (hints, hints_ranges) = Self::flatten_hints(&hints, data.len())?;
 
         let shared_program_data = SharedProgramData {
             data,
@@ -114,18 +114,23 @@ impl Program {
 
     pub(crate) fn flatten_hints(
         hints: &HashMap<usize, Vec<HintParams>>,
-    ) -> (Vec<HintParams>, Vec<Option<(usize, NonZeroUsize)>>) {
+        program_length: usize,
+    ) -> Result<(Vec<HintParams>, Vec<Option<(usize, NonZeroUsize)>>), ProgramError> {
         let bounds = hints
             .iter()
             .map(|(pc, hs)| (*pc, hs.len()))
-            .reduce(|(max_pc, full_len), (pc, len)| (max_pc.max(pc), full_len + len));
+            .reduce(|(max_hint_pc, full_len), (pc, len)| (max_hint_pc.max(pc), full_len + len));
 
-        let Some((max_pc, full_len)) = bounds else {
-            return (Vec::new(), Vec::new());
+        let Some((max_hint_pc, full_len)) = bounds else {
+            return Ok((Vec::new(), Vec::new()));
         };
 
+        if max_hint_pc >= program_length {
+            return Err(ProgramError::InvalidHintPc(max_hint_pc, program_length));
+        }
+
         let mut hints_values = Vec::with_capacity(full_len);
-        let mut hints_ranges = vec![None; max_pc + 1];
+        let mut hints_ranges = vec![None; max_hint_pc + 1];
 
         for (pc, hs) in hints.iter().filter(|(_, hs)| !hs.is_empty()) {
             let range = (
@@ -136,7 +141,7 @@ impl Program {
             hints_values.extend_from_slice(&hs[..]);
         }
 
-        (hints_values, hints_ranges)
+        Ok((hints_values, hints_ranges))
     }
 
     #[cfg(feature = "std")]
diff --git a/vm/src/utils.rs b/vm/src/utils.rs
index f8fa9ed03d..7244e4d90e 100644
--- a/vm/src/utils.rs
+++ b/vm/src/utils.rs
@@ -343,7 +343,8 @@ pub mod test_utils {
 
     impl From<ProgramFlat> for Program {
         fn from(val: ProgramFlat) -> Self {
-            let (hints, hints_ranges) = Program::flatten_hints(&val.hints);
+            let (hints, hints_ranges) =
+                Program::flatten_hints(&val.hints, val.data.len()).expect("hints are valid");
             Program {
                 shared_program_data: Arc::new(SharedProgramData {
                     data: val.data,

From 414f2e8ea50560ccbc2369ee670d2c4f8e60f4a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1?= <47506558+MegaRedHand@users.noreply.github.com>
Date: Wed, 19 Jul 2023 10:52:38 -0300
Subject: [PATCH 03/10] Fix tests (+add test)

---
 ..._index_crash.json => invalid_hint_pc.json} |  0
 .../manually_compiled/valid_program_a.json    |  2 +-
 vm/src/serde/deserialize_program.rs           | 53 +++++++++++++++++--
 vm/src/tests/cairo_run_test.rs                |  2 +-
 vm/src/utils.rs                               |  1 +
 5 files changed, 53 insertions(+), 5 deletions(-)
 rename cairo_programs/manually_compiled/{hint_index_crash.json => invalid_hint_pc.json} (100%)

diff --git a/cairo_programs/manually_compiled/hint_index_crash.json b/cairo_programs/manually_compiled/invalid_hint_pc.json
similarity index 100%
rename from cairo_programs/manually_compiled/hint_index_crash.json
rename to cairo_programs/manually_compiled/invalid_hint_pc.json
diff --git a/cairo_programs/manually_compiled/valid_program_a.json b/cairo_programs/manually_compiled/valid_program_a.json
index dd9fd98240..02a48dc4c6 100644
--- a/cairo_programs/manually_compiled/valid_program_a.json
+++ b/cairo_programs/manually_compiled/valid_program_a.json
@@ -160,7 +160,7 @@
                 }
             }
         ],
-        "46": [
+        "4": [
             {
                 "accessible_scopes": [
                     "__main__",
diff --git a/vm/src/serde/deserialize_program.rs b/vm/src/serde/deserialize_program.rs
index f836ecca5f..6ff76ae6a7 100644
--- a/vm/src/serde/deserialize_program.rs
+++ b/vm/src/serde/deserialize_program.rs
@@ -878,7 +878,7 @@ mod tests {
                 }],
             ),
             (
-                46,
+                4,
                 vec![HintParams {
                     code: "import math".to_string(),
                     accessible_scopes: vec![
@@ -911,7 +911,7 @@ mod tests {
     /// Deserialize a program without an entrypoint.
     #[test]
     #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
-    fn deserialize_program_without_entrypoint_test() {
+    fn deserialize_program_without_entrypoint() {
         let reader =
             include_bytes!("../../../cairo_programs/manually_compiled/valid_program_a.json");
 
@@ -947,7 +947,7 @@ mod tests {
                 }],
             ),
             (
-                46,
+                4,
                 vec![HintParams {
                     code: "import math".to_string(),
                     accessible_scopes: vec![
@@ -1528,4 +1528,51 @@ mod tests {
             .unwrap()
         );
     }
+
+    #[test]
+    #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
+    fn deserialize_program_with_invalid_hint_pc() {
+        let reader = br#"{
+            "attributes": [],
+            "builtins": [],
+            "compiler_version": "0.11.0",
+            "data": [
+                "0x41241"
+            ],
+            "debug_info": {
+                "instruction_locations": {}
+            },
+            "hints": {
+                "1": [
+                    {
+                        "accessible_scopes": [],
+                        "code": "",
+                        "flow_tracking_data": {
+                            "ap_tracking": {
+                                "group": 0,
+                                "offset": 0
+                            },
+                            "reference_ids": {}
+                        }
+                    }
+                ]
+            },
+            "identifiers": {
+                "__main__.main": {}
+            },
+            "main_scope": "",
+            "prime": "0x800000000000011000000000000000000000000000000000000000000000001",
+            "reference_manager": {
+                "references": []
+            }
+        }"#;
+
+        let deserialization_result = deserialize_and_parse_program(reader, Some("main"));
+
+        assert!(deserialization_result.is_err());
+        assert_matches!(
+            deserialization_result.unwrap_err(),
+            ProgramError::InvalidHintPc(1, 1)
+        );
+    }
 }
diff --git a/vm/src/tests/cairo_run_test.rs b/vm/src/tests/cairo_run_test.rs
index e87b2d77cd..baa95b9f90 100644
--- a/vm/src/tests/cairo_run_test.rs
+++ b/vm/src/tests/cairo_run_test.rs
@@ -986,7 +986,7 @@ fn cairo_run_overflowing_dict() {
 #[test]
 fn cairo_run_big_hint_pcs() {
     let program_data =
-        include_bytes!("../../../cairo_programs/manually_compiled/hint_index_crash.json");
+        include_bytes!("../../../cairo_programs/manually_compiled/invalid_hint_pc.json");
     run_program_with_error(
         program_data,
         "Hint PC (18446744073709551615) is greater or equal to program length (0)",
diff --git a/vm/src/utils.rs b/vm/src/utils.rs
index 7244e4d90e..7f8918dab2 100644
--- a/vm/src/utils.rs
+++ b/vm/src/utils.rs
@@ -343,6 +343,7 @@ pub mod test_utils {
 
     impl From<ProgramFlat> for Program {
         fn from(val: ProgramFlat) -> Self {
+            // NOTE: panics if hints have PCs higher than the program length
             let (hints, hints_ranges) =
                 Program::flatten_hints(&val.hints, val.data.len()).expect("hints are valid");
             Program {

From 782fd62e1f684eed958b0bce87590a691f3c7db1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1?= <47506558+MegaRedHand@users.noreply.github.com>
Date: Wed, 19 Jul 2023 10:56:25 -0300
Subject: [PATCH 04/10] Appease clippy

---
 vm/src/types/program.rs | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/vm/src/types/program.rs b/vm/src/types/program.rs
index 00ff7ae6fe..31574b250c 100644
--- a/vm/src/types/program.rs
+++ b/vm/src/types/program.rs
@@ -49,7 +49,7 @@ use arbitrary::Arbitrary;
 pub(crate) struct SharedProgramData {
     pub(crate) data: Vec<MaybeRelocatable>,
     pub(crate) hints: Vec<HintParams>,
-    pub(crate) hints_ranges: Vec<Option<(usize, NonZeroUsize)>>,
+    pub(crate) hints_ranges: Vec<HintRange>,
     pub(crate) main: Option<usize>,
     //start and end labels will only be used in proof-mode
     pub(crate) start: Option<usize>,
@@ -60,6 +60,10 @@ pub(crate) struct SharedProgramData {
     pub(crate) reference_manager: Vec<HintReference>,
 }
 
+/// Represents a range of "hinted" PCs. Is [`None`] if the range is empty,
+/// and it is a tuple of `(start, length)` otherwise.
+type HintRange = Option<(usize, NonZeroUsize)>;
+
 #[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))]
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct Program {
@@ -115,7 +119,7 @@ impl Program {
     pub(crate) fn flatten_hints(
         hints: &HashMap<usize, Vec<HintParams>>,
         program_length: usize,
-    ) -> Result<(Vec<HintParams>, Vec<Option<(usize, NonZeroUsize)>>), ProgramError> {
+    ) -> Result<(Vec<HintParams>, Vec<HintRange>), ProgramError> {
         let bounds = hints
             .iter()
             .map(|(pc, hs)| (*pc, hs.len()))

From f09221a33942d01f0ace0193c1b83a9899f69f55 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1?= <47506558+MegaRedHand@users.noreply.github.com>
Date: Wed, 19 Jul 2023 11:03:48 -0300
Subject: [PATCH 05/10] Add some docs

---
 vm/src/types/program.rs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/vm/src/types/program.rs b/vm/src/types/program.rs
index 31574b250c..5c54cb0189 100644
--- a/vm/src/types/program.rs
+++ b/vm/src/types/program.rs
@@ -49,6 +49,7 @@ use arbitrary::Arbitrary;
 pub(crate) struct SharedProgramData {
     pub(crate) data: Vec<MaybeRelocatable>,
     pub(crate) hints: Vec<HintParams>,
+    /// This maps a PC to the range of hints in `hints` that correspond to it.
     pub(crate) hints_ranges: Vec<HintRange>,
     pub(crate) main: Option<usize>,
     //start and end labels will only be used in proof-mode
@@ -60,8 +61,9 @@ pub(crate) struct SharedProgramData {
     pub(crate) reference_manager: Vec<HintReference>,
 }
 
-/// Represents a range of "hinted" PCs. Is [`None`] if the range is empty,
-/// and it is a tuple of `(start, length)` otherwise.
+/// Represents a range of hints corresponding to a PC.
+///
+/// Is [`None`] if the range is empty, and it is [`Some`] tuple `(start, length)` otherwise.
 type HintRange = Option<(usize, NonZeroUsize)>;
 
 #[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(Arbitrary))]

From 3593a2225ba395e5588c038d2a3361c91d8040f5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1?= <47506558+MegaRedHand@users.noreply.github.com>
Date: Wed, 19 Jul 2023 11:05:26 -0300
Subject: [PATCH 06/10] Update changelog

---
 CHANGELOG.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 799dcfdea7..ceb3657bab 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
 
 #### Upcoming Changes
 
+* fix: return error when a parsed hint's PC is invalid [#1340](https://github.com/lambdaclass/cairo-vm/pull/1340)
+
 * chore(examples): remove _wee_alloc_ dependency from _wasm-demo_ example and _ensure-no_std_ dummy crate [#1337](https://github.com/lambdaclass/cairo-vm/pull/1337)
 
 * docs: improved crate documentation [#1334](https://github.com/lambdaclass/cairo-vm/pull/1334)

From af73230878974772f9553e178a2abfaca9b6a3d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1?= <47506558+MegaRedHand@users.noreply.github.com>
Date: Wed, 19 Jul 2023 11:41:43 -0300
Subject: [PATCH 07/10] Ignore manually compiled jsons in workflows cache

---
 .github/workflows/rust.yml | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index d8f0ade90a..213c1aa78a 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -31,6 +31,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
           examples/wasm-demo/src/array_sum.json
         key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
         restore-keys: ${{ matrix.program-target }}-cache-
@@ -82,6 +83,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
           examples/wasm-demo/src/array_sum.json
         key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Fetch proof programs
@@ -90,6 +92,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
         key: cairo_proof_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
     - name: Fetch bench programs
       uses: actions/cache/restore@v3
@@ -97,6 +100,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
         key: cairo_bench_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
     - name: Fetch test contracts
       uses: actions/cache/restore@v3
@@ -104,6 +108,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
         key: cairo_1_test_contracts-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
     - name: Run clippy
       run: make clippy
@@ -139,6 +144,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
           examples/wasm-demo/src/array_sum.json
         key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Fetch proof programs
@@ -147,6 +153,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
         key: cairo_proof_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
     - name: Fetch bench programs
       uses: actions/cache/restore@v3
@@ -154,6 +161,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
         key: cairo_bench_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
     - name: Fetch test contracts
       uses: actions/cache/restore@v3
@@ -161,6 +169,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
         key: cairo_1_test_contracts-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
 
     # NOTE: we do this separately because --workspace operates in weird ways
@@ -215,6 +224,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
           examples/wasm-demo/src/array_sum.json
         key: cairo_test_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Fetch proof programs
@@ -223,6 +233,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
         key: cairo_proof_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
     - name: Fetch test contracts
       uses: actions/cache/restore@v3
@@ -230,6 +241,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
         key: cairo_1_test_contracts-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
 
     - name: Install testing tools
@@ -334,6 +346,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
         key: ${{ matrix.program-target }}-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
         fail-on-cache-miss: true
 
@@ -377,6 +390,7 @@ jobs:
         path: |
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
+          !cairo_programs/manually_compiled/*
         key: ${{ matrix.program-target }}-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
         fail-on-cache-miss: true
 

From f8178510ed407d34ed42797ce028789d2bb744cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1?= <47506558+MegaRedHand@users.noreply.github.com>
Date: Wed, 19 Jul 2023 15:54:10 -0300
Subject: [PATCH 08/10] Fix warning in wasm-demo

---
 examples/wasm-demo/src/lib.rs | 1 -
 1 file changed, 1 deletion(-)

diff --git a/examples/wasm-demo/src/lib.rs b/examples/wasm-demo/src/lib.rs
index 37a65cc5c7..c3ad8d406c 100644
--- a/examples/wasm-demo/src/lib.rs
+++ b/examples/wasm-demo/src/lib.rs
@@ -12,7 +12,6 @@ extern "C" {
     fn log(msg: &str);
 }
 
-#[cfg(feature = "console_error_panic_hook")]
 #[wasm_bindgen(start)]
 pub fn start() {
     crate::utils::set_panic_hook();

From 5b15f2e858a85dcba5b8bb4297aa7763c62d2ddd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1?= <47506558+MegaRedHand@users.noreply.github.com>
Date: Wed, 19 Jul 2023 16:10:12 -0300
Subject: [PATCH 09/10] Fix hash not hashing wasm-demo program

---
 .github/workflows/rust.yml | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 213c1aa78a..d50acae67b 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -93,7 +93,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
-        key: cairo_proof_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
+        key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Fetch bench programs
       uses: actions/cache/restore@v3
       with:
@@ -101,7 +101,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
-        key: cairo_bench_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
+        key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Fetch test contracts
       uses: actions/cache/restore@v3
       with:
@@ -109,7 +109,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
-        key: cairo_1_test_contracts-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
+        key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Run clippy
       run: make clippy
 
@@ -154,7 +154,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
-        key: cairo_proof_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
+        key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Fetch bench programs
       uses: actions/cache/restore@v3
       with:
@@ -162,7 +162,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
-        key: cairo_bench_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
+        key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Fetch test contracts
       uses: actions/cache/restore@v3
       with:
@@ -170,7 +170,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
-        key: cairo_1_test_contracts-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
+        key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
 
     # NOTE: we do this separately because --workspace operates in weird ways
     - name: Check all features (felt)
@@ -234,7 +234,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
-        key: cairo_proof_programs-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
+        key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Fetch test contracts
       uses: actions/cache/restore@v3
       with:
@@ -242,7 +242,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
-        key: cairo_1_test_contracts-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
+        key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
 
     - name: Install testing tools
       uses: taiki-e/install-action@v2
@@ -326,7 +326,7 @@ jobs:
         path: |
           cairo_programs/**/*.memory
           cairo_programs/**/*.trace
-        key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
+        key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
         restore-keys: ${{ matrix.program-target }}-reference-trace-cache-
 
     - name: Python3 Build
@@ -347,7 +347,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
-        key: ${{ matrix.program-target }}-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
+        key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
         fail-on-cache-miss: true
 
     # This is not pretty, but we need `make` to see the compiled programs are
@@ -391,7 +391,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
-        key: ${{ matrix.program-target }}-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
+        key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
         fail-on-cache-miss: true
 
     - name: Generate traces
@@ -481,7 +481,7 @@ jobs:
         path: |
           cairo_programs/**/*.memory
           cairo_programs/**/*.trace
-        key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles( 'cairo_programs/**/*.cairo' ) }}
+        key: ${{ matrix.program-target }}-reference-trace-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
         fail-on-cache-miss: true
 
     - name: Fetch traces for cairo-vm

From f28bbde4fd1fc02a9c37098fa3081d36a49dbc9f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1?= <47506558+MegaRedHand@users.noreply.github.com>
Date: Wed, 19 Jul 2023 16:15:36 -0300
Subject: [PATCH 10/10] Fix mismatching paths

---
 .github/workflows/rust.yml | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index d50acae67b..d7d8798613 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -93,6 +93,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
+          examples/wasm-demo/src/array_sum.json
         key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Fetch bench programs
       uses: actions/cache/restore@v3
@@ -101,6 +102,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
+          examples/wasm-demo/src/array_sum.json
         key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Fetch test contracts
       uses: actions/cache/restore@v3
@@ -109,6 +111,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
+          examples/wasm-demo/src/array_sum.json
         key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Run clippy
       run: make clippy
@@ -154,6 +157,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
+          examples/wasm-demo/src/array_sum.json
         key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Fetch bench programs
       uses: actions/cache/restore@v3
@@ -162,6 +166,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
+          examples/wasm-demo/src/array_sum.json
         key: cairo_bench_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Fetch test contracts
       uses: actions/cache/restore@v3
@@ -170,6 +175,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
+          examples/wasm-demo/src/array_sum.json
         key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
 
     # NOTE: we do this separately because --workspace operates in weird ways
@@ -234,6 +240,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
+          examples/wasm-demo/src/array_sum.json
         key: cairo_proof_programs-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
     - name: Fetch test contracts
       uses: actions/cache/restore@v3
@@ -242,6 +249,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
+          examples/wasm-demo/src/array_sum.json
         key: cairo_1_test_contracts-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
 
     - name: Install testing tools
@@ -347,6 +355,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
+          examples/wasm-demo/src/array_sum.json
         key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
         fail-on-cache-miss: true
 
@@ -391,6 +400,7 @@ jobs:
           cairo_programs/**/*.casm
           cairo_programs/**/*.json
           !cairo_programs/manually_compiled/*
+          examples/wasm-demo/src/array_sum.json
         key: ${{ matrix.program-target }}-cache-${{ hashFiles('cairo_programs/**/*.cairo', 'examples/wasm-demo/src/array_sum.cairo') }}
         fail-on-cache-miss: true