summaryrefslogtreecommitdiff
path: root/lang/cairo/files/patch-rust-1.87.0
blob: 639d340b7993cc7fcc371dc9fbcbbf8101972cba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
https://github.com/lambdaclass/cairo-vm/pull/1990

From b427a3eddd4e40969eb910e559c6a28dd3e6c988 Mon Sep 17 00:00:00 2001
From: YairVaknin-starkware
 <141148375+YairVaknin-starkware@users.noreply.github.com>
Date: Mon, 10 Mar 2025 11:39:57 +0200
Subject: [PATCH] Update_to_rustc_1.85 (#1990)

* Update_to_rustc_1.85

* Fix montconfig

* format

* clippy

* clippy fix

---------

Co-authored-by: Edgar Luque <git@edgl.dev>
---
 vm/src/air_public_input.rs                          |  2 +-
 vm/src/cairo_run.rs                                 |  6 +++---
 .../builtin_hint_processor/signature.rs             |  7 +------
 .../builtin_hint_processor/uint256_utils.rs         |  4 ++--
 .../hint_processor/builtin_hint_processor/vrf/fq.rs |  2 +-
 .../cairo_1_hint_processor/dict_manager.rs          | 13 ++++++++++++-
 .../cairo_1_hint_processor/hint_processor.rs        |  7 ++++++-
 vm/src/math_utils/mod.rs                            |  1 -
 vm/src/serde/deserialize_program.rs                 |  4 ++--
 vm/src/serde/deserialize_utils.rs                   |  2 +-
 vm/src/vm/decoding/decoder.rs                       |  6 +++---
 vm/src/vm/runners/builtin_runner/modulo.rs          |  6 +++---
 vm/src/vm/runners/cairo_pie.rs                      |  9 ++++-----
 vm/src/vm/vm_core.rs                                |  4 ++--
 vm/src/vm/vm_memory/memory.rs                       |  2 +-
 29 files changed, 62 insertions(+), 52 deletions(-)

diff --git src/air_public_input.rs src/air_public_input.rs
index d4f39dfc80..9c81aad591 100644
--- cargo-crates/cairo-vm-1.0.2/src/air_public_input.rs
+++ cargo-crates/cairo-vm-1.0.2/src/air_public_input.rs
@@ -48,7 +48,7 @@ mod mem_value_serde {
 
     struct Felt252OptionVisitor;
 
-    impl<'de> de::Visitor<'de> for Felt252OptionVisitor {
+    impl de::Visitor<'_> for Felt252OptionVisitor {
         type Value = Option<Felt252>;
 
         fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
diff --git src/cairo_run.rs src/cairo_run.rs
index 43ecd8b164..e5950c5e8f 100644
--- cargo-crates/cairo-vm-1.0.2/src/cairo_run.rs
+++ cargo-crates/cairo-vm-1.0.2/src/cairo_run.rs
@@ -45,7 +45,7 @@ pub struct CairoRunConfig<'a> {
     pub allow_missing_builtins: Option<bool>,
 }
 
-impl<'a> Default for CairoRunConfig<'a> {
+impl Default for CairoRunConfig<'_> {
     fn default() -> Self {
         CairoRunConfig {
             entrypoint: "main",
@@ -152,9 +152,9 @@ pub fn cairo_run_pie(
     if cairo_run_config.proof_mode {
         return Err(RunnerError::CairoPieProofMode.into());
     }
-    if !hint_processor
+    if hint_processor
         .get_n_steps()
-        .is_some_and(|steps| steps == pie.execution_resources.n_steps)
+        .is_none_or(|steps| steps != pie.execution_resources.n_steps)
     {
         return Err(RunnerError::PieNStepsVsRunResourcesNStepsMismatch.into());
     }
diff --git src/hint_processor/builtin_hint_processor/signature.rs src/hint_processor/builtin_hint_processor/signature.rs
index 878a379b7a..2a77752c7e 100644
--- cargo-crates/cairo-vm-1.0.2/src/hint_processor/builtin_hint_processor/signature.rs
+++ cargo-crates/cairo-vm-1.0.2/src/hint_processor/builtin_hint_processor/signature.rs
@@ -1,7 +1,5 @@
 use crate::stdlib::{boxed::Box, collections::HashMap, prelude::*};
 
-use num_integer::Integer;
-
 use crate::{
     hint_processor::{
         builtin_hint_processor::hint_utils::{get_integer_from_var_name, get_ptr_from_var_name},
@@ -27,10 +25,7 @@ pub fn verify_ecdsa_signature(
     if ecdsa_ptr.segment_index != ecdsa_builtin.base() as isize {
         return Err(HintError::AddSignatureWrongEcdsaPtr(Box::new(ecdsa_ptr)));
     }
-    if !ecdsa_ptr
-        .offset
-        .is_multiple_of(&(CELLS_PER_SIGNATURE as usize))
-    {
+    if !num_integer::Integer::is_multiple_of(&ecdsa_ptr.offset, &(CELLS_PER_SIGNATURE as usize)) {
         return Err(HintError::AddSignatureNotAPublicKey(Box::new(ecdsa_ptr)));
     }
     ecdsa_builtin
diff --git src/hint_processor/builtin_hint_processor/uint256_utils.rs src/hint_processor/builtin_hint_processor/uint256_utils.rs
index 9c91fafa8a..0946dd5ad7 100644
--- cargo-crates/cairo-vm-1.0.2/src/hint_processor/builtin_hint_processor/uint256_utils.rs
+++ cargo-crates/cairo-vm-1.0.2/src/hint_processor/builtin_hint_processor/uint256_utils.rs
@@ -86,13 +86,13 @@ impl<'a> Uint256<'a> {
     }
 }
 
-impl<'a> From<&BigUint> for Uint256<'a> {
+impl From<&BigUint> for Uint256<'_> {
     fn from(value: &BigUint) -> Self {
         Self::split(value)
     }
 }
 
-impl<'a> From<Felt252> for Uint256<'a> {
+impl From<Felt252> for Uint256<'_> {
     fn from(value: Felt252) -> Self {
         let (high, low) = value.div_rem(pow2_const_nz(128));
         Self::from_values(low, high)
diff --git src/hint_processor/builtin_hint_processor/vrf/fq.rs src/hint_processor/builtin_hint_processor/vrf/fq.rs
index c31047d8e0..470a96ac8c 100644
--- cargo-crates/cairo-vm-1.0.2/src/hint_processor/builtin_hint_processor/vrf/fq.rs
+++ cargo-crates/cairo-vm-1.0.2/src/hint_processor/builtin_hint_processor/vrf/fq.rs
@@ -71,7 +71,7 @@ pub fn uint512_unsigned_div_rem(
 /// Implements hint:
 /// ```python
 /// from starkware.python.math_utils import div_mod
-
+///
 /// def split(a: int):
 /// return (a & ((1 << 128) - 1), a >> 128)
 ///
diff --git src/math_utils/mod.rs src/math_utils/mod.rs
index 565a768b7c..75ad9888e9 100644
--- cargo-crates/cairo-vm-1.0.2/src/math_utils/mod.rs
+++ cargo-crates/cairo-vm-1.0.2/src/math_utils/mod.rs
@@ -61,7 +61,6 @@ pub fn pow2_const_nz(n: u32) -> &'static NonZeroFelt {
 /// let negative = Felt252::MAX;
 /// assert_eq!(signed_felt(negative), BigInt::from(-1));
 /// ```
-
 pub fn signed_felt(felt: Felt252) -> BigInt {
     let biguint = felt.to_biguint();
     if biguint > *SIGNED_FELT_MAX {
diff --git src/serde/deserialize_program.rs src/serde/deserialize_program.rs
index 8f0e9a0dee..dc13a2e9f6 100644
--- cargo-crates/cairo-vm-1.0.2/src/serde/deserialize_program.rs
+++ cargo-crates/cairo-vm-1.0.2/src/serde/deserialize_program.rs
@@ -309,7 +309,7 @@ impl ValueAddress {
 
 struct Felt252Visitor;
 
-impl<'de> de::Visitor<'de> for Felt252Visitor {
+impl de::Visitor<'_> for Felt252Visitor {
     type Value = Felt252;
 
     fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
@@ -377,7 +377,7 @@ impl<'de> de::Visitor<'de> for ReferenceIdsVisitor {
 
 struct ValueAddressVisitor;
 
-impl<'de> de::Visitor<'de> for ValueAddressVisitor {
+impl de::Visitor<'_> for ValueAddressVisitor {
     type Value = ValueAddress;
 
     fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
diff --git src/serde/deserialize_utils.rs src/serde/deserialize_utils.rs
index 7b4c7bb20e..157c66de2f 100644
--- cargo-crates/cairo-vm-1.0.2/src/serde/deserialize_utils.rs
+++ cargo-crates/cairo-vm-1.0.2/src/serde/deserialize_utils.rs
@@ -88,7 +88,7 @@ fn register(input: &str) -> IResult<&str, Option<Register>> {
 }
 
 fn offset(input: &str) -> IResult<&str, i32> {
-    if input.eq("") {
+    if input.is_empty() {
         return Ok(("", 0));
     }
 
diff --git src/vm/decoding/decoder.rs src/vm/decoding/decoder.rs
index 9dd02ea276..095006adcc 100644
--- cargo-crates/cairo-vm-1.0.2/src/vm/decoding/decoder.rs
+++ cargo-crates/cairo-vm-1.0.2/src/vm/decoding/decoder.rs
@@ -37,9 +37,9 @@ pub fn decode_instruction(encoded_instr: u128) -> Result<Instruction, VirtualMac
     const OFFX_MASK: u128 = 0xFFFF;
 
     // Grab offsets and convert them from little endian format.
-    let off0 = decode_offset(encoded_instr >> OFF0_OFF & OFFX_MASK);
-    let off1 = decode_offset(encoded_instr >> OFF1_OFF & OFFX_MASK);
-    let off2 = decode_offset(encoded_instr >> OFF2_OFF & OFFX_MASK);
+    let off0 = decode_offset((encoded_instr >> OFF0_OFF) & OFFX_MASK);
+    let off1 = decode_offset((encoded_instr >> OFF1_OFF) & OFFX_MASK);
+    let off2 = decode_offset((encoded_instr >> OFF2_OFF) & OFFX_MASK);
 
     // Grab flags
     let flags = encoded_instr >> FLAGS_OFFSET;
diff --git src/vm/runners/builtin_runner/modulo.rs src/vm/runners/builtin_runner/modulo.rs
index ef11096535..37575ddd07 100644
--- cargo-crates/cairo-vm-1.0.2/src/vm/runners/builtin_runner/modulo.rs
+++ cargo-crates/cairo-vm-1.0.2/src/vm/runners/builtin_runner/modulo.rs
@@ -491,15 +491,15 @@ impl ModBuiltinRunner {
 
     /// NOTE: It is advisable to use VirtualMachine::mod_builtin_fill_memory instead of this method directly
     /// when implementing hints to avoid cloning the runners
-
+    ///
     /// Fills the memory with inputs to the builtin instances based on the inputs to the
     /// first instance, pads the offsets table to fit the number of operations writen in the
     /// input to the first instance, and caculates missing values in the values table.
-
+    ///
     /// For each builtin, the given tuple is of the form (builtin_ptr, builtin_runner, n),
     /// where n is the number of operations in the offsets table (i.e., the length of the
     /// offsets table is 3*n).
-
+    ///
     /// The number of operations written to the input of the first instance n' should be at
     /// least n and a multiple of batch_size. Previous offsets are copied to the end of the
     /// offsets table to make its length 3n'.
diff --git src/vm/runners/cairo_pie.rs src/vm/runners/cairo_pie.rs
index ca6960e2d4..b839be06f3 100644
--- cargo-crates/cairo-vm-1.0.2/src/vm/runners/cairo_pie.rs
+++ cargo-crates/cairo-vm-1.0.2/src/vm/runners/cairo_pie.rs
@@ -255,9 +255,9 @@ impl CairoPie {
             HashMap::from_iter(segment_sizes.iter().map(|si| (si.index, si.size)));
 
         let validate_addr = |addr: Relocatable| -> Result<(), CairoPieValidationError> {
-            if !segment_sizes
+            if segment_sizes
                 .get(&addr.segment_index)
-                .is_some_and(|size| addr.offset <= *size)
+                .is_none_or(|size| addr.offset > *size)
             {
                 return Err(CairoPieValidationError::InvalidAddress);
             }
@@ -437,7 +437,6 @@ impl CairoPie {
 pub(super) mod serde_impl {
     use crate::stdlib::collections::HashMap;
     use crate::types::builtin_name::BuiltinName;
-    use num_integer::Integer;
     use num_traits::Num;
 
     use super::CAIRO_PIE_VERSION;
@@ -467,7 +466,7 @@ pub(super) mod serde_impl {
 
     pub(crate) struct Felt252Wrapper<'a>(&'a Felt252);
 
-    impl<'a> Serialize for Felt252Wrapper<'a> {
+    impl Serialize for Felt252Wrapper<'_> {
         fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
         where
             S: Serializer,
@@ -723,7 +722,7 @@ pub(super) mod serde_impl {
         }
 
         pub fn from_bytes(bytes: &[u8]) -> Option<CairoPieMemory> {
-            if !bytes.len().is_multiple_of(&CELL_BYTE_LEN) {
+            if !num_integer::Integer::is_multiple_of(&bytes.len(), &CELL_BYTE_LEN) {
                 return None;
             }
 
diff --git src/vm/vm_core.rs src/vm/vm_core.rs
index 447f9c85d0..9fc7ca7cab 100644
--- cargo-crates/cairo-vm-1.0.2/src/vm/vm_core.rs
+++ cargo-crates/cairo-vm-1.0.2/src/vm/vm_core.rs
@@ -78,10 +78,10 @@ impl DeducedOperands {
         self.0 & 1 != 0
     }
     fn was_op0_deducted(&self) -> bool {
-        self.0 & 1 << 1 != 0
+        self.0 & (1 << 1) != 0
     }
     fn was_op1_deducted(&self) -> bool {
-        self.0 & 1 << 2 != 0
+        self.0 & (1 << 2) != 0
     }
 }
 
diff --git src/vm/vm_memory/memory.rs src/vm/vm_memory/memory.rs
index 9a20b60d05..c5f7e32055 100644
--- cargo-crates/cairo-vm-1.0.2/src/vm/vm_memory/memory.rs
+++ cargo-crates/cairo-vm-1.0.2/src/vm/vm_memory/memory.rs
@@ -233,7 +233,7 @@ impl Memory {
     }
 
     /// Retrieve a value from memory (either normal or temporary) and apply relocation rules
-    pub(crate) fn get<'a, 'b: 'a, K: 'a>(&'b self, key: &'a K) -> Option<Cow<MaybeRelocatable>>
+    pub(crate) fn get<'a, 'b: 'a, K: 'a>(&'b self, key: &'a K) -> Option<Cow<'b, MaybeRelocatable>>
     where
         Relocatable: TryFrom<&'a K>,
     {
--- cargo-crates/cairo-vm-1.0.2/src/hint_processor/cairo_1_hint_processor/dict_manager.rs.orig	2006-07-24 03:21:28.000000000 +0200
+++ cargo-crates/cairo-vm-1.0.2/src/hint_processor/cairo_1_hint_processor/dict_manager.rs	2025-05-20 15:28:17.489344000 +0200
@@ -124,6 +124,18 @@ impl DictManagerExecScope {
             let mut prev_end = vm.add_memory_segment();
             for tracker in &self.trackers {
                 vm.add_relocation_rule(tracker.start, prev_end)?;
+                #[cfg(feature = "extensive_hints")]
+                {
+                    vm.add_relocation_rule(
+                        tracker.start,
+                        MaybeRelocatable::RelocatableValue(prev_end),
+                    )?;
+                }
+                #[cfg(not(feature = "extensive_hints"))]
+                {
+                    vm.add_relocation_rule(tracker.start, prev_end)?;
+                }
+
                 prev_end += (tracker.end.unwrap_or_default() - tracker.start)?;
                 prev_end += 1;
             }
--- cargo-crates/cairo-vm-1.0.2/src/hint_processor/cairo_1_hint_processor/hint_processor.rs.orig	2006-07-24 03:21:28.000000000 +0200
+++ cargo-crates/cairo-vm-1.0.2/src/hint_processor/cairo_1_hint_processor/hint_processor.rs	2025-05-20 15:27:32.673984000 +0200
@@ -1,3 +1,8 @@
+// ark-ff-macros mess workaround
+// can't put this directly above MontConfig derive because Rust can't parse it correctly.
+#![allow(non_local_definitions)]
+#![allow(unexpected_cfgs)]
+
 use super::dict_manager::DictManagerExecScope;
 use super::hint_processor_utils::*;
 use crate::any_box;
@@ -38,9 +43,9 @@ struct MemoryExecScope {
 #[derive(MontConfig)]
 #[modulus = "3618502788666131213697322783095070105623107215331596699973092056135872020481"]
 #[generator = "3"]
-
 /// Returns the Beta value of the Starkware elliptic curve.
 struct FqConfig;
+
 type Fq = Fp256<MontBackend<FqConfig, 4>>;
 
 fn get_beta() -> Felt252 {