Skip to content

Commit 6fef8f0

Browse files
authored
BM-196: Prepend 0x to request_id and add verify-proof command in the CLI (github#35)
- Prepend `0x` to request id prints - Add `verify-proof` subcommand to CLI
1 parent 09023a2 commit 6fef8f0

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

crates/boundless-market/src/bin/cli.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ use anyhow::{bail, Context, Result};
1515
use clap::{Args, Parser, Subcommand};
1616
use guest_util::ECHO_ELF;
1717
use hex::FromHex;
18-
use risc0_zkvm::sha::Digest;
18+
use risc0_ethereum_contracts::IRiscZeroVerifier;
19+
use risc0_zkvm::{
20+
sha::{Digest, Digestible},
21+
Journal,
22+
};
1923
use url::Url;
2024

2125
use boundless_market::{
@@ -72,6 +76,14 @@ enum Command {
7276
#[clap(short, long, default_value = "false")]
7377
wait: bool,
7478
},
79+
/// Verify the proof of the given request against
80+
/// the SetVerifier contract.
81+
VerifyProof {
82+
/// The proof request identifier
83+
request_id: U256,
84+
/// The image id of the original request
85+
image_id: B256,
86+
},
7587
/// Get the status of a given request
7688
Status {
7789
/// The proof request identifier
@@ -138,6 +150,8 @@ struct MainArgs {
138150
wallet_private_key: PrivateKeySigner,
139151
#[clap(short, long, env)]
140152
proof_market_address: Address,
153+
#[clap(short, long, env)]
154+
set_verifier_address: Address,
141155
#[command(subcommand)]
142156
command: Command,
143157
}
@@ -156,7 +170,7 @@ async fn main() -> Result<()> {
156170
let provider =
157171
ProviderBuilder::new().with_recommended_fillers().wallet(wallet).on_http(args.rpc_url);
158172
let market = ProofMarketService::new(args.proof_market_address, provider.clone(), caller);
159-
173+
let set_verifier = IRiscZeroVerifier::new(args.set_verifier_address, provider.clone());
160174
let command = args.command.clone();
161175
match command {
162176
Command::Deposit { amount } => {
@@ -182,7 +196,7 @@ async fn main() -> Result<()> {
182196
}
183197
Command::Slash { request_id } => {
184198
market.slash(request_id).await?;
185-
tracing::info!("Request slashed: {request_id:x}");
199+
tracing::info!("Request slashed: 0x{request_id:x}");
186200
}
187201
Command::GetProof { request_id, wait } => {
188202
let (journal, seal) = if wait {
@@ -198,6 +212,19 @@ async fn main() -> Result<()> {
198212
serde_json::to_string_pretty(&seal)?
199213
);
200214
}
215+
Command::VerifyProof { request_id, image_id } => {
216+
let (journal, seal) = market
217+
.wait_for_request_fulfillment(request_id, Duration::from_secs(5), None)
218+
.await?;
219+
220+
let journal_digest = <[u8; 32]>::from(Journal::new(journal.to_vec()).digest()).into();
221+
set_verifier
222+
.verify(seal, image_id, journal_digest)
223+
.call()
224+
.await
225+
.map_err(|_| anyhow::anyhow!("Verification failed"))?;
226+
tracing::info!("Proof for request id 0x{request_id:x} verified successfully.");
227+
}
201228
Command::Status { request_id } => {
202229
let status = market.get_status(request_id).await?;
203230
tracing::info!("Status: {:?}", status);
@@ -298,7 +325,7 @@ where
298325

299326
let request_id = market.submit_request(&request, &signer).await?;
300327
tracing::info!(
301-
"Submitted request ID {request_id:x}, bidding start at block number {}",
328+
"Submitted request ID 0x{request_id:x}, bidding start at block number {}",
302329
offer.biddingStart
303330
);
304331

@@ -360,7 +387,7 @@ where
360387

361388
let request_id = market.submit_request(&request, &signer).await?;
362389
tracing::info!(
363-
"Proving request ID {request_id:x}, bidding start at block number {}",
390+
"Proving request ID 0x{request_id:x}, bidding start at block number {}",
364391
request.offer.biddingStart
365392
);
366393

docs/src/market/proving_request.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,21 @@ The [client-cli](../../../crates/boundless-market/src/bin/cli.rs) allows to:
7777
2024-09-17T15:14:01.314302Z INFO cli: Journal: "0x576564204a756c2020332031343a33373a31322050445420323032340a" - Seal: "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000164578a3cc24cf38d1173509a99db4f70d57ff3a6c43cb2e8552a2a5d252968ba"
7878
```
7979

80-
4. Send an offer with the requirements specified as command line arguments:
80+
4. Verify a proof of a request
81+
82+
With the `verify-proof` subcommand, you can verify a proof for a given request id and image id.
83+
84+
```console
85+
RUST_LOG=info,boundless_market=debug cargo run --bin cli -- verify-proof 0x466acfc0f27bba9fbb7a8508f576527e81e83bd00000052 257569e11f856439ec3c1e0fe6486fb9af90b1da7324d577f65dd0d45ec12c7d
86+
```
87+
88+
Should output something like:
89+
90+
```console
91+
2024-10-07T14:50:54.442260Z INFO cli: Proof for request id 0x466acfc0f27bba9fbb7a8508f576527e81e83bd00000052 verified successfully.
92+
```
93+
94+
5. Send an offer with the requirements specified as command line arguments:
8195

8296
With the `submit-offer` subcommand, you can specify the requirements and input as command-line options.
8397
It will upload the image and input, and place public URLs in the request.
@@ -91,7 +105,7 @@ The [client-cli](../../../crates/boundless-market/src/bin/cli.rs) allows to:
91105
PINATA_JWT="YOUR_PINATA_JWT" RUST_LOG=info,boundless_market=debug cargo run --bin cli -- submit-offer offer.yaml --wait --input "hello" --encode-input --journal-prefix ""
92106
```
93107

94-
5. Slash a request and get back funds
108+
6. Slash a request and get back funds
95109

96110
With the `slash` subcommand, you can slash a given `request ID` and get a refund of your offer:
97111

0 commit comments

Comments
 (0)