Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voyager verification support #3093

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a6cb597
Add skeleton for voyager verification support
jkopanski Jan 24, 2025
af28837
Voyager db for querying the project
jkopanski Feb 25, 2025
76ea3fd
Voyager contract verifier
jkopanski Feb 26, 2025
b826533
Tests for voyager verifier
jkopanski Feb 27, 2025
62ad6c0
Changelog entry and docs
jkopanski Mar 4, 2025
ed50d99
Simplify by not requiring contract file path
jkopanski Mar 13, 2025
cd3c00b
Clear unused dependencies
jkopanski Mar 13, 2025
8141fdd
Formatting and typos
jkopanski Mar 13, 2025
c5a8102
Clippy lint
jkopanski Mar 13, 2025
f730ba6
Break up too long function
jkopanski Mar 14, 2025
fc214f6
contract_file is no longer needed
jkopanski Mar 14, 2025
4828923
Revert leftover changes to Cargo.toml
jkopanski Mar 24, 2025
8260a1e
Test if path is empty instead of comparing with new object
jkopanski Mar 24, 2025
96fed1a
Reword message warning about file transfer
jkopanski Mar 24, 2025
3a5664a
Document that `sncast verify` no longer defaults to walnut
jkopanski Mar 24, 2025
af0ad12
Prefer functions over pattern matching
jkopanski Mar 24, 2025
0970892
Add new test with auto confirmation, rename 2 other
jkopanski Mar 24, 2025
aeab4f0
Document changes to verify subcommand flags
jkopanski Mar 24, 2025
4b4fc7a
Replace wrong rpc urls
jkopanski Mar 25, 2025
e922750
Unify {WALNUT,VOYAGER}_API_URL env var
jkopanski Mar 28, 2025
df4b5d7
Tests for new class hash argument
jkopanski Mar 28, 2025
08957a7
Adjust changelog after rebase
jkopanski Mar 29, 2025
a27fd13
rm leftover line
jkopanski Mar 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Cast

#### Added

- `sncast verify` now supports verifying against [voyager](https://voyager.online/) block explorer.

#### Changed

- `verify` command now supports the `--class-hash` for Walnut verification
- `verify` command now supports the `--class-hash` as possible contract identifier

## [0.40.0] - 2025-03-26

Expand Down Expand Up @@ -56,6 +60,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
#### Changed
- gas is now reported using resource bounds triplet (l1_gas, l1_data_gas and l2_gas)
- `available_gas` now accepts named arguments denoting resource bounds (eg #[available_gas(l1_gas: 1, l1_data_gas: 2, l2_gas: 3)])
- `sncast verify` no longer defaults to using walnut.

#### Fixed

Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ toml = "0.8.20"
rpassword = "7.3.1"
promptly = "0.3.1"
ptree = "0.5.2"
reqwest = "0.12.14"
reqwest = { version = "0.12.14", features = ["json"] }
fs_extra = "1.3.0"
openssl = { version = "0.10", features = ["vendored"] }
toml_edit = "0.22.24"
Expand Down
7 changes: 4 additions & 3 deletions crates/sncast/src/starknet_commands/verify/explorer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ pub struct VerificationPayload {
}

#[async_trait::async_trait]
pub trait VerificationInterface {
fn new(network: Network, workspace_dir: Utf8PathBuf) -> Self;
pub trait VerificationInterface: Sized {
fn new(network: Network, workspace_dir: Utf8PathBuf) -> Result<Self>;
async fn verify(
&self,
identifier: ContractIdentifier,
contract_name: String,
package: Option<String>,
) -> Result<VerifyResponse>;
fn gen_explorer_url(&self) -> Result<String>;
fn gen_explorer_url(&self) -> String;
}
36 changes: 27 additions & 9 deletions crates/sncast/src/starknet_commands/verify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ use starknet_types_core::felt::Felt;
use std::{collections::HashMap, fmt};

pub mod explorer;
pub mod voyager;
pub mod walnut;

use explorer::ContractIdentifier;
use explorer::VerificationInterface;
use voyager::Voyager;
use walnut::WalnutVerificationInterface;

#[derive(Args)]
Expand All @@ -35,7 +37,7 @@ pub struct Verify {
pub contract_name: String,

/// Block explorer to use for the verification
#[arg(short, long, value_enum, default_value_t = Verifier::Walnut)]
#[arg(short, long, value_enum)]
pub verifier: Verifier,

/// The network on which block explorer will do the verification
Expand All @@ -54,25 +56,35 @@ pub struct Verify {
#[derive(ValueEnum, Clone, Debug)]
pub enum Verifier {
Walnut,
Voyager,
}

impl fmt::Display for Verifier {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Verifier::Walnut => write!(f, "walnut"),
Verifier::Voyager => write!(f, "voyager"),
}
}
}

pub async fn verify(
verify: Verify,
args: Verify,
manifest_path: &Utf8PathBuf,
artifacts: &HashMap<String, StarknetContractArtifacts>,
) -> Result<VerifyResponse> {
let verifier = verify.verifier;
let Verify {
contract_address,
class_hash,
contract_name,
verifier,
network,
confirm_verification,
package,
} = args;

// Let's ask confirmation
if !verify.confirm_verification {
if !confirm_verification {
let prompt_text = format!(
"\n\tYou are about to submit the entire workspace code to the third-party verifier at {verifier}.\n\n\tImportant: Make sure your project does not include sensitive information like private keys. The snfoundry.toml file will be uploaded. Keep the keystore outside the project to prevent it from being uploaded.\n\n\tAre you sure you want to proceed? (Y/n)"
);
Expand All @@ -83,7 +95,6 @@ pub async fn verify(
}
}

let contract_name = verify.contract_name;
if !artifacts.contains_key(&contract_name) {
return Err(anyhow!("Contract named '{contract_name}' was not found"));
}
Expand All @@ -94,7 +105,7 @@ pub async fn verify(
.parent()
.ok_or(anyhow!("Failed to obtain workspace dir"))?;

let contract_identifier = match (verify.class_hash, verify.contract_address) {
let contract_identifier = match (class_hash, contract_address) {
(Some(class_hash), None) => ContractIdentifier::ClassHash {
class_hash: class_hash.to_fixed_hex_string(),
},
Expand All @@ -109,9 +120,16 @@ pub async fn verify(

match verifier {
Verifier::Walnut => {
let walnut =
WalnutVerificationInterface::new(verify.network, workspace_dir.to_path_buf());
walnut.verify(contract_identifier, contract_name).await
let walnut = WalnutVerificationInterface::new(network, workspace_dir.to_path_buf())?;
walnut
.verify(contract_identifier, contract_name, package)
.await
}
Verifier::Voyager => {
let voyager = Voyager::new(network, workspace_dir.to_path_buf())?;
voyager
.verify(contract_identifier, contract_name, package)
.await
}
}
}
Loading
Loading