Skip to content

Commit e92df3c

Browse files
update stwo-cairo version to sharp7 head (#221)
## Type - [ ] feature - [ ] bugfix - [ ] dev (no functional changes, no API changes) - [ ] fmt (formatting, renaming) - [ ] build - [ ] docs - [ ] testing ## Description ## Breaking changes? - [ ] yes - [ ] no <!-- Reviewable:start --> - - - This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/starkware-libs/bootloader-hints/221) <!-- Reviewable:end -->
1 parent e08ba10 commit e92df3c

File tree

2 files changed

+31
-49
lines changed

2 files changed

+31
-49
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ serde = { version = "1.0.219", features = ["derive"] }
3030
serde_json = "1.0.142"
3131
starknet-crypto = "0.7.4"
3232
starknet-types-core = "0.1.2"
33-
stwo_cairo_utils = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "17a1b4cead265fe0312ef5bda771b12b5472d1c8" }
34-
stwo-cairo-adapter = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "17a1b4cead265fe0312ef5bda771b12b5472d1c8" }
35-
stwo_cairo_prover = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "17a1b4cead265fe0312ef5bda771b12b5472d1c8" }
36-
stwo-cairo-serialize = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "17a1b4cead265fe0312ef5bda771b12b5472d1c8" }
37-
cairo-air = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "17a1b4cead265fe0312ef5bda771b12b5472d1c8" }
33+
stwo_cairo_utils = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "8663128d3067c795afc3cba29a4f8399d4126f64" }
34+
stwo-cairo-adapter = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "8663128d3067c795afc3cba29a4f8399d4126f64" }
35+
stwo_cairo_prover = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "8663128d3067c795afc3cba29a4f8399d4126f64" }
36+
stwo-cairo-serialize = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "8663128d3067c795afc3cba29a4f8399d4126f64" }
37+
cairo-air = { git = "https://github.com/starkware-libs/stwo-cairo", rev = "8663128d3067c795afc3cba29a4f8399d4126f64" }
3838
tempfile = "3.10.1"
3939
thiserror = "1.0.61"
4040
thiserror-no-std = "2.0.2"

crates/stwo_run_and_prove/src/main.rs

Lines changed: 26 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use cairo_air::PreProcessedTraceVariant;
21
use cairo_air::utils::ProofFormat;
32
use cairo_air::verifier::verify_cairo;
43
use cairo_program_runner_lib::cairo_run_program;
@@ -22,7 +21,6 @@ use stwo_cairo_prover::prover::{
2221
};
2322

2423
use stwo_cairo_prover::stwo::core::channel::MerkleChannel;
25-
use stwo_cairo_prover::stwo::core::pcs::PcsConfig;
2624
use stwo_cairo_prover::stwo::core::vcs::MerkleHasher;
2725
use stwo_cairo_prover::stwo::core::vcs::blake2_merkle::Blake2sMerkleChannel;
2826
use stwo_cairo_prover::stwo::core::vcs::poseidon252_merkle::Poseidon252MerkleChannel;
@@ -140,12 +138,6 @@ struct ProveConfig {
140138
prover_params_json: Option<PathBuf>,
141139
}
142140

