Skip to content

Commit

Permalink
typed_data
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdubs committed Jul 23, 2024
1 parent 610c3d0 commit 2afb925
Show file tree
Hide file tree
Showing 8 changed files with 745 additions and 337 deletions.
Binary file added .DS_Store
Binary file not shown.
429 changes: 375 additions & 54 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ alloy-json-rpc = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7
alloy-primitives = { version = "0.7.0" }
alloy-provider = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" }
alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" }
alloy-sol-types = { version = "0.7.0" }
alloy-sol-types = { version = "0.7.0", features=["std"] }
alloy-transport = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" }
alloy-signer = { git = "https://github.com/alloy-rs/alloy.git" }
alloy-dyn-abi = { version = "0.7.0" , features=["std", "eip712"] }
alloy-signer-local = {git = "https://github.com/alloy-rs/alloy.git"}
k256 = "0.13"
log = "0.4"
thiserror = "1.0.63"
byteorder = "1.4"
zerocopy = "0.3"
serde_json = "1"
serde = { version = "1.0", features = ["derive"] }
# eip-712 = "0.1.1"
ethabi = "18.0.0"
ethereum-types = "0.14.1"
itertools = "0.10.0"
indexmap = "1.7.0"
rustc-hex = "2.1.0"
validator = "0.12.0"

[dev-dependencies]
alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy.git", rev = "d68a6b7" }
Expand All @@ -30,3 +42,6 @@ serial_test = "0.5.1"
[build-dependencies]
alloy-primitives = { version = "0.7.0" }
serde_json = "1"

[features]
eip712 = ["alloy-signer/eip712"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Universal Etheruem signature verification with ERC-6492
# Universal Etheruem signature verification with ERC-6942

This crate verifies any Ethereum signature including:

- EOAs
- Smart contract wallets with [ERC-1271](https://eips.ethereum.org/EIPS/eip-1271)
- Predeploy contract wallets with [ERC-6492](https://eips.ethereum.org/EIPS/eip-6492)
- Predeploy contract wallets with [ERC-6942](https://eips.ethereum.org/EIPS/eip-6942)

## Usage

Expand Down
8 changes: 4 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ fn compile_contracts() {
assert!(output.status.success());
}

const ERC6492_FILE: &str = "forge/out/Erc6492.sol/ValidateSigOffchain.json";
const ERC6492_BYTECODE_FILE: &str = "forge/out/Erc6492.sol/ValidateSigOffchain.bytecode";
const ERC6942_FILE: &str = "forge/out/Erc6942.sol/ValidateSigOffchain.json";
const ERC6942_BYTECODE_FILE: &str = "forge/out/Erc6942.sol/ValidateSigOffchain.bytecode";
const ERC1271_MOCK_FILE: &str = "forge/out/Erc1271Mock.sol/Erc1271Mock.json";
const ERC1271_MOCK_BYTECODE_FILE: &str = "forge/out/Erc1271Mock.sol/Erc1271Mock.bytecode";
fn extract_bytecodes() {
extract_bytecode(
&format_foundry_dir(ERC6492_FILE),
&format_foundry_dir(ERC6492_BYTECODE_FILE),
&format_foundry_dir(ERC6942_FILE),
&format_foundry_dir(ERC6942_BYTECODE_FILE),
);
extract_bytecode(
&format_foundry_dir(ERC1271_MOCK_FILE),
Expand Down
12 changes: 6 additions & 6 deletions contracts/Erc6492.sol → contracts/Erc6942.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ interface IERC1271Wallet {
}

error ERC1271Revert(bytes error);
error ERC6492DeployFailed(bytes error);
error ERC6942DeployFailed(bytes error);

contract UniversalSigValidator {
bytes32 private constant ERC6492_DETECTION_SUFFIX = 0x6492649264926492649264926492649264926492649264926492649264926492;
bytes32 private constant ERC6942_DETECTION_SUFFIX = 0x6942694269426942694269426942694269426942694269426942694269426942;
bytes4 private constant ERC1271_SUCCESS = 0x1626ba7e;

function isValidSigImpl(
Expand All @@ -19,19 +19,19 @@ contract UniversalSigValidator {
) public returns (bool) {
uint contractCodeLen = address(_signer).code.length;
bytes memory sigToValidate;
// The order here is strictly defined in https://eips.ethereum.org/EIPS/eip-6492
// - ERC-6492 suffix check and verification first, while being permissive in case the contract is already deployed; if the contract is deployed we will check the sig against the deployed version, this allows 6492 signatures to still be validated while taking into account potential key rotation
// The order here is strictly defined in https://eips.ethereum.org/EIPS/eip-6942
// - ERC-6942 suffix check and verification first, while being permissive in case the contract is already deployed; if the contract is deployed we will check the sig against the deployed version, this allows 6942 signatures to still be validated while taking into account potential key rotation
// - ERC-1271 verification if there's contract code
// - finally, ecrecover
bool isCounterfactual = bytes32(_signature[_signature.length-32:_signature.length]) == ERC6492_DETECTION_SUFFIX;
bool isCounterfactual = bytes32(_signature[_signature.length-32:_signature.length]) == ERC6942_DETECTION_SUFFIX;
if (isCounterfactual) {
address create2Factory;
bytes memory factoryCalldata;
(create2Factory, factoryCalldata, sigToValidate) = abi.decode(_signature[0:_signature.length-32], (address, bytes, bytes));

if (contractCodeLen == 0 || tryPrepare) {
(bool success, bytes memory err) = create2Factory.call(factoryCalldata);
if (!success) revert ERC6492DeployFailed(err);
if (!success) revert ERC6942DeployFailed(err);
}
} else {
sigToValidate = _signature;
Expand Down
Loading

0 comments on commit 2afb925

Please sign in to comment.