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

feat(forge, cast): add RunArgs generate_local_signatures to enable trace with local contracts functions and events #7359

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

Conversation

byteshijinn
Copy link

Motivation

Supply a fast way to add all project contracts functions and events to signatures makes them decode correctly.

Solution

This PR introduces such a possibility using a cli argument --generate-local-signatures for cast run.

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

supportive, though we can solve this a bit differently

lmk if anything's unclear

Comment on lines 86 to 82

#[arg(long, short, alias = "gs")]
pub generate_local_signatures: bool,
Copy link
Member

Choose a reason for hiding this comment

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

This needs docs+explainer

let _ = fs::write_json_file(&path, &cached_signatures);
}
}

handle_traces(result, &config, chain, self.label, self.debug).await?;
Copy link
Member

Choose a reason for hiding this comment

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

perhaps a better solution than doing the preprocess step would be to provide the local signatures here:

so they can be merged with this here

.with_signature_identifier(SignaturesIdentifier::new(
Config::foundry_cache_dir(),
config.offline,
)?)

Copy link
Author

Choose a reason for hiding this comment

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

I implemented it in run.rs to make it optional, and handle_traces as a public method I wanted to change it as little as possible until I understood all others crates package if refered to it.

Copy link
Author

Choose a reason for hiding this comment

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

In fact, it makes more sense for this function to be executed at forge compile time, and it apears in cast run as a shortcut entry to avoid typing the command twice.

Comment on lines 23 to 30
use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};

#[derive(Debug, Default, Serialize, Deserialize)]
struct CachedSignatures {
events: BTreeMap<String, String>,
functions: BTreeMap<String, String>,
}
Copy link
Member

Choose a reason for hiding this comment

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

we already have this type here

#[derive(Debug, Default, Serialize, Deserialize)]
struct CachedSignatures {
events: BTreeMap<String, String>,
functions: BTreeMap<String, String>,
}

we should prevent duplicating this and instead find a way to reuse the existing type

we can make the type pub instead and also make this a helper function:

let identifier = if let Some(cache_path) = cache_path {
let path = cache_path.join("signatures");
trace!(target: "evm::traces", ?path, "reading signature cache");
let cached = if path.is_file() {
fs::read_json_file(&path)
.map_err(|err| warn!(target: "evm::traces", ?path, ?err, "failed to read cache file"))
.unwrap_or_default()
} else {
if let Err(err) = std::fs::create_dir_all(cache_path) {
warn!(target: "evm::traces", "could not create signatures cache dir: {:?}", err);
}
CachedSignatures::default()
};

Copy link
Author

Choose a reason for hiding this comment

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

I defined it again because I find it does not exported. For maintenance reasons, I think you're right. At first I was just using it for myself so I didn't think about it that much, I'll spend some time refactoring the code next.

@byteshijinn
Copy link
Author

I updated my code. please check again @mattsse

@byteshijinn byteshijinn changed the title add RunArgs generate_local_signatures to enable trace with local contracts functions and events feat(forge, cast): add RunArgs generate_local_signatures to enable trace with local contracts functions and events Apr 20, 2024
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.

None yet

2 participants