-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: add Sourcify support to TraceIdentifiers #11817
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
267d9d0
Add Sourcify support to TraceIdentifiers
silvekkk 92e7f6d
Merge branch 'master' into helpIssue
grandizzy 34df55b
simply code
silvekkk 2525258
fix typos
silvekkk ed52eb6
add test
silvekkk dcaff0e
fix test and ci
silvekkk b3602fb
Refactor to fix ci
silvekkk 18a1138
Merge branch 'master' into helpIssue
silvekkk d1144b7
using APIv2 & replace test
silvekkk c89fde1
make chain id configurable
silvekkk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use super::{IdentifiedAddress, TraceIdentifier}; | ||
use alloy_json_abi::JsonAbi; | ||
use revm_inspectors::tracing::types::CallTraceNode; | ||
use serde::Deserialize; | ||
use std::borrow::Cow; | ||
|
||
#[derive(Deserialize)] | ||
struct SourceifyFile { | ||
name: String, | ||
content: String, | ||
} | ||
|
||
/// A trace identifier that uses Sourcify to identify contract ABIs. | ||
pub struct SourceifyIdentifier; | ||
|
||
impl SourceifyIdentifier { | ||
silvekkk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
pub fn new() -> Self { | ||
Self | ||
} | ||
} | ||
|
||
impl Default for SourceifyIdentifier { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl TraceIdentifier for SourceifyIdentifier { | ||
fn identify_addresses(&mut self, nodes: &[&CallTraceNode]) -> Vec<IdentifiedAddress<'_>> { | ||
let mut identities = Vec::new(); | ||
|
||
for &node in nodes { | ||
let address = node.trace.address; | ||
|
||
// Try to get ABI from Sourcify | ||
let abi = foundry_common::block_on(async { | ||
let client = reqwest::Client::new(); | ||
silvekkk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
let url = format!("https://repo.sourcify.dev/contracts/full_match/1/{address:?}/"); | ||
silvekkk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
let files: Vec<SourceifyFile> = | ||
client.get(&url).send().await.ok()?.json().await.ok()?; | ||
|
||
for file in files { | ||
silvekkk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if file.name == "metadata.json" { | ||
let metadata: serde_json::Value = | ||
serde_json::from_str(&file.content).ok()?; | ||
let abi_value = metadata.get("output")?.get("abi")?; | ||
return serde_json::from_value::<JsonAbi>(abi_value.clone()).ok(); | ||
} | ||
} | ||
None | ||
}); | ||
|
||
if let Some(abi) = abi { | ||
identities.push(IdentifiedAddress { | ||
address, | ||
label: Some("Sourcify".to_string()), | ||
contract: Some("Sourcify".to_string()), | ||
abi: Some(Cow::Owned(abi)), | ||
artifact_id: None, | ||
}); | ||
} | ||
} | ||
|
||
identities | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.