Skip to content

Commit eeb5ae4

Browse files
authored
refactor: use auction strategy by default (#2388)
1 parent adb2bd2 commit eeb5ae4

File tree

12 files changed

+443
-95
lines changed

12 files changed

+443
-95
lines changed

crates/core/executor/src/profiler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ impl Profiler {
162162
pb.set_style(
163163
ProgressStyle::default_bar()
164164
.template(
165+
#[allow(clippy::literal_string_with_formatting_args)]
165166
"{msg} \n {spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({eta})",
166167
)
167168
.unwrap()

crates/prover/src/gas/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ pub fn final_transform(raw_gas: f64) -> Result<u64, GasError> {
5353
}
5454

5555
/// Calculates core, precompile, mem records. Does not implement packed or last shard logic.
56-
#[allow(clippy::manual_repeat_n)]
5756
pub fn estimated_records<'a>(
5857
split_opts: &SplitOpts,
5958
estimator: &'a RecordEstimator,
@@ -108,14 +107,12 @@ pub fn estimated_records<'a>(
108107
])
109108
}
110109

111-
std::iter::repeat(Cow::Owned(memory_air(threshold, threshold)))
112-
.take(full_airs as usize)
113-
.chain(
114-
remainders
115-
.iter()
116-
.any(|x| *x > 0)
117-
.then(|| Cow::Owned(memory_air(remainders[0], remainders[1]))),
118-
)
110+
std::iter::repeat_n(Cow::Owned(memory_air(threshold, threshold)), full_airs as usize).chain(
111+
remainders
112+
.iter()
113+
.any(|x| *x > 0)
114+
.then(|| Cow::Owned(memory_air(remainders[0], remainders[1]))),
115+
)
119116
};
120117

121118
core_records.chain(global_memory_records).chain(precompile_records)

crates/recursion/core/src/air/builder.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use core::iter::{once, repeat};
1+
use core::iter::{once, repeat_n};
22
use p3_air::{AirBuilder, AirBuilderWithPublicValues};
33
use p3_field::AbstractField;
44
use sp1_stark::{
@@ -58,7 +58,6 @@ pub trait RecursionMemoryAirBuilder: RecursionInteractionAirBuilder {
5858
);
5959
}
6060

