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

Add voyager verification to the verify command #2566

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

cwkang1998
Copy link

@cwkang1998 cwkang1998 commented Oct 7, 2024

This is a follow up PR to complete changes that #2288 wants to introduce.

Closes #2287

Introduced changes

Additional context on a possible edge case

As Voyager backend limits the http alive time to less than 30s, given a large contract which compilation might take longer, we might have to have the compilation task run asynchronously in order and have the status polled. This is currently not implemented in this PR as testing is being done to see if this is significant enough of a problem to be addressed this way.

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Performed self-review of the code
  • Added changes to CHANGELOG.md

Will complete this checklist after another self review.

@cwkang1998 cwkang1998 changed the title Add Voyager as a contract verifier Add voyager verification interface to the verify command Oct 7, 2024
@cwkang1998 cwkang1998 changed the title Add voyager verification interface to the verify command Add voyager verification to the verify command Oct 7, 2024
@cwkang1998
Copy link
Author

cwkang1998 commented Oct 10, 2024

Addressing some of @integraledelebesgue comments from #2288

#[async_trait] attribute is not required #2288 (comment)

Seems that its failing to compile without the macro. Any alternatives you might have had in your mind?

Please add descriptions of all parameters to display in help

We would like to unify the wole configuration to a TOML file. Could you please redesign the url acquisition logic to use an enum provied via CastConfig rather than an environmental variable?

Both implementations of this method are identical. You can make it a default implementation

Sure

  1. Similarly to verify, implementations of this method differ only with the url source. How about introducing a new trait method, let's say get_base_url, implementing it manually on both types and using in a default implementation of gen_explorer_url?
  2. This method never fails. Are there any reasons for it to return a Result?
    refactor verification crate & add voyager interface  #2288 (comment)
  1. I'll try that out.
  2. I don't think so, removing it.

@cwkang1998
Copy link
Author

cwkang1998 commented Oct 12, 2024

Successfully made some of the methods default, and remove the need of using a base struct inside each concrete verification interface struct.

Since the verification provider api is constructed slightly differently, I don't think that replacinggen_explorer_url is a valid choice anymore since the last review. However, I did still move the configuration for the custom base api url to CastConfig as suggested.

Will move on to update the current tests tomorrow.

@cwkang1998
Copy link
Author

Tests updated! Reviews would be appreciated.

@piotmag769
Copy link
Member

cc @cptartur

Copy link
Member

@cptartur cptartur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for contributing. I think some parts may be improved.

Also, I haven't reviewed the tests yet but will do soon.

Comment on lines +12 to +14
#### Added
- Add Voyager API support for `verify` subcommand [Read more here](https://foundry-rs.github.io/starknet-foundry/appendix/sncast/verify.html).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### Added
- Add Voyager API support for `verify` subcommand [Read more here](https://foundry-rs.github.io/starknet-foundry/appendix/sncast/verify.html).
#### Added
- Voyager API support for `verify` subcommand [Read more here](https://foundry-rs.github.io/starknet-foundry/appendix/sncast/verify.html).


#[async_trait]
pub trait VerificationInterface {
fn get_workspace_dir(&self) -> Utf8PathBuf;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be a part of trait. I think all verification providers will want to handle it the same so there's no point abstracting it like that.

I'd simply change verify signature so it takes this directory as well.

Additionally read_workspace_files should be removed from this trait and should be made a free function that takes directory as an argument.

Comment on lines +44 to +69
async fn send_verification_request(
&self,
url: String,
payload: VerificationPayload,
) -> Result<VerifyResponse> {
let json_payload = serde_json::to_string(&payload)?;
let client = reqwest::Client::new();
let api_res = client
.post(url)
.header("Content-Type", "application/json")
.body(json_payload)
.send()
.await
.context("Failed to send request to verifier API")?;

if api_res.status() == StatusCode::OK {
let message = api_res
.text()
.await
.context("Failed to read verifier API response")?;
Ok(VerifyResponse { message })
} else {
let message = api_res.text().await.context("Failed to verify contract")?;
Err(anyhow!(message))
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't using self anyway, I'd just make it a normal function.

Comment on lines +50 to +58
#[serde(
default,
rename(
serialize = "verification-base-url",
deserialize = "verification-base-url"
)
)]
/// Custom base url to be used for verification
pub verification_base_url: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to allow overriding the URL, I think it should be done only in verify subcommand arguments not in a global configuration.

@@ -7,4 +7,4 @@ pub mod multicall;
pub mod script;
pub mod show_config;
pub mod tx_status;
pub mod verify;
pub mod verification;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't rename that. Modules in starknet_commands generally follow the name of the commands they are related to.

pub trait VerificationInterface {
fn get_workspace_dir(&self) -> Utf8PathBuf;

fn gen_explorer_url(&self, config: CastConfig) -> String;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of having an config argument, implementations should take a base url and network arguments when being created with new.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way usage is much simpler: provide an relevant override of gen_explorer_url that forms correct urls from information you have and verify can use it without providing anything.


The address of the contract that is to be verified.

## `--class-name <CONTRACT_NAME>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we renaming this?

Comment on lines +92 to +95
// ensure that either contract_address or class_hash is provided
if contract_address.is_none() && class_hash.is_none() {
bail!("Either contract_address or class_hash must be provided");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be done at clap level with ArgGroup and flatten

Take a look at this: https://stackoverflow.com/questions/76315540/how-do-i-require-one-of-the-two-clap-options

Comment on lines +10 to +13
## `--class-hash, -c <CONTRACT_ADDRESS>`
Required.

The address of the contract that is to be verified.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also say that this conflicts with the other argument and exactly one is required.

@cptartur cptartur self-requested a review October 18, 2024 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add voyager verification interface to the verify command
4 participants