Skip to content

Commit 3b23126

Browse files
authored
Cherry picks (#8009)
2 parents c79536e + 27fa308 commit 3b23126

File tree

20 files changed

+154
-128
lines changed

20 files changed

+154
-128
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

corelib/src/byte_array.cairo

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,9 @@ pub impl ByteArrayImpl of ByteArrayTrait {
114114

115115
// The split index is the number of bytes left for the next word (new pending_word of the
116116
// modified ByteArray).
117-
let split_index = if let Some(split_index) =
118-
crate::num::traits::CheckedSub::checked_sub(total_pending_bytes, BYTES_IN_BYTES31) {
119-
split_index
120-
} else {
117+
let Some(split_index) = crate::num::traits::CheckedSub::checked_sub(
118+
total_pending_bytes, BYTES_IN_BYTES31,
119+
) else {
121120
self.pending_word = word + self.pending_word * one_shift_left_bytes_felt252(len);
122121
self.pending_word_len = total_pending_bytes;
123122
return;

corelib/src/ecdsa.cairo

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,9 @@ pub fn check_ecdsa_signature(
112112
// Calculate the point `r * Q`.
113113
let mut rQ_state = init_ec;
114114
rQ_state.add_mul(signature_r, public_key_point);
115-
let rQ = match rQ_state.finalize_nz() {
116-
Some(pt) => pt,
115+
let Some(rQ) = rQ_state.finalize_nz() else {
117116
// The zero case is not actually possible, as `signature_r` isn't 0.
118-
None => { return false; },
117+
return false;
119118
};
120119

121120
// Check the `(zG + rQ).x = sR.x` case.

corelib/src/math.cairo

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ pub fn egcd<
4747
) -> (T, T, T, bool) {
4848
let (q, r) = DivRem::<T>::div_rem(a.into(), b);
4949

50-
let r = if let Some(r) = r.try_into() {
51-
r
52-
} else {
50+
let Some(r) = r.try_into() else {
5351
return (b.into(), core::num::traits::Zero::zero(), core::num::traits::One::one(), false);
5452
};
5553

corelib/src/poseidon.cairo

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,13 @@ fn _poseidon_hash_span_inner(
138138
ref span: Span<felt252>,
139139
) -> felt252 {
140140
let (s0, s1, s2) = state;
141-
let x = *match span.pop_front() {
142-
Some(x) => x,
143-
None => { return HashState { s0, s1, s2, odd: false }.finalize(); },
141+
let Some(x) = span.pop_front() else {
142+
return HashState { s0, s1, s2, odd: false }.finalize();
144143
};
145-
let y = *match span.pop_front() {
146-
Some(y) => y,
147-
None => { return HashState { s0: s0 + x, s1, s2, odd: true }.finalize(); },
144+
let Some(y) = span.pop_front() else {
145+
return HashState { s0: s0 + *x, s1, s2, odd: true }.finalize();
148146
};
149-
let next_state = hades_permutation(s0 + x, s1 + y, s2);
147+
let next_state = hades_permutation(s0 + *x, s1 + *y, s2);
150148
crate::gas::withdraw_gas_all(builtin_costs).expect('Out of gas');
151149
_poseidon_hash_span_inner(builtin_costs, next_state, ref span)
152150
}

corelib/src/starknet/storage_access.cairo

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -872,10 +872,9 @@ fn inner_byte_array_pointer(address: StorageAddress, chunk: felt252) -> StorageB
872872
/// The length of the byte array is read from `address` at domain `address_domain`.
873873
/// For more info read the documentation of `ByteArrayStore`.
874874
fn inner_read_byte_array(address_domain: u32, address: StorageAddress) -> SyscallResult<ByteArray> {
875-
let len: usize =
876-
match starknet::syscalls::storage_read_syscall(address_domain, address)?.try_into() {
877-
Some(x) => x,
878-
None => { return SyscallResult::Err(array!['Invalid ByteArray length']); },
875+
let Some::<usize>(len) = starknet::syscalls::storage_read_syscall(address_domain, address)?
876+
.try_into() else {
877+
return Err(array!['Invalid ByteArray length']);
879878
};
880879
let (mut remaining_full_words, pending_word_len) = core::DivRem::div_rem(
881880
len, BYTES_IN_BYTES31.try_into().unwrap(),
@@ -886,18 +885,13 @@ fn inner_read_byte_array(address_domain: u32, address: StorageAddress) -> Syscal
886885
let mut result: ByteArray = Default::default();
887886
loop {
888887
if remaining_full_words == 0 {
889-
break Ok(());
888+
break;
890889
}
891-
let value =
892-
match starknet::syscalls::storage_read_syscall(
893-
address_domain, storage_address_from_base_and_offset(chunk_base, index_in_chunk),
894-
) {
895-
Ok(value) => value,
896-
Err(err) => { break Err(err); },
897-
};
898-
let value: bytes31 = match value.try_into() {
899-
Some(x) => x,
900-
None => { break Err(array!['Invalid value']); },
890+
let value = starknet::syscalls::storage_read_syscall(
891+
address_domain, storage_address_from_base_and_offset(chunk_base, index_in_chunk),
892+
)?;
893+
let Some::<bytes31>(value) = value.try_into() else {
894+
return Err(array!['Invalid value']);
901895
};
902896
result.data.append(value);
903897
remaining_full_words -= 1;
@@ -911,7 +905,7 @@ fn inner_read_byte_array(address_domain: u32, address: StorageAddress) -> Syscal
911905
0
912906
},
913907
};
914-
}?;
908+
}
915909
if pending_word_len != 0 {
916910
let pending_word = starknet::syscalls::storage_read_syscall(
917911
address_domain, storage_address_from_base_and_offset(chunk_base, index_in_chunk),

crates/bin/cairo-execute/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,12 @@ fn main() -> anyhow::Result<()> {
333333
let load_offset = entry_point_offset + header_len;
334334
let info = ProfilingInfo::from_trace(&builder, load_offset, &Default::default(), trace);
335335

336-
let profiling_processor = ProfilingInfoProcessor::new(
336+
let processed_profiling_info = ProfilingInfoProcessor::new(
337337
Some(&db),
338-
replace_sierra_ids_in_program(&db, builder.sierra_program()),
339-
debug_info.statements_locations.get_statements_functions_map_for_tests(&db),
340-
);
341-
let processed_profiling_info = profiling_processor.process(&info, &Default::default());
338+
&replace_sierra_ids_in_program(&db, builder.sierra_program()),
339+
&debug_info.statements_locations.get_statements_functions_map_for_tests(&db),
340+
)
341+
.process(&info, &Default::default());
342342
println!("{processed_profiling_info}");
343343
}
344344

crates/bin/cairo-run/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ fn main() -> anyhow::Result<()> {
9999
.with_context(|| "Failed to run the function.")?;
100100

101101
if args.run_profiler {
102-
let profiling_info_processor = ProfilingInfoProcessor::new(
103-
Some(db),
104-
sierra_program,
105-
debug_info.statements_locations.get_statements_functions_map_for_tests(db),
106-
);
107102
match result.profiling_info {
108103
Some(raw_profiling_info) => {
104+
let statements_functions =
105+
debug_info.statements_locations.get_statements_functions_map_for_tests(db);
106+
let profiling_info_processor =
107+
ProfilingInfoProcessor::new(Some(db), &sierra_program, &statements_functions);
108+
109109
let profiling_info =
110110
profiling_info_processor.process(&raw_profiling_info, &Default::default());
111111
println!("Profiling info:\n{profiling_info}");

crates/bin/cairo-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ clap.workspace = true
1212
serde = { workspace = true, default-features = true }
1313

1414
cairo-lang-compiler = { path = "../../cairo-lang-compiler", version = "~2.12.0-rc.2" }
15+
cairo-lang-runner = { path = "../../cairo-lang-runner", version = "~2.12.0-rc.2" }
1516
cairo-lang-test-runner = { path = "../../cairo-lang-test-runner", version = "~2.12.0-rc.2" }

crates/bin/cairo-test/src/main.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use std::path::PathBuf;
44

55
use anyhow::Ok;
66
use cairo_lang_compiler::project::check_compiler_path;
7-
use cairo_lang_test_runner::{RunProfilerConfig, TestRunConfig, TestRunner};
7+
use cairo_lang_runner::profiling::ProfilerConfig;
8+
use cairo_lang_test_runner::{TestRunConfig, TestRunner};
89
use clap::{Parser, ValueEnum};
910
use serde::Serialize;
1011

11-
/// The clap-arg equivalent of [RunProfilerConfig].
12+
/// A clap-arg wrapper for Option<[ProfilerConfig]>.
1213
#[derive(ValueEnum, Clone, Default, Debug, Serialize, PartialEq, Eq, Hash)]
1314
#[serde(rename_all = "kebab-case")]
1415
enum RunProfilerConfigArg {
@@ -17,12 +18,12 @@ enum RunProfilerConfigArg {
1718
Cairo,
1819
Sierra,
1920
}
20-
impl From<RunProfilerConfigArg> for RunProfilerConfig {
21+
impl From<RunProfilerConfigArg> for Option<ProfilerConfig> {
2122
fn from(val: RunProfilerConfigArg) -> Self {
2223
match val {
23-
RunProfilerConfigArg::None => RunProfilerConfig::None,
24-
RunProfilerConfigArg::Cairo => RunProfilerConfig::Cairo,
25-
RunProfilerConfigArg::Sierra => RunProfilerConfig::Sierra,
24+
RunProfilerConfigArg::None => None,
25+
RunProfilerConfigArg::Cairo => Some(ProfilerConfig::Cairo),
26+
RunProfilerConfigArg::Sierra => Some(ProfilerConfig::Sierra),
2627
}
2728
}
2829
}
@@ -53,7 +54,7 @@ struct Args {
5354
#[arg(long, default_value_t = false)]
5455
starknet: bool,
5556
/// Whether to run the profiler, and what results to produce. See
56-
/// [cairo_lang_test_runner::RunProfilerConfig]
57+
/// [cairo_lang_runner::profiling::ProfilerConfig]
5758
#[arg(short, long, default_value_t, value_enum)]
5859
run_profiler: RunProfilerConfigArg,
5960
/// Should disable gas calculation.
@@ -74,7 +75,7 @@ fn main() -> anyhow::Result<()> {
7475
filter: args.filter,
7576
ignored: args.ignored,
7677
include_ignored: args.include_ignored,
77-
run_profiler: args.run_profiler.into(),
78+
profiler_config: args.run_profiler.into(),
7879
gas_enabled: !args.gas_disabled,
7980
print_resource_usage: args.print_resource_usage,
8081
};

0 commit comments

Comments
 (0)