Skip to content

Commit 8be4064

Browse files
Update stwo-cario to 4ca3f15 (#153)
1 parent 0f45006 commit 8be4064

File tree

14 files changed

+53
-81
lines changed

14 files changed

+53
-81
lines changed

.github/workflows/check.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ jobs:
2222
steps:
2323
- uses: actions/checkout@v4
2424
- run: rustup show
25+
- run: rustup component add clippy --toolchain nightly
2526
- uses: Swatinem/rust-cache@v2
26-
- run: cargo clippy --all -- -D warnings
27+
- run: cargo +nightly clippy --all -- -D warnings
2728

2829
tests:
2930
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ members = [
77
resolver = "2"
88

99
[workspace.dependencies]
10-
bincode = { version = "2.0.0-rc.3", default-features = false, features = [
10+
bincode = { version = "2.0.1", features = [
1111
"serde",
1212
] }
1313
cairo-lang-executable = { git = "https://github.com/starkware-libs/cairo.git", rev = "f6f7c3bf45c9973bf8782d78c84aed6e741c2a2d" }
@@ -29,8 +29,8 @@ serde = { version = "1.0.202", features = ["derive"] }
2929
serde_json = "1.0.117"
3030
starknet-crypto = "0.6.2"
3131
starknet-types-core = "0.1.2"
32-
stwo_cairo_utils = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "e5fc0d8e20d535adbfd6acd01e8d859c3d8460dc" }
33-
stwo-cairo-adapter = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "e5fc0d8e20d535adbfd6acd01e8d859c3d8460dc" }
32+
stwo_cairo_utils = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "4ca3f15db375a0a75501a905b734551fe307e216" }
33+
stwo-cairo-adapter = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "4ca3f15db375a0a75501a905b734551fe307e216" }
3434
tempfile = "3.10.1"
3535
thiserror = "1.0.61"
3636
thiserror-no-std = "2.0.2"

crates/cairo-program-runner-lib/src/hints/bootloader_hints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ pub fn assert_is_composite_packed_output(
245245
match packed_output {
246246
PackedOutput::Composite(_) => Ok(()),
247247
other => Err(HintError::CustomHint(
248-
format!("Expected composite packed output, got {:?}", other).into_boxed_str(),
248+
format!("Expected composite packed output, got {other:?}").into_boxed_str(),
249249
)),
250250
}
251251
}

crates/cairo-program-runner-lib/src/hints/execute_task_hints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ fn process_program_common_logic(
370370
references,
371371
)
372372
.map_err(|err| {
373-
HintError::CustomHint(format!("{} for hint: {}", err, hint.code).into())
373+
HintError::CustomHint(format!("{err} for hint: {}", hint.code).into())
374374
})
375375
})
376376
.collect::<Result<Vec<_>, HintError>>()?;

