Skip to content

Commit

Permalink
Contract verification (foundry-rs#2252)
Browse files Browse the repository at this point in the history
Closes foundry-rs#892 

## Introduced changes

This PR builds upon the changes introduced in PR foundry-rs#875. The original PR
is still open because the Voyager APIs are not ready yet, but we require
the verification feature for the Walnut Debugger. To accommodate this,
we have incorporated the changes from PR foundry-rs#875 and made the following
additions:
* Introduced the `WalnutVerificationInterface`.
* Resolved branch conflicts.
* Made minor modifications to ensure compatibility.

Furthermore, to make the PR merge-ready, we have temporarily removed the
Voyager and Starkscan interfaces since their respective APIs are not
currently available. New verification interfaces can be added once
Voyager, Starkscan, or any other provider adds API support for Cairo
contract verification.

This Pull Request adds the verify command for the contract verification.
More about the details of the contract verification can found
[here](https://github.com/foundry-rs/starknet-foundry/blob/master/design_documents/contract_verification.md).

* Added `verify` command to the `sncast` tool
* Modified `cast/main.rs` & created
`cast/src/starknet_commands/verify.rs` mainly

## Checklist

- [x] Linked relevant issue
- [x] Updated relevant documentation
- [x] Added relevant tests
- [x] Performed self-review of the code
- [x] Added changes to `CHANGELOG.md`

---------

Co-authored-by: MBarwicki <[email protected]>
Co-authored-by: Rohit Ranjan <[email protected]>
Co-authored-by: Tomasz Rejowski <[email protected]>
Co-authored-by: Karol Sewiło <[email protected]>
  • Loading branch information
5 people authored Jul 9, 2024
1 parent a128991 commit c633861
Show file tree
Hide file tree
Showing 13 changed files with 736 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Cast

#### Added

- `verify` subcommand to verify contract (walnut APIs supported as of this version). [Read more here](./docs/src/appendix/sncast/verify.md)

## [0.26.0] - 2024-07-03

### Forge
Expand Down
85 changes: 83 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,4 @@ base16ct = { version = "0.2.0", features = ["alloc"] }
fs4 = "0.7"
async-trait = "0.1.80"
serde_path_to_error = "0.1.16"
wiremock = "0.6.0"
2 changes: 2 additions & 0 deletions crates/sncast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ base16ct.workspace = true
starknet-crypto.workspace = true
async-trait.workspace = true
serde_path_to_error.workspace = true
walkdir.workspace = true

[dev-dependencies]
ctor.workspace = true
Expand All @@ -56,6 +57,7 @@ project-root.workspace = true
tempfile.workspace = true
test-case.workspace = true
fs_extra.workspace = true
wiremock.workspace = true

[[bin]]
name = "sncast"
Expand Down
8 changes: 8 additions & 0 deletions crates/sncast/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{anyhow, bail, Context, Error, Result};
use camino::Utf8PathBuf;
use clap::ValueEnum;
use helpers::constants::{KEYSTORE_PASSWORD_ENV_VAR, UDC_ADDRESS};
use rand::rngs::OsRng;
use rand::RngCore;
Expand Down Expand Up @@ -61,6 +62,13 @@ impl FromStr for AccountType {
}
}
}

#[derive(ValueEnum, Clone, Debug)]
pub enum Network {
Mainnet,
Sepolia,
}

#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct AccountData {
pub private_key: FieldElement,
Expand Down
30 changes: 30 additions & 0 deletions crates/sncast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use sncast::{
use starknet::core::utils::get_selector_from_name;
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::JsonRpcClient;
use starknet_commands::verify::Verify;
use tokio::runtime::Runtime;

mod starknet_commands;
Expand Down Expand Up @@ -141,6 +142,9 @@ enum Commands {

/// Get the status of a transaction
TxStatus(TxStatus),

/// Verify a contract
Verify(Verify),
}

fn main() -> Result<()> {
Expand Down Expand Up @@ -426,6 +430,32 @@ async fn run_async_command(
print_command_result("tx-status", &mut result, numbers_format, &output_format)?;
Ok(())
}
Commands::Verify(verify) => {
let manifest_path = assert_manifest_path_exists()?;
let package_metadata = get_package_metadata(&manifest_path, &verify.package)?;
let artifacts = build_and_load_artifacts(
&package_metadata,
&BuildConfig {
scarb_toml_path: manifest_path.clone(),
json: cli.json,
profile: cli.profile.unwrap_or("dev".to_string()),
},
)
.expect("Failed to build contract");
let mut result = starknet_commands::verify::verify(
verify.contract_address,
verify.contract_name,
verify.verifier,
verify.network,
verify.confirm_verification,
&package_metadata.manifest_path,
&artifacts,
)
.await;

print_command_result("verify", &mut result, numbers_format, &output_format)?;
Ok(())
}
Commands::Script(_) => unreachable!(),
}
}
Expand Down
7 changes: 7 additions & 0 deletions crates/sncast/src/response/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,10 @@ pub struct TransactionStatusResponse {
}

impl CommandResponse for TransactionStatusResponse {}

#[derive(Serialize)]
pub struct VerifyResponse {
pub message: String,
}

impl CommandResponse for VerifyResponse {}
1 change: 1 addition & 0 deletions crates/sncast/src/starknet_commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pub mod multicall;
pub mod script;
pub mod show_config;
pub mod tx_status;
pub mod verify;
Loading

0 comments on commit c633861

Please sign in to comment.