Skip to content

Commit 9f0b62c

Browse files
authored
feat(forge): eip712 cheatcodes (#10570)
1 parent 3a5abac commit 9f0b62c

File tree

12 files changed

+1333
-425
lines changed

12 files changed

+1333
-425
lines changed

Cargo.lock

Lines changed: 429 additions & 400 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,13 @@ foundry-wallets = { path = "crates/wallets" }
196196
foundry-linking = { path = "crates/linking" }
197197

198198
# solc & compilation utilities
199-
foundry-block-explorers = { version = "0.17.0", default-features = false }
200-
foundry-compilers = { version = "0.16.1", default-features = false }
199+
foundry-block-explorers = { version = "0.18.0", default-features = false }
200+
foundry-compilers = { version = "0.17.0", default-features = false }
201201
foundry-fork-db = "0.14"
202202
solang-parser = { version = "=0.3.8", package = "foundry-solang-parser" }
203-
solar-parse = { version = "=0.1.3", default-features = false }
204-
solar-sema = { version = "=0.1.3", default-features = false }
205-
solar-interface = { version = "=0.1.3", default-features = false }
206-
203+
solar-parse = { version = "=0.1.4", default-features = false }
204+
solar-sema = { version = "=0.1.4", default-features = false }
205+
solar-interface = { version = "=0.1.4", default-features = false }
207206

208207
## alloy
209208
alloy-consensus = { version = "1.0.5", default-features = false }
@@ -229,17 +228,17 @@ alloy-transport-ipc = { version = "1.0.5", default-features = false }
229228
alloy-transport-ws = { version = "1.0.5", default-features = false }
230229

231230
## alloy-core
232-
alloy-dyn-abi = "1.0"
233-
alloy-json-abi = "1.0"
234-
alloy-primitives = { version = "1.0", features = [
231+
alloy-dyn-abi = "1.1.2"
232+
alloy-json-abi = "1.1.2"
233+
alloy-primitives = { version = "1.1.2", features = [
235234
"getrandom",
236235
"rand",
237236
"map-fxhash",
238237
"map-foldhash",
239238
] }
240-
alloy-sol-macro-expander = "1.0"
241-
alloy-sol-macro-input = "1.0"
242-
alloy-sol-types = "1.0"
239+
alloy-sol-macro-expander = "1.1.2"
240+
alloy-sol-macro-input = "1.1.2"
241+
alloy-sol-types = "1.1.2"
243242

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

396-
## solar
397-
solar-parse = { git = "https://github.com/paradigmxyz/solar.git", branch = "dani/resolver-absolute-paths" }
398-
solar-sema = { git = "https://github.com/paradigmxyz/solar.git", branch = "dani/resolver-absolute-paths" }
399-
solar-interface = { git = "https://github.com/paradigmxyz/solar.git", branch = "dani/resolver-absolute-paths" }
400-
401395
## foundry
402396
# foundry-fork-db = { git = "https://github.com/foundry-rs/foundry-fork-db", rev = "811a61a" }

crates/anvil/core/src/eth/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub struct Params<T: Default> {
3535
/// Represents ethereum JSON-RPC API
3636
#[derive(Clone, Debug, serde::Deserialize)]
3737
#[serde(tag = "method", content = "params")]
38+
#[allow(clippy::large_enum_variant)]
3839
pub enum EthRequest {
3940
#[serde(rename = "web3_clientVersion", with = "empty_params")]
4041
Web3ClientVersion(()),
@@ -640,7 +641,7 @@ pub enum EthRequest {
640641

641642
/// Add an address to the [`DelegationCapability`] of the wallet
642643
///
643-
/// [`DelegationCapability`]: wallet::DelegationCapability
644+
/// [`DelegationCapability`]: wallet::DelegationCapability
644645
#[serde(rename = "anvil_addCapability", with = "sequence")]
645646
AnvilAddCapability(Address),
646647

crates/cheatcodes/assets/cheatcodes.json

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cheatcodes/spec/src/vm.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2888,6 +2888,55 @@ interface Vm {
28882888
/// catch (bytes memory interceptedInitcode) { initcode = interceptedInitcode; }
28892889
#[cheatcode(group = Utilities, safety = Unsafe)]
28902890
function interceptInitcode() external;
2891+
2892+
/// Generates the hash of the canonical EIP-712 type representation.
2893+
///
2894+
/// Supports 2 different inputs:
2895+
/// 1. Name of the type (i.e. "Transaction"):
2896+
/// * requires previous binding generation with `forge bind-json`.
2897+
/// * bindings will be retrieved from the path configured in `foundry.toml`.
2898+
///
2899+
/// 2. String representation of the type (i.e. "Foo(Bar bar) Bar(uint256 baz)").
2900+
/// * Note: the cheatcode will output the canonical type even if the input is malformated
2901+
/// with the wrong order of elements or with extra whitespaces.
2902+
#[cheatcode(group = Utilities)]
2903+
function eip712HashType(string calldata typeNameOrDefinition) external pure returns (bytes32 typeHash);
2904+
2905+
/// Generates the hash of the canonical EIP-712 type representation.
2906+
/// Requires previous binding generation with `forge bind-json`.
2907+
///
2908+
/// Params:
2909+
/// * `bindingsPath`: path where the output of `forge bind-json` is stored.
2910+
/// * `typeName`: Name of the type (i.e. "Transaction").
2911+
#[cheatcode(group = Utilities)]
2912+
function eip712HashType(string calldata bindingsPath, string calldata typeName) external pure returns (bytes32 typeHash);
2913+
2914+
/// Generates the struct hash of the canonical EIP-712 type representation and its abi-encoded data.
2915+
///
2916+
/// Supports 2 different inputs:
2917+
/// 1. Name of the type (i.e. "PermitSingle"):
2918+
/// * requires previous binding generation with `forge bind-json`.
2919+
/// * bindings will be retrieved from the path configured in `foundry.toml`.
2920+
///
2921+
/// 2. String representation of the type (i.e. "Foo(Bar bar) Bar(uint256 baz)").
2922+
/// * Note: the cheatcode will use the canonical type even if the input is malformated
2923+
/// with the wrong order of elements or with extra whitespaces.
2924+
#[cheatcode(group = Utilities)]
2925+
function eip712HashStruct(string calldata typeNameOrDefinition, bytes calldata abiEncodedData) external pure returns (bytes32 typeHash);
2926+
2927+
/// Generates the struct hash of the canonical EIP-712 type representation and its abi-encoded data.
2928+
/// Requires previous binding generation with `forge bind-json`.
2929+
///
2930+
/// Params:
2931+
/// * `bindingsPath`: path where the output of `forge bind-json` is stored.
2932+
/// * `typeName`: Name of the type (i.e. "PermitSingle").
2933+
/// * `abiEncodedData`: ABI-encoded data for the struct that is being hashed.
2934+
#[cheatcode(group = Utilities)]
2935+
function eip712HashStruct(string calldata bindingsPath, string calldata typeName, bytes calldata abiEncodedData) external pure returns (bytes32 typeHash);
2936+
2937+
/// Generates a ready-to-sign digest of human-readable typed data following the EIP-712 standard.
2938+
#[cheatcode(group = Utilities)]
2939+
function eip712HashTypedData(string calldata jsonData) external pure returns (bytes32 digest);
28912940
}
28922941
}
28932942

crates/cheatcodes/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub struct CheatsConfig {
3333
pub rpc_endpoints: ResolvedRpcEndpoints,
3434
/// Project's paths as configured
3535
pub paths: ProjectPathsConfig,
36+
/// Path to the directory that contains the bindings generated by `forge bind-json`.
37+
pub bind_json_path: PathBuf,
3638
/// Filesystem permissions for cheatcodes like `writeFile`, `readFile`
3739
pub fs_permissions: FsPermissions,
3840
/// Project root
@@ -98,6 +100,7 @@ impl CheatsConfig {
98100
no_storage_caching: config.no_storage_caching,
99101
rpc_endpoints,
100102
paths: config.project_paths(),
103+
bind_json_path: config.bind_json.out.clone(),
101104
fs_permissions: config.fs_permissions.clone().joined(config.root.as_ref()),
102105
root: config.root.clone(),
103106
broadcast: config.root.clone().join(&config.broadcast),
@@ -303,6 +306,7 @@ impl Default for CheatsConfig {
303306
paths: ProjectPathsConfig::builder().build_with_root("./"),
304307
fs_permissions: Default::default(),
305308
root: Default::default(),
309+
bind_json_path: PathBuf::default().join("utils").join("jsonBindings.sol"),
306310
broadcast: Default::default(),
307311
allowed_paths: vec![],
308312
evm_opts: Default::default(),

0 commit comments

Comments
 (0)