crates/cairo-program-runner-lib/src/hints/fact_topologies.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub fn compute_fact_topologies(
175175
.get_plain_fact_topologies(applicative_bootloader_program_hash)
176176
.map_err(|e| {
177177
FactTopologyError::CompositePackedParsingFailed(
178-
format!("{:?}", e).into_boxed_str(),
178+
format!("{e:?}").into_boxed_str(),
179179
)
180180
})?;
181181
plain_fact_topologies.extend(subtask_plain_fact_topologies);
@@ -385,11 +385,8 @@ fn get_program_task_fact_topology(
385385
BuiltinAdditionalData::Output(data) => data,
386386
other => {
387387
return Err(FactTopologyError::Internal(
388-
format!(
389-
"Additional data of output builtin is not of the expected type: {:?}",
390-
other
391-
)
392-
.into_boxed_str(),
388+
format!("Additional data of output builtin is not of the expected type: {other:?}")
389+
.into_boxed_str(),
393390
))
394391
}
395392
};

crates/cairo-program-runner-lib/src/hints/program_hash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ mod tests {
210210
let program_hash = compute_program_hash_chain(&stripped_program, bootloader_version)
211211
.expect("Failed to compute program hash.");
212212

213-
let program_hash_hex = format!("{:#x}", program_hash);
213+
let program_hash_hex = format!("{program_hash:#x}");
214214

215215
assert_eq!(program_hash_hex, expected_program_hash);
216216
}

crates/cairo-program-runner-lib/src/hints/simple_bootloader_hints.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,13 @@ pub fn simulate_keccak_calc_high_low(
273273
let divisor = NonZeroFelt::try_from(Felt252::from(1u64 << (x * 8))).unwrap();
274274
let (high_felt, low_felt) = felt.div_rem(&divisor);
275275
insert_value_from_var_name(
276-
&format!("high{}", index),
276+
&format!("high{index}"),
277277
high_felt,
278278
vm,
279279
ids_data,
280280
ap_tracking,
281281
)?;
282-
insert_value_from_var_name(
283-
&format!("low{}", index),
284-
low_felt,
285-
vm,
286-
ids_data,
287-
ap_tracking,
288-
)?;
282+
insert_value_from_var_name(&format!("low{index}"), low_felt, vm, ids_data, ap_tracking)?;
289283

290284
Ok(())
291285
}

crates/cairo-program-runner-lib/src/hints/types.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,8 @@ impl<'de> Deserialize<'de> for TaskSpec {
305305
let task = match helper.task_type.as_str() {
306306
"CairoPiePath" => {
307307
if let Some(path) = &helper.path {
308-
create_pie_task(path).map_err(|e| {
309-
D::Error::custom(format!("Error creating PIE task: {:?}", e))
310-
})?
308+
create_pie_task(path)
309+
.map_err(|e| D::Error::custom(format!("Error creating PIE task: {e:?}")))?
311310
} else {
312311
return Err(D::Error::custom("CairoPiePath requires a path"));
313312
}
@@ -317,7 +316,7 @@ impl<'de> Deserialize<'de> for TaskSpec {
317316
let program_input = if let Some(program_input_data) = &helper.program_input {
318317
let program_input_json =
319318
serde_json::to_string(program_input_data).map_err(|e| {
320-
D::Error::custom(format!("Failed to serialize program input: {:?}", e))
319+
D::Error::custom(format!("Failed to serialize program input: {e:?}"))
321320
})?;
322321
Some(program_input_json)
323322
} else {
@@ -326,19 +325,19 @@ impl<'de> Deserialize<'de> for TaskSpec {
326325
// Deserialize program if present
327326
if let Some(program_data) = &helper.program {
328327
let program_bytes = serde_json::to_vec(program_data).map_err(|e| {
329-
D::Error::custom(format!("Failed to serialize program: {:?}", e))
328+
D::Error::custom(format!("Failed to serialize program: {e:?}"))
330329
})?;
331330
let program =
332331
Program::from_bytes(&program_bytes, Some("main")).map_err(|e| {
333-
D::Error::custom(format!("Failed to deserialize program: {:?}", e))
332+
D::Error::custom(format!("Failed to deserialize program: {e:?}"))
334333
})?;
335334
Task::Cairo0Program(Cairo0Executable {
336335
program,
337336
program_input,
338337
})
339338
} else if let Some(path) = &helper.path {
340339
create_cairo0_program_task(path, program_input).map_err(|e| {
341-
D::Error::custom(format!("Error creating Program task: {:?}", e))
340+
D::Error::custom(format!("Error creating Program task: {e:?}"))
342341
})?
343342
} else {
344343
return Err(D::Error::custom(
@@ -350,7 +349,7 @@ impl<'de> Deserialize<'de> for TaskSpec {
350349
if let Some(path) = &helper.path {
351350
create_cairo1_program_task(path, helper.user_args_list, helper.user_args_file)
352351
.map_err(|e| {
353-
D::Error::custom(format!("Error creating Cairo1 Program Task: {:?}", e))
352+
D::Error::custom(format!("Error creating Cairo1 Program Task: {e:?}"))
354353
})?
355354
} else {
356355
return Err(D::Error::custom("Cairo1Executable requires a path"));

crates/cairo-program-runner-lib/src/hints/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn gen_arg(
101101
let mut ptr = base;
102102
for arg in args {
103103
if let Some(value) = arg.downcast_ref::<MaybeRelocatable>() {
104-
ptr = vm.segments.load_data(ptr, &[value.clone()])?;
104+
ptr = vm.segments.load_data(ptr, std::slice::from_ref(value))?;
105105
} else if let Some(vector) = arg.downcast_ref::<Vec<Box<dyn Any>>>() {
106106
let nested_base = gen_arg(vm, vector)?;
107107
ptr = vm.segments.load_data(ptr, &[nested_base.into()])?;

crates/cairo-program-runner-lib/src/hints/verifier_utils.rs

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn safe_log2(x: u128) -> Result<u32, HintError> {
3737
Ok(x.trailing_zeros())
3838
} else {
3939
Err(HintError::CustomHint(
40-
format!("safe_log2: Input {} is not a power of two.", x).into(),
40+
format!("safe_log2: Input {x} is not a power of two.").into(),
4141
))
4242
}
4343
}
@@ -64,13 +64,10 @@ pub fn extract_annotations(
6464
) -> Result<Vec<Felt252>, HintError> {
6565
let mut res = Vec::new();
6666

67-
let pattern = format!(
68-
r"P->V\[(\d+):(\d+)\]: /cpu air/{}: .*?{}\((.+)\)",
69-
prefix, kind
70-
);
67+
let pattern = format!(r"P->V\[(\d+):(\d+)\]: /cpu air/{prefix}: .*?{kind}\((.+)\)");
7168

7269
let re = Regex::new(&pattern)
73-
.map_err(|e| HintError::CustomHint(format!("Regex error: {}", e).into()))?;
70+
.map_err(|e| HintError::CustomHint(format!("Regex error: {e}").into()))?;
7471

7572
for line in annotations {
7673
if let Some(captures) = re.captures(line) {
@@ -86,9 +83,7 @@ pub fn extract_annotations(
8683
let mut parse_and_push = |value_str: &str| -> Result<(), HintError> {
8784
let value_str = value_str.trim();
8885
let value = Felt252::from_hex(value_str).map_err(|_| {
89-
HintError::CustomHint(
90-
format!("Failed to parse value_str '{}'", value_str).into(),
91-
)
86+
HintError::CustomHint(format!("Failed to parse value_str '{value_str}'").into())
9287
})?;
9388
res.push(value);
9489
Ok(())
@@ -125,7 +120,7 @@ fn extract_z_and_alpha(annotations: &[String]) -> Result<(Felt252, Felt252), Hin
125120
let re = Regex::new(
126121
r"V->P: /cpu air/STARK/Interaction: Interaction element #\d+: Field Element\(0x([0-9a-f]+)\)",
127122
)
128-
.map_err(|e| HintError::CustomHint(format!("Regex error: {}", e).into()))?;
123+
.map_err(|e| HintError::CustomHint(format!("Regex error: {e}").into()))?;
129124

130125
let mut interaction_elements = Vec::new();
131126

@@ -139,7 +134,7 @@ fn extract_z_and_alpha(annotations: &[String]) -> Result<(Felt252, Felt252), Hin
139134
})?
140135
.as_str();
141136
let value = Felt252::from_hex(hex_str).map_err(|_| {
142-
HintError::CustomHint(format!("Failed to parse hex_str '{}'", hex_str).into())
137+
HintError::CustomHint(format!("Failed to parse hex_str '{hex_str}'").into())
143138
})?;
144139
interaction_elements.push(value);
145140
}
@@ -309,7 +304,7 @@ pub fn extract_proof_values(
309304
let mut fri_witnesses_authentications: Vec<Vec<Felt252>> = Vec::new();
310305

311306
for i in 1..n_fri_layers {
312-
let prefix = &format!("STARK/FRI/Decommitment/Layer {}", i);
307+
let prefix = &format!("STARK/FRI/Decommitment/Layer {i}");
313308
let leaves = annotations(prefix, "Field Element")?;
314309
let authentications = annotations(prefix, "Hash")?;
315310
fri_witnesses_leaves.push(leaves);
@@ -385,14 +380,14 @@ fn get_dynamic_or_const_value(
385380
}
386381
}
387382

388-
let full_name = format!("{}.{}", module_name, name);
383+
let full_name = format!("{module_name}.{name}");
389384

390385
if let Some(identifier) = identifiers.get(&full_name) {
391386
// Check if the identifier is a constant
392387
if let Some(type_) = &identifier.type_ {
393388
if type_ != "const" {
394389
return Err(HintError::CustomHint(
395-
format!("Identifier '{}' is not a constant.", full_name).into(),
390+
format!("Identifier '{full_name}' is not a constant.").into(),
396391
));
397392
}
398393
}
@@ -402,18 +397,14 @@ fn get_dynamic_or_const_value(
402397
} else {
403398
// If the identifier exists but has no value, return an error
404399
return Err(HintError::CustomHint(
405-
format!("Identifier '{}' has no value.", full_name).into(),
400+
format!("Identifier '{full_name}' has no value.").into(),
406401
));
407402
}
408403
}
409404

410405
// If the identifier wasn't found in `dynamic_params` or `identifiers`
411406
Err(HintError::CustomHint(
412-
format!(
413-
"Identifier '{}' not found in dynamic_params or identifiers.",
414-
name
415-
)
416-
.into(),
407+
format!("Identifier '{name}' not found in dynamic_params or identifiers.").into(),
417408
))
418409
}
419410

@@ -880,11 +871,7 @@ pub fn get_pages_and_products(
880871
let addr = cell.address;
881872
let val = cell.value.ok_or_else(|| {
882873
HintError::CustomHint(
883-
format!(
884-
"Value is missing in public memory entry at address {}.",
885-
addr
886-
)
887-
.into(),
874+
format!("Value is missing in public memory entry at address {addr}.").into(),
888875
)
889876
})?;
890877

@@ -948,20 +935,15 @@ pub fn compute_continuous_page_headers(
948935
if address != expected_address {
949936
return Err(HintError::CustomHint(
950937
format!(
951-
"Address mismatch for page {}: expected {}, got {}",
952-
page_id, expected_address, address
938+
"Address mismatch for page {page_id}: expected {expected_address}, got {address}"
953939
)
954940
.into(),
955941
));
956942
}
957943

958944
page_data.push(value.ok_or_else(|| {
959945
HintError::CustomHint(
960-
format!(
961-
"Value is missing for address {} on page {}.",
962-
address, page_id
963-
)
964-
.into(),
946+
format!("Value is missing for address {address} on page {page_id}.").into(),
965947
)
966948
})?);
967949

@@ -990,16 +972,13 @@ pub fn compute_continuous_page_headers(
990972
let page_index = i + 1;
991973
if page_index as u32 != *page_id {
992974
return Err(HintError::CustomHint(
993-
format!(
994-
"Page IDs are not consecutive: expected {}, got {}",
995-
page_index, page_id
996-
)
997-
.into(),
975+
format!("Page IDs are not consecutive: expected {page_index}, got {page_id}")
976+
.into(),
998977
));
999978
}
1000979

1001980
let page_data = data.get(page_id).ok_or_else(|| {
1002-
HintError::CustomHint(format!("Data for page {} not found.", page_id).into())
981+
HintError::CustomHint(format!("Data for page {page_id} not found.").into())
1003982
})?;
1004983

1005984
let hash_value = Pedersen::hash_array(page_data);
@@ -1089,7 +1068,7 @@ pub fn sort_segments(
10891068
BuiltinName::mul_mod,
10901069
];
10911070
segment_names.extend(builtin_ordered_list.iter().filter_map(|builtin| {
1092-
let name = format!("{:?}", builtin);
1071+
let name = format!("{builtin:?}");
10931072
memory_segments.contains_key(&name).then_some(name)
10941073
}));
10951074

0 commit comments

Comments
 (0)