Skip to content

feat(forge): eip712 with solar #10510

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

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0a6982a
wip
0xrusowsky May 9, 2025
76fa60e
feat: eip712 type hash PoC
0xrusowsky May 9, 2025
4aeaceb
style: json
0xrusowsky May 9, 2025
d031f04
style: json
0xrusowsky May 9, 2025
078438b
style: json
0xrusowsky May 9, 2025
a9c5ea1
style: comments
0xrusowsky May 9, 2025
44fc6c3
wip
0xrusowsky May 12, 2025
2748946
initial impl using solar
0xrusowsky May 13, 2025
c752df6
fix: untracked change
0xrusowsky May 13, 2025
6cfc2f5
fix: optimize resolve_type
0xrusowsky May 13, 2025
027581c
initial working impl
0xrusowsky May 13, 2025
d1de66c
feat: eip712 solar resolver
0xrusowsky May 13, 2025
2ee28c6
style: docs + fmt + clippy
0xrusowsky May 13, 2025
d270789
todo: cheatcode
0xrusowsky May 13, 2025
b444a5b
docs: comments
0xrusowsky May 13, 2025
8f6bfcc
fix: use HIR rather than AST
0xrusowsky May 14, 2025
bb0d09b
from build opts
0xrusowsky May 14, 2025
864a0f4
docs
0xrusowsky May 14, 2025
491b7f0
fix: rmv hashset
0xrusowsky May 14, 2025
695d1ae
create utils for solar_pcx_from_build_opts
0xrusowsky May 14, 2025
85b8d31
incorporate version logic into `solar_pcx_from_build_opts`
0xrusowsky May 14, 2025
6d35756
wip bind-json: eip712 resolver integration
0xrusowsky May 15, 2025
00bb04d
forge(bind-json): integrate solar
0xrusowsky May 16, 2025
924516c
fix: tests
0xrusowsky May 16, 2025
c4872f1
Merge branch 'master' into feat/eip712-with-solar
0xrusowsky May 16, 2025
df74d85
style: clippy
0xrusowsky May 16, 2025
eeeb40e
undo cheatcode setup (will tackle it on its own PR)
0xrusowsky May 16, 2025
c259a17
rmv old test
0xrusowsky May 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 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 @@ -194,6 +194,7 @@ foundry-fork-db = "0.12"
solang-parser = "=0.3.3"
solar-parse = { version = "=0.1.2", default-features = false }
solar-sema = { version = "=0.1.2", default-features = false }
solar-interface = { version = "=0.1.2", default-features = false }

## revm
revm = { version = "19.4.0", default-features = false }
Expand Down
4 changes: 3 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ foundry-config.workspace = true
foundry-debugger.workspace = true
foundry-evm.workspace = true
foundry-wallets.workspace = true
foundry-block-explorers.workspace = true

foundry-compilers = { workspace = true, features = ["full"] }
foundry-block-explorers.workspace = true
solar-sema.workspace = true

alloy-eips.workspace = true
alloy-dyn-abi.workspace = true
Expand Down Expand Up @@ -50,6 +51,7 @@ tracing-subscriber = { workspace = true, features = ["registry", "env-filter"] }
tracing.workspace = true
yansi.workspace = true
rustls = { workspace = true, features = ["ring"] }
dunce.workspace = true

tracing-tracy = { version = "0.11", optional = true }

Expand Down
3 changes: 3 additions & 0 deletions crates/cli/src/opts/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pub use self::core::BuildOpts;
mod paths;
pub use self::paths::ProjectPathOpts;

mod utils;
pub use self::utils::{solar_pcx_from_build_opts, solar_pcx_from_solc_project};

// A set of solc compiler settings that can be set via command line arguments, which are intended
// to be merged into an existing `foundry_config::Config`.
//
Expand Down
105 changes: 105 additions & 0 deletions crates/cli/src/opts/build/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
use crate::{opts::BuildOpts, utils::LoadConfig};

