Skip to content

Commit

Permalink
feat: check version for proof requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstam committed May 31, 2024
1 parent e48c01e commit 8ee0ef1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
3 changes: 3 additions & 0 deletions sdk/src/network/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sol! {
uint64 nonce;
uint64 deadline;
uint32 mode;
string version;
}

struct SubmitProof {
Expand Down Expand Up @@ -94,11 +95,13 @@ impl NetworkAuth {
nonce: u64,
deadline: u64,
mode: i32,
version: &str,
) -> Result<Vec<u8>> {
let type_struct = CreateProof {
nonce,
deadline,
mode: mode as u32,
version: version.to_string(),
};
self.sign_message(type_struct).await
}
Expand Down
9 changes: 7 additions & 2 deletions sdk/src/network/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const DEFAULT_PROVER_NETWORK_RPC: &str = "https://rpc.succinct.xyz/";
/// The default SP1 Verifier address on all chains.
const DEFAULT_SP1_VERIFIER_ADDRESS: &str = "0xed2107448519345059eab9cddab42ddc78fbebe9";

/// The timeout for a request to the network.
const TIMEOUT: Duration = Duration::from_secs(60 * 60);

pub struct NetworkClient {
pub rpc: TwirpClient,
pub http: HttpClientWithMiddleware,
Expand Down Expand Up @@ -172,17 +175,18 @@ impl NetworkClient {
elf: &[u8],
stdin: &SP1Stdin,
mode: ProofMode,
version: &str,
) -> Result<String> {
let start = SystemTime::now();
let since_the_epoch = start
.duration_since(UNIX_EPOCH)
.expect("Invalid start time");
let deadline = since_the_epoch.as_secs() + 1000;
let deadline = since_the_epoch.as_secs() + TIMEOUT.as_secs();

let nonce = self.get_nonce().await?;
let create_proof_signature = self
.auth
.sign_create_proof_message(nonce, deadline, mode.into())
.sign_create_proof_message(nonce, deadline, mode.into(), version)
.await?;
let res = self
.rpc
Expand All @@ -191,6 +195,7 @@ impl NetworkClient {
nonce,
deadline,
mode: mode.into(),
version: version.to_string(),
})
.await?;

Expand Down
5 changes: 4 additions & 1 deletion sdk/src/network/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ impl NetworkProver {
log::info!("Skipping simulation");
}

let proof_id = client.create_proof(elf, &stdin, mode).await?;
let version = sp1_prover::install::PLONK_BN254_ARTIFACTS_COMMIT;
log::info!("Client version {}", version);

let proof_id = client.create_proof(elf, &stdin, mode, version).await?;
log::info!("Created {}", proof_id);

let mut is_claimed = false;
Expand Down
13 changes: 10 additions & 3 deletions sdk/src/proto/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub struct CreateProofRequest {
/// The deadline for the proof request, signifying the latest time a fulfillment would be valid.
#[prost(uint64, tag = "4")]
pub deadline: u64,
/// The client version used, in the form of an 8-character git commit hash.
#[prost(string, tag = "5")]
pub version: ::prost::alloc::string::String,
}
/// The response for creating a proof.
#[derive(serde::Serialize, serde::Deserialize)]
Expand Down Expand Up @@ -303,18 +306,21 @@ pub enum ProofMode {
Compressed = 2,
/// The proof mode for a PlonK proof.
Plonk = 3,
/// The proof mode for a Groth16 proof.
Groth16 = 4,
}
impl ProofMode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub const fn as_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
ProofMode::Unspecified => "PROOF_MODE_UNSPECIFIED",
ProofMode::Core => "PROOF_MODE_CORE",
ProofMode::Compressed => "PROOF_MODE_COMPRESSED",
ProofMode::Plonk => "PROOF_MODE_PLONK",
ProofMode::Groth16 => "PROOF_MODE_GROTH16",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
Expand All @@ -324,6 +330,7 @@ impl ProofMode {
"PROOF_MODE_CORE" => Some(Self::Core),
"PROOF_MODE_COMPRESSED" => Some(Self::Compressed),
"PROOF_MODE_PLONK" => Some(Self::Plonk),
"PROOF_MODE_GROTH16" => Some(Self::Groth16),
_ => None,
}
}
Expand Down Expand Up @@ -362,7 +369,7 @@ impl ProofStatus {
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub const fn as_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
ProofStatus::ProofUnspecifiedStatus => "PROOF_UNSPECIFIED_STATUS",
ProofStatus::ProofPreparing => "PROOF_PREPARING",
Expand Down Expand Up @@ -419,7 +426,7 @@ impl TransactionStatus {
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub const fn as_str_name(&self) -> &'static str {
pub fn as_str_name(&self) -> &'static str {
match self {
TransactionStatus::TransactionUnspecifiedStatus => "TRANSACTION_UNSPECIFIED_STATUS",
TransactionStatus::TransactionScheduled => "TRANSACTION_SCHEDULED",
Expand Down

0 comments on commit 8ee0ef1

Please sign in to comment.