Skip to content

feat(forge): cheatcode eip712 #10570

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

Merged
merged 24 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
70827ae
wip: eip712 cheacode
0xrusowsky May 19, 2025
ef3c1b9
wip: integrate json-bind
0xrusowsky May 20, 2025
e69ddd7
Merge branch 'master' of github.com:foundry-rs/foundry into chore/che…
0xrusowsky May 20, 2025
d1e1512
finish cheatcode impl + unit tests
0xrusowsky May 20, 2025
9ea76dc
fix: merge conflicts
0xrusowsky May 20, 2025
cf67c2c
style: clippy + fmt
0xrusowsky May 20, 2025
88fb7be
fix: simple example + bump alloy core + docs
0xrusowsky May 20, 2025
a6cca9a
fix: cheats spec
0xrusowsky May 20, 2025
5bcccbc
Merge branch 'feat/eip712-with-solar' into chore/cheat-eip712
grandizzy May 22, 2025
4395b32
load json bindings from foundry.toml + allow custom path + extend tests
0xrusowsky May 22, 2025
cbabab3
style: fmt
0xrusowsky May 22, 2025
7f64f72
fix: test assertion for win
0xrusowsky May 22, 2025
7ff2758
test: custom path
0xrusowsky May 22, 2025
c057902
fix: custom path without being the configured one in `foundry.toml`
0xrusowsky May 22, 2025
c6f037d
fix: use calldata instead of memory in cheatcode fns
0xrusowsky May 22, 2025
4b23502
chore(forge): cheat eip712 struct hash (#10626)
0xrusowsky May 29, 2025
876b7ba
new cheat: eip712 hash typed data
0xrusowsky May 29, 2025
f8dddb6
bump solar and compilers
0xrusowsky May 29, 2025
2c07808
fix: failing compiler test
0xrusowsky May 29, 2025
cac75c3
bump compiler and explorers + patch vyper prague -> cancun
0xrusowsky May 29, 2025
b998d0e
style: clippy
0xrusowsky May 29, 2025
452cbce
fix: check for `.vyi` paths
0xrusowsky May 29, 2025
ce7948f
style: simplify
0xrusowsky May 29, 2025
d35f498
style: simplify
0xrusowsky May 29, 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
829 changes: 429 additions & 400 deletions Cargo.lock

Large diffs are not rendered by default.

28 changes: 11 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,13 @@ foundry-wallets = { path = "crates/wallets" }
foundry-linking = { path = "crates/linking" }

# solc & compilation utilities
foundry-block-explorers = { version = "0.17.0", default-features = false }
foundry-compilers = { version = "0.16.1", default-features = false }
foundry-block-explorers = { version = "0.18.0", default-features = false }
foundry-compilers = { version = "0.17.0", default-features = false }
foundry-fork-db = "0.14"
solang-parser = { version = "=0.3.8", package = "foundry-solang-parser" }
solar-parse = { version = "=0.1.3", default-features = false }
solar-sema = { version = "=0.1.3", default-features = false }
solar-interface = { version = "=0.1.3", default-features = false }

solar-parse = { version = "=0.1.4", default-features = false }
solar-sema = { version = "=0.1.4", default-features = false }
solar-interface = { version = "=0.1.4", default-features = false }

## alloy
alloy-consensus = { version = "1.0.5", default-features = false }
Expand All @@ -229,17 +228,17 @@ alloy-transport-ipc = { version = "1.0.5", default-features = false }
alloy-transport-ws = { version = "1.0.5", default-features = false }

## alloy-core
alloy-dyn-abi = "1.0"
alloy-json-abi = "1.0"
alloy-primitives = { version = "1.0", features = [
alloy-dyn-abi = "1.1.2"
alloy-json-abi = "1.1.2"
alloy-primitives = { version = "1.1.2", features = [
"getrandom",
"rand",
"map-fxhash",
"map-foldhash",
] }
alloy-sol-macro-expander = "1.0"
alloy-sol-macro-input = "1.0"
alloy-sol-types = "1.0"
alloy-sol-macro-expander = "1.1.2"
alloy-sol-macro-input = "1.1.2"
alloy-sol-types = "1.1.2"

alloy-chains = "0.2"
alloy-rlp = "0.3"
Expand Down Expand Up @@ -393,10 +392,5 @@ revm = { git = "https://github.com/bluealloy/revm.git", rev = "b5808253" }
op-revm = { git = "https://github.com/bluealloy/revm.git", rev = "b5808253" }
# revm-inspectors = { git = "https://github.com/paradigmxyz/revm-inspectors.git", rev = "a625c04" }

## solar
solar-parse = { git = "https://github.com/paradigmxyz/solar.git", branch = "dani/resolver-absolute-paths" }
solar-sema = { git = "https://github.com/paradigmxyz/solar.git", branch = "dani/resolver-absolute-paths" }
solar-interface = { git = "https://github.com/paradigmxyz/solar.git", branch = "dani/resolver-absolute-paths" }

## foundry
# foundry-fork-db = { git = "https://github.com/foundry-rs/foundry-fork-db", rev = "811a61a" }
3 changes: 2 additions & 1 deletion crates/anvil/core/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct Params<T: Default> {
/// Represents ethereum JSON-RPC API
#[derive(Clone, Debug, serde::Deserialize)]
#[serde(tag = "method", content = "params")]
#[allow(clippy::large_enum_variant)]
pub enum EthRequest {
#[serde(rename = "web3_clientVersion", with = "empty_params")]
Web3ClientVersion(()),
Expand Down Expand Up @@ -640,7 +641,7 @@ pub enum EthRequest {

/// Add an address to the [`DelegationCapability`] of the wallet
///
/// [`DelegationCapability`]: wallet::DelegationCapability
/// [`DelegationCapability`]: wallet::DelegationCapability
#[serde(rename = "anvil_addCapability", with = "sequence")]
AnvilAddCapability(Address),

Expand Down
100 changes: 100 additions & 0 deletions crates/cheatcodes/assets/cheatcodes.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions crates/cheatcodes/spec/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2888,6 +2888,55 @@ interface Vm {
/// catch (bytes memory interceptedInitcode) { initcode = interceptedInitcode; }
#[cheatcode(group = Utilities, safety = Unsafe)]
function interceptInitcode() external;

/// Generates the hash of the canonical EIP-712 type representation.
///
/// Supports 2 different inputs:
/// 1. Name of the type (i.e. "Transaction"):
/// * requires previous binding generation with `forge bind-json`.
/// * bindings will be retrieved from the path configured in `foundry.toml`.
///
/// 2. String representation of the type (i.e. "Foo(Bar bar) Bar(uint256 baz)").
/// * Note: the cheatcode will output the canonical type even if the input is malformated
/// with the wrong order of elements or with extra whitespaces.
#[cheatcode(group = Utilities)]
function eip712HashType(string calldata typeNameOrDefinition) external pure returns (bytes32 typeHash);

/// Generates the hash of the canonical EIP-712 type representation.
/// Requires previous binding generation with `forge bind-json`.
///
/// Params:
/// * `bindingsPath`: path where the output of `forge bind-json` is stored.
/// * `typeName`: Name of the type (i.e. "Transaction").
#[cheatcode(group = Utilities)]
function eip712HashType(string calldata bindingsPath, string calldata typeName) external pure returns (bytes32 typeHash);

/// Generates the struct hash of the canonical EIP-712 type representation and its abi-encoded data.
///
/// Supports 2 different inputs:
/// 1. Name of the type (i.e. "PermitSingle"):
/// * requires previous binding generation with `forge bind-json`.
/// * bindings will be retrieved from the path configured in `foundry.toml`.
///
/// 2. String representation of the type (i.e. "Foo(Bar bar) Bar(uint256 baz)").
/// * Note: the cheatcode will use the canonical type even if the input is malformated
/// with the wrong order of elements or with extra whitespaces.
#[cheatcode(group = Utilities)]
function eip712HashStruct(string calldata typeNameOrDefinition, bytes calldata abiEncodedData) external pure returns (bytes32 typeHash);

/// Generates the struct hash of the canonical EIP-712 type representation and its abi-encoded data.
/// Requires previous binding generation with `forge bind-json`.
///
/// Params:
/// * `bindingsPath`: path where the output of `forge bind-json` is stored.
/// * `typeName`: Name of the type (i.e. "PermitSingle").
/// * `abiEncodedData`: ABI-encoded data for the struct that is being hashed.
#[cheatcode(group = Utilities)]
function eip712HashStruct(string calldata bindingsPath, string calldata typeName, bytes calldata abiEncodedData) external pure returns (bytes32 typeHash);

/// Generates a ready-to-sign digest of human-readable typed data following the EIP-712 standard.
#[cheatcode(group = Utilities)]
function eip712HashTypedData(string calldata jsonData) external pure returns (bytes32 digest);
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/cheatcodes/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub struct CheatsConfig {
pub rpc_endpoints: ResolvedRpcEndpoints,
/// Project's paths as configured
pub paths: ProjectPathsConfig,
/// Path to the directory that contains the bindings generated by `forge bind-json`.
pub bind_json_path: PathBuf,
/// Filesystem permissions for cheatcodes like `writeFile`, `readFile`
pub fs_permissions: FsPermissions,
/// Project root
Expand Down Expand Up @@ -98,6 +100,7 @@ impl CheatsConfig {
no_storage_caching: config.no_storage_caching,
rpc_endpoints,
paths: config.project_paths(),
bind_json_path: config.bind_json.out.clone(),
fs_permissions: config.fs_permissions.clone().joined(config.root.as_ref()),
root: config.root.clone(),
broadcast: config.root.clone().join(&config.broadcast),
Expand Down Expand Up @@ -303,6 +306,7 @@ impl Default for CheatsConfig {
paths: ProjectPathsConfig::builder().build_with_root("./"),
fs_permissions: Default::default(),
root: Default::default(),
bind_json_path: PathBuf::default().join("utils").join("jsonBindings.sol"),
broadcast: Default::default(),
allowed_paths: vec![],
evm_opts: Default::default(),
Expand Down
Loading