use eyre::Result;
use foundry_compilers::{
artifacts::{Source, Sources},
multi::{MultiCompilerLanguage, MultiCompilerParsedSource},
solc::{SolcLanguage, SolcVersionedInput},
CompilerInput, Graph, Project,
};
use solar_sema::{interface::Session, ParsingContext};
use std::path::PathBuf;

/// Builds a Solar [`solar_sema::ParsingContext`] from [`BuildOpts`].
///
/// * Configures include paths, remappings and registers all in-memory sources so that solar can
/// operate without touching disk.
/// * If no `target_paths` are provided, all project files are processed.
/// * Only processes the subset of sources with the most up-to-date Solitidy version.
pub fn solar_pcx_from_build_opts<'sess>(
sess: &'sess Session,
build: BuildOpts,
target_paths: Option<Vec<PathBuf>>,
) -> Result<ParsingContext<'sess>> {
// Process build options
let config = build.load_config()?;
let project = config.ephemeral_project()?;

let sources = match target_paths {
// If target files are provided, only process those sources
Some(targets) => {
let mut sources = Sources::new();
for t in targets.into_iter() {
let path = dunce::canonicalize(t)?;
let source = Source::read(&path)?;
sources.insert(path, source);
}
sources
}
// Otherwise, process all project files
None => project.paths.read_input_files()?,
};

// Only process sources with latest Solidity version to avoid conflicts.
let graph = Graph::<MultiCompilerParsedSource>::resolve_sources(&project.paths, sources)?;
let (version, sources, _) = graph
// resolve graph into mapping language -> version -> sources
.into_sources_by_version(&project)?
.sources
.into_iter()
// only interested in Solidity sources
.find(|(lang, _)| *lang == MultiCompilerLanguage::Solc(SolcLanguage::Solidity))
.ok_or_else(|| eyre::eyre!("no Solidity sources"))?
.1
.into_iter()
// always pick the latest version
.max_by(|(v1, _, _), (v2, _, _)| v1.cmp(v2))
.unwrap();

let solc = SolcVersionedInput::build(
sources,
config.solc_settings()?,
SolcLanguage::Solidity,
version,
);

Ok(solar_pcx_from_solc_project(sess, &project, &solc, true))
}

/// Builds a Solar [`solar_sema::ParsingContext`] from a [`foundry_compilers::Project`] and a
/// [`SolcVersionedInput`].
///
/// * Configures include paths, remappings.
/// * Soruce files can be manually added if the param `add_source_file` is set to `false`.

Check failure on line 73 in crates/cli/src/opts/build/utils.rs

View workflow job for this annotation

GitHub Actions / codespell

Soruce ==> Source, Spruce
pub fn solar_pcx_from_solc_project<'sess>(
sess: &'sess Session,
project: &Project,
solc: &SolcVersionedInput,
add_source_files: bool,
) -> ParsingContext<'sess> {
// Configure the parsing context with the paths, remappings and sources
let mut pcx = ParsingContext::new(sess);

pcx.file_resolver
.set_current_dir(solc.cli_settings.base_path.as_ref().unwrap_or(&project.paths.root));
for remapping in &project.paths.remappings {
pcx.file_resolver.add_import_remapping(solar_sema::interface::config::ImportRemapping {
context: remapping.context.clone().unwrap_or_default(),
prefix: remapping.name.clone(),
path: remapping.path.clone(),
});
}
pcx.file_resolver.add_include_paths(solc.cli_settings.include_paths.iter().cloned());

if add_source_files {
for (path, source) in &solc.input.sources {
if let Ok(src_file) =
sess.source_map().new_source_file(path.clone(), source.content.as_str())
{
pcx.add_file(src_file);
}
}
}

pcx
}
2 changes: 2 additions & 0 deletions crates/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ serde_json.workspace = true
similar = { version = "2", features = ["inline"] }
solang-parser.workspace = true
solar-parse.workspace = true
solar-sema.workspace = true
solar-interface.workspace = true
strum = { workspace = true, features = ["derive"] }
thiserror.workspace = true
tokio = { workspace = true, features = ["time"] }
Expand Down
Loading
Loading