Skip to content

Commit

Permalink
Fix same contract name issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lok52 committed Nov 29, 2023
1 parent dad4035 commit a8cf95f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use smart_contract_verifier::{
use smart_contract_verifier_proto::blockscout::smart_contract_verifier::v2::{
verify_response::PostActionResponses, LookupMethodsRequest, LookupMethodsResponse,
};
use std::{str::FromStr, sync::Arc};
use std::{collections::HashSet, str::FromStr, sync::Arc};
use tokio::sync::Semaphore;
use tonic::{Request, Response, Status};

Expand Down Expand Up @@ -210,7 +210,7 @@ fn new_bucket(settings: &S3FetcherSettings) -> anyhow::Result<Arc<Bucket>> {

fn process_verify_result(
result: Result<SoliditySuccess, VerificationError>,
post_actions: Vec<VerifyPostAction>,
post_actions: HashSet<VerifyPostAction>,
) -> Result<VerifyResponse, Status> {
match result {
Ok(res) => {
Expand All @@ -236,14 +236,13 @@ fn process_verify_result(

fn process_post_actions(
res: &SoliditySuccess,
post_actions: &Vec<VerifyPostAction>,
post_actions: &HashSet<VerifyPostAction>,
) -> PostActionResponses {
let mut post_actions_responses: PostActionResponses = Default::default();
for action in post_actions {
match action {
VerifyPostAction::LookupMethods => {
let methods =
find_methods_from_compiler_output(&res.contract_name, &res.compiler_output);
let methods = find_methods_from_compiler_output(res);
match methods {
Ok(methods) => {
let response = LookupMethodsResponseWrapper::from(methods);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{collections::HashSet, str::FromStr};

#[derive(PartialEq, Eq, Hash)]
pub enum VerifyPostAction {
LookupMethods,
}
Expand All @@ -14,11 +15,6 @@ impl FromStr for VerifyPostAction {
}
}
}
pub fn parse_post_actions(actions: &[String]) -> anyhow::Result<Vec<VerifyPostAction>> {
actions
.iter()
.collect::<HashSet<_>>()
.into_iter()
.map(|action| action.parse())
.collect()
pub fn parse_post_actions(actions: &[String]) -> anyhow::Result<HashSet<VerifyPostAction>> {
actions.iter().map(|action| action.parse()).collect()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use super::{
disassemble::{disassemble_bytecode, DisassembledOpcode},
method::Method,
};
use crate::SoliditySuccess;
use bytes::Bytes;
use ethers_core::abi::Abi;
use ethers_solc::{sourcemap::SourceMap, CompilerOutput};
use ethers_solc::sourcemap::SourceMap;
use std::{collections::BTreeMap, iter::repeat};

pub struct LookupMethodsRequest {
Expand All @@ -19,24 +20,37 @@ pub struct LookupMethodsResponse {
}

pub fn find_methods_from_compiler_output(
contract_name: &String,
output: &CompilerOutput,
res: &SoliditySuccess,
) -> anyhow::Result<LookupMethodsResponse> {
let file_ids = output
let file_ids = res
.compiler_output
.sources
.iter()
.map(|(name, file)| (file.id, name.clone()))
.collect();

let (_, contract) = output
.contracts_iter()
.find(|(name, _)| *name == contract_name)
let path = &res.file_path;
let file = res
.compiler_output
.contracts
.get(path)
.ok_or_else(|| anyhow::anyhow!("file {path} not found"))?;
let contract_name = &res.contract_name;
let contract = file
.get(&res.contract_name)
.ok_or_else(|| anyhow::anyhow!("contract {contract_name} not found"))?;

let abi = &contract
.abi
.as_ref()
.ok_or_else(|| anyhow::anyhow!("abi missing"))?
.abi;

let evm = contract
.evm
.as_ref()
.ok_or_else(|| anyhow::anyhow!("evm missing"))?;

let deployed_bytecode = evm
.deployed_bytecode
.as_ref()
Expand All @@ -45,6 +59,7 @@ pub fn find_methods_from_compiler_output(
.bytecode
.as_ref()
.ok_or_else(|| anyhow::anyhow!("bytecode missing"))?;

let source_map = bytecode
.source_map()
.ok_or_else(|| anyhow::anyhow!("source map missing"))??;
Expand All @@ -53,11 +68,7 @@ pub fn find_methods_from_compiler_output(
.as_bytes()
.ok_or_else(|| anyhow::anyhow!("invalid bytecode"))?
.0;
let abi = &contract
.abi
.as_ref()
.ok_or_else(|| anyhow::anyhow!("abi missing"))?
.abi;

let methods = parse_selectors(abi);

Ok(find_methods_internal(
Expand Down

0 comments on commit a8cf95f

Please sign in to comment.