61-
#[allow(clippy::manual_repeat_n)]
6261
fn recursion_eval_memory_access_single<E: Into<Self::Expr> + Clone>(
6362
&mut self,
6463
timestamp: impl Into<Self::Expr>,
@@ -79,12 +78,12 @@ pub trait RecursionMemoryAirBuilder: RecursionInteractionAirBuilder {
7978
let prev_values = once(prev_timestamp)
8079
.chain(once(addr.clone()))
8180
.chain(once(memory_access.prev_value().clone().into()))
82-
.chain(repeat(Self::Expr::zero()).take(3))
81+
.chain(repeat_n(Self::Expr::zero(), 3))
8382
.collect();
8483
let current_values = once(timestamp)
8584
.chain(once(addr.clone()))
8685
.chain(once(memory_access.value().clone().into()))
87-
.chain(repeat(Self::Expr::zero()).take(3))
86+
.chain(repeat_n(Self::Expr::zero(), 3))
8887
.collect();
8988

9089
self.receive(

crates/recursion/core/src/chips/mem/constant.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ impl<F: PrimeField32> MachineAir<F> for MemoryChip<F> {
102102
// This is a no-op.
103103
}
104104

105-
#[allow(clippy::manual_repeat_n)]
106105
fn generate_trace(&self, input: &Self::Record, _: &mut Self::Record) -> RowMajorMatrix<F> {
107106
// Match number of rows generated by the `.chunks` call in `generate_preprocessed_trace`.
108107
let num_rows = input
@@ -111,7 +110,7 @@ impl<F: PrimeField32> MachineAir<F> for MemoryChip<F> {
111110
.map(|x| x / NUM_CONST_MEM_ENTRIES_PER_ROW + 1)
112111
.unwrap_or_default();
113112
let mut rows =
114-
std::iter::repeat([F::zero(); NUM_MEM_INIT_COLS]).take(num_rows).collect::<Vec<_>>();
113+
std::iter::repeat_n([F::zero(); NUM_MEM_INIT_COLS], num_rows).collect::<Vec<_>>();
115114

116115
// Pad the rows to the next power of two.
117116
pad_rows_fixed(&mut rows, || [F::zero(); NUM_MEM_INIT_COLS], input.fixed_log2_rows(self));

crates/sdk/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ sp1-stark = { workspace = true }
4848
sp1-primitives = { workspace = true }
4949
itertools = { workspace = true }
5050
tonic = { version = "0.12", features = ["tls", "tls-roots"], optional = true }
51-
alloy-sol-types = { version = "1.0", default-features = false, optional = true }
51+
alloy-sol-types = { version = "1.0", default-features = false }
5252
alloy-primitives = { version = "1.0", default-features = false, optional = true, features = ["k256", "serde"] }
5353
backoff = { version = "0.4", features = ["tokio"], optional = true }
5454

@@ -76,9 +76,8 @@ network = [
7676
"dep:backoff",
7777
]
7878
tee-2fa = []
79-
sepolia = [
79+
reserved-capacity = [
8080
"network",
81-
"dep:alloy-sol-types",
8281
]
8382
cuda = []
8483
bigint-rug = ["sp1-core-machine/bigint-rug"]

crates/sdk/src/network/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::network::proto::{
3636
},
3737
};
3838

39-
#[cfg(feature = "sepolia")]
39+
#[cfg(not(feature = "reserved-capacity"))]
4040
use crate::network::proto::types::{
4141
GetProofRequestParamsRequest, GetProofRequestParamsResponse, GetProversByUptimeRequest,
4242
TransactionVariant,
@@ -226,7 +226,7 @@ impl NetworkClient {
226226
}
227227

228228
/// Gets the proof request parameters from the network.
229-
#[cfg(feature = "sepolia")]
229+
#[cfg(not(feature = "reserved-capacity"))]
230230
pub async fn get_proof_request_params(
231231
&self,
232232
mode: ProofMode,
@@ -427,7 +427,7 @@ impl NetworkClient {
427427
let nonce = self.get_nonce().await?;
428428

429429
cfg_if::cfg_if! {
430-
if #[cfg(feature = "sepolia")] {
430+
if #[cfg(not(feature = "reserved-capacity"))] {
431431
let whitelist = if let Some(whitelist) = &whitelist {
432432
whitelist.iter().map(|addr| addr.to_vec()).collect()
433433
} else {

crates/sdk/src/network/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub use alloy_primitives::{Address, B256};
2525
pub use error::*;
2626

2727
cfg_if::cfg_if! {
28-
if #[cfg(feature = "sepolia")] {
28+
if #[cfg(not(feature = "reserved-capacity"))] {
2929
pub(crate) const PUBLIC_EXPLORER_URL: &str = "https://explorer.sepolia.succinct.xyz";
3030
pub(crate) const DEFAULT_NETWORK_RPC_URL: &str = "https://rpc.sepolia.succinct.xyz";
3131
} else {

crates/sdk/src/network/proto/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
pub mod artifact;
77

88
cfg_if::cfg_if! {
9-
if #[cfg(feature = "sepolia")] {
9+
if #[cfg(not(feature = "reserved-capacity"))] {
1010
mod sepolia {
1111
#[rustfmt::skip]
1212
pub mod network;
@@ -27,4 +27,4 @@ cfg_if::cfg_if! {
2727
#[rustfmt::skip]
2828
pub use self::base::{network, types};
2929
}
30-
}
30+
}

crates/sdk/src/network/prover.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
SP1VerifyingKey,
2525
};
2626

27-
#[cfg(feature = "sepolia")]
27+
#[cfg(not(feature = "reserved-capacity"))]
2828
use crate::network::proto::types::GetProofRequestParamsResponse;
2929

3030
use alloy_primitives::{Address, B256, U256};
@@ -43,6 +43,12 @@ pub struct NetworkProver {
4343
pub(crate) tee_signers: Vec<Address>,
4444
}
4545

46+
#[cfg(feature = "reserved-capacity")]
47+
const DEFAULT_FULFILLMENT_STRATEGY: FulfillmentStrategy = FulfillmentStrategy::Reserved;
48+
49+
#[cfg(not(feature = "reserved-capacity"))]
50+
const DEFAULT_FULFILLMENT_STRATEGY: FulfillmentStrategy = FulfillmentStrategy::Auction;
51+
4652
impl NetworkProver {
4753
/// Creates a new [`NetworkProver`] with the given private key.
4854
///
@@ -139,7 +145,7 @@ impl NetworkProver {
139145
pk,
140146
stdin: stdin.clone(),
141147
timeout: None,
142-
strategy: FulfillmentStrategy::Hosted,
148+
strategy: DEFAULT_FULFILLMENT_STRATEGY,
143149
skip_simulation: false,
144150
cycle_limit: None,
145151
gas_limit: None,
@@ -190,7 +196,7 @@ impl NetworkProver {
190196
/// let params = client.get_proof_request_params(SP1ProofMode::Compressed).await.unwrap();
191197
/// })
192198
/// ```
193-
#[cfg(feature = "sepolia")]
199+
#[cfg(not(feature = "reserved-capacity"))]
194200
pub async fn get_proof_request_params(
195201
&self,
196202
mode: SP1ProofMode,
@@ -347,16 +353,16 @@ impl NetworkProver {
347353
) -> Result<B256> {
348354
// Ensure the strategy is supported in the network.
349355
cfg_if::cfg_if! {
350-
if #[cfg(feature = "sepolia")] {
356+
if #[cfg(not(feature = "reserved-capacity"))] {
351357
if strategy != FulfillmentStrategy::Auction {
352358
return Err(anyhow::anyhow!(
353-
"Strategy not supported with \"sepolia\" feature. Use FulfillmentStrategy::Auction."
359+
"This fulfillment strategy requires the \"reserved-capacity\" feature on sp1-sdk. Use FulfillmentStrategy::Auction or enable the feature."
354360
));
355361
}
356362
} else {
357363
if strategy == FulfillmentStrategy::Auction {
358364
return Err(anyhow::anyhow!(
359-
"FulfillmentStrategy::Auction requires the \"sepolia\" feature."
365+
"FulfillmentStrategy::Auction is not available with the \"reserved-capacity\" feature on sp1-sdk. Use a different strategy or disable the feature."
360366
));
361367
}
362368
}
@@ -568,6 +574,7 @@ impl NetworkProver {
568574
let mut whitelist = whitelist.clone();
569575

570576
// Attempt to get proof, with retry logic for failed auction requests.
577+
#[allow(clippy::never_loop)]
571578
loop {
572579
let request_id = self
573580
.request_proof_impl(
@@ -612,7 +619,7 @@ impl NetworkProver {
612619
let mut proof = match self.wait_proof(request_id, timeout, auction_timeout).await {
613620
Ok(proof) => proof,
614621
Err(e) => {
615-
#[cfg(feature = "sepolia")]
622+
#[cfg(not(feature = "reserved-capacity"))]
616623
// Check if this is an auction request that we can retry.
617624
if let Some(network_error) = e.downcast_ref::<Error>() {
618625
if matches!(
@@ -747,7 +754,7 @@ impl NetworkProver {
747754
max_price_per_pgu: Option<u64>,
748755
) -> Result<(Address, Address, Address, u64, u64, Vec<u8>)> {
749756
cfg_if::cfg_if! {
750-
if #[cfg(feature = "sepolia")] {
757+
if #[cfg(not(feature = "reserved-capacity"))] {
751758
let params = self.get_proof_request_params(mode).await?;
752759
let auctioneer_value = if let Some(auctioneer) = auctioneer {
753760
auctioneer
@@ -811,7 +818,7 @@ impl Prover<CpuProverComponents> for NetworkProver {
811818
pk,
812819
stdin,
813820
mode,
814-
FulfillmentStrategy::Hosted,
821+
DEFAULT_FULFILLMENT_STRATEGY,
815822
None,
816823
false,
817824
None,

crates/sdk/src/network/utils.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
#![allow(deprecated)]
66

7-
use std::cmp::max;
7+
use std::cmp::{max, min};
88

99
use prost::Message;
1010

@@ -31,9 +31,10 @@ pub(crate) fn sign_raw(message: &[u8], signer: &SigningKey) -> (Signature, Recov
3131

3232
/// Calculate the timeout for a proof request based on gas limit.
3333
///
34-
/// Uses a base timeout of 5 minutes plus 1 second per 2000000 prover gas.
34+
/// Uses a base timeout of 5 minutes plus 1 second per 2000000 prover gas. The timeout is capped at
35+
/// 4 hours.
3536
pub(crate) fn calculate_timeout_from_gas_limit(gas_limit: u64) -> u64 {
3637
let base_timeout = 300; // 5 minutes
3738
let gas_based_timeout = gas_limit / 2_000_000;
38-
max(base_timeout, gas_based_timeout)
39+
min(max(base_timeout, gas_based_timeout), 14400)
3940
}

0 commit comments

Comments
 (0)