143-
struct CairoProverInputs {
144-
prover_input: ProverInput,
145-
pcs_config: PcsConfig,
146-
preprocessed_trace: PreProcessedTraceVariant,
147-
}
148-
149141
fn main() -> Result<(), StwoRunAndProveError> {
150142
let args = match Args::try_parse_from(env::args()) {
151143
Ok(args) => args,
@@ -199,6 +191,7 @@ fn stwo_run_and_prove(
199191
let program_input = get_program_input(&program_input)?;
200192
info!("Running cairo run program.");
201193
let runner = cairo_run_program(&program, program_input, cairo_run_config)?;
194+
info!("Adapting prover input.");
202195
let prover_input = adapter(&runner);
203196
let (successful_proof_attempt, output_vec) =
204197
prove_with_retries(prover_input, prove_config, prover)?;
@@ -219,37 +212,27 @@ fn prove_with_retries(
219212
prove_config: ProveConfig,
220213
prover: Box<dyn ProverTrait>,
221214
) -> Result<(usize, OutputVec), StwoRunAndProveError> {
222-
let ProverParameters {
223-
channel_hash,
224-
pcs_config,
225-
preprocessed_trace,
226-
} = match prove_config.prover_params_json {
215+
let prover_params = match prove_config.prover_params_json {
227216
Some(ref path) => sonic_rs::from_str(&read_to_string(path)?)?,
228217
None => default_prod_prover_parameters(),
229218
};
230219

231-
let cairo_prover_inputs = CairoProverInputs {
232-
prover_input: prover_input.clone(),
233-
pcs_config,
234-
preprocessed_trace,
235-
};
236-
237220
// create the directory if it doesn't exist
238221
std::fs::create_dir_all(&prove_config.proofs_dir)?;
239222
let proof_format = prove_config.proof_format;
240223

241-
for i in 1..=prove_config.n_proof_attempts + 1 {
224+
for i in 1..=prove_config.n_proof_attempts {
242225
info!(
243226
"Attempting to generate proof {}/{}.",
244227
i, prove_config.n_proof_attempts
245228
);
246229
let proof_file_path = prove_config.proofs_dir.join(format!("proof_{i}"));
247230

248231
match prover.choose_channel_and_prove(
249-
&cairo_prover_inputs,
232+
prover_params,
233+
prover_input.clone(),
250234
proof_file_path,
251235
&proof_format,
252-
channel_hash,
253236
prove_config.verify,
254237
) {
255238
Ok(output_values) => {
@@ -282,23 +265,25 @@ fn prove_with_retries(
282265
panic!("Should not reach here, n_proof_attempts should be at least 1.");
283266
}
284267

285-
/// Chooses the appropriate channel based on the `channel_hash` and generates a proof.
268+
/// Chooses the appropriate channel and generates a proof.
286269
fn choose_channel_and_prove(
287-
cairo_prover_inputs: &CairoProverInputs,
270+
prover_params: ProverParameters,
271+
prover_input: ProverInput,
288272
proof_file_path: PathBuf,
289273
proof_format: &ProofFormat,
290-
channel_hash: ChannelHash,
291274
verify: bool,
292275
) -> Result<OutputVec, StwoRunAndProveError> {
293-
match channel_hash {
276+
match prover_params.channel_hash {
294277
ChannelHash::Blake2s => prove::<Blake2sMerkleChannel>(
295-
cairo_prover_inputs,
278+
prover_params,
279+
prover_input,
296280
proof_file_path,
297281
proof_format,
298282
verify,
299283
),
300284
ChannelHash::Poseidon252 => prove::<Poseidon252MerkleChannel>(
301-
cairo_prover_inputs,
285+
prover_params,
286+
prover_input,
302287
proof_file_path,
303288
proof_format,
304289
verify,
@@ -310,10 +295,10 @@ fn choose_channel_and_prove(
310295
trait ProverTrait {
311296
fn choose_channel_and_prove(
312297
&self,
313-
cairo_prover_inputs: &CairoProverInputs,
298+
prover_params: ProverParameters,
299+
prover_input: ProverInput,
314300
proof_file_path: PathBuf,
315301
proof_format: &ProofFormat,
316-
channel_hash: ChannelHash,
317302
verify: bool,
318303
) -> Result<OutputVec, StwoRunAndProveError>;
319304
}
@@ -323,17 +308,17 @@ struct StwoProverEntryPoint;
323308
impl ProverTrait for StwoProverEntryPoint {
324309
fn choose_channel_and_prove(
325310
&self,
326-
cairo_prover_inputs: &CairoProverInputs,
311+
prover_params: ProverParameters,
312+
prover_input: ProverInput,
327313
proof_file_path: PathBuf,
328314
proof_format: &ProofFormat,
329-
channel_hash: ChannelHash,
330315
verify: bool,
331316
) -> Result<OutputVec, StwoRunAndProveError> {
332317
choose_channel_and_prove(
333-
cairo_prover_inputs,
318+
prover_params,
319+
prover_input,
334320
proof_file_path,
335321
proof_format,
336-
channel_hash,
337322
verify,
338323
)
339324
}
@@ -344,7 +329,8 @@ impl ProverTrait for StwoProverEntryPoint {
344329
/// Verifies the proof if the `verify` flag is set.
345330
/// Returns the program output.
346331
fn prove<MC: MerkleChannel>(
347-
cairo_prover_inputs: &CairoProverInputs,
332+
prover_params: ProverParameters,
333+
prover_input: ProverInput,
348334
proof_file_path: PathBuf,
349335
proof_format: &ProofFormat,
350336
verify: bool,
@@ -354,11 +340,7 @@ where
354340
MC::H: Serialize,
355341
<MC::H as MerkleHasher>::Hash: CairoSerialize,
356342
{
357-
let proof = prove_cairo::<MC>(
358-
cairo_prover_inputs.prover_input.clone(),
359-
cairo_prover_inputs.pcs_config,
360-
cairo_prover_inputs.preprocessed_trace,
361-
)?;
343+
let proof = prove_cairo::<MC>(prover_input, prover_params)?;
362344

363345
let mut proof_file = create_file(&proof_file_path)?;
364346

@@ -386,7 +368,7 @@ where
386368
// retry the proof generation in case of a verification failure. In the calling function we
387369
// assume this specific error type, so if we don't map it, and the error type returned by
388370
// `verify_cairo` changes, it will break the retry logic.
389-
verify_cairo::<MC>(proof, cairo_prover_inputs.preprocessed_trace)
371+
verify_cairo::<MC>(proof, prover_params.preprocessed_trace)
390372
.map_err(|_| StwoRunAndProveError::Verification)?;
391373
}
392374

@@ -481,7 +463,7 @@ mod tests {
481463
mock_prover
482464
.expect_choose_channel_and_prove()
483465
.times(1)
484-
.returning(move |_, proof_file, _, _, _| {
466+
.returning(move |_, _, proof_file, _, _| {
485467
let expected_proof_file = get_path(EXPECTED_PROOF_FILE_NAME);
486468
fs::copy(&expected_proof_file, &proof_file).expect("Failed to copy proof file.");
487469
Ok(vec![ARRAY_SUM_EXPECTED_OUTPUT])
@@ -506,7 +488,7 @@ mod tests {
506488
mock_prover
507489
.expect_choose_channel_and_prove()
508490
.times(n_proof_attempts)
509-
.returning(move |_, proof_file, _, _, _| {
491+
.returning(move |_, _, proof_file, _, _| {
510492
let expected_proof_file = get_path(EXPECTED_PROOF_FILE_NAME);
511493
fs::copy(&expected_proof_file, &proof_file).expect("Failed to copy proof file.");
512494
Err(StwoRunAndProveError::Verification)
@@ -535,7 +517,7 @@ mod tests {
535517
mock_prover
536518
.expect_choose_channel_and_prove()
537519
.times(n_proof_attempts)
538-
.returning(move |_, proof_file, _, _, _| {
520+
.returning(move |_, _, proof_file, _, _| {
539521
let expected_proof_file = get_path(EXPECTED_PROOF_FILE_NAME);
540522
fs::copy(&expected_proof_file, &proof_file).expect("Failed to copy proof file.");
541523
results.next().unwrap()

0 commit comments

Comments
 (0)