Skip to content

Commit

Permalink
6942 --> 6492
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdubs committed Jul 23, 2024
1 parent 2afb925 commit 38e3171
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 72 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Universal Etheruem signature verification with ERC-6942
# Universal Etheruem signature verification with ERC-6492

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-6942](https://eips.ethereum.org/EIPS/eip-6942)
- Predeploy contract wallets with [ERC-6492](https://eips.ethereum.org/EIPS/eip-6492)

## Usage

Expand Down Expand Up @@ -37,7 +37,7 @@ use sig_verifier::extract_address;
#[tokio::main]
async fn main() {
let signature = bytes!("0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658")
let address = extract_address(signature).await.unwrap(); // works for EOA, ERC1271, ERC6942
let address = extract_address(signature).await.unwrap(); // works for EOA, ERC1271, ERC6492
dbg!(address);
}
```
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 ERC6942_FILE: &str = "forge/out/Erc6942.sol/ValidateSigOffchain.json";
const ERC6942_BYTECODE_FILE: &str = "forge/out/Erc6942.sol/ValidateSigOffchain.bytecode";
const ERC6492_FILE: &str = "forge/out/Erc6492.sol/ValidateSigOffchain.json";
const ERC6492_BYTECODE_FILE: &str = "forge/out/Erc6492.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(ERC6942_FILE),
&format_foundry_dir(ERC6942_BYTECODE_FILE),
&format_foundry_dir(ERC6492_FILE),
&format_foundry_dir(ERC6492_BYTECODE_FILE),
);
extract_bytecode(
&format_foundry_dir(ERC1271_MOCK_FILE),
Expand Down
12 changes: 6 additions & 6 deletions contracts/Erc6942.sol → contracts/Erc6492.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ interface IERC1271Wallet {
}

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

contract UniversalSigValidator {
bytes32 private constant ERC6942_DETECTION_SUFFIX = 0x6942694269426942694269426942694269426942694269426942694269426942;
bytes32 private constant ERC6492_DETECTION_SUFFIX = 0x6492649264926492649264926492649264926492649264926492649264926492;
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-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
// 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
// - ERC-1271 verification if there's contract code
// - finally, ecrecover
bool isCounterfactual = bytes32(_signature[_signature.length-32:_signature.length]) == ERC6942_DETECTION_SUFFIX;
bool isCounterfactual = bytes32(_signature[_signature.length-32:_signature.length]) == ERC6492_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 ERC6942DeployFailed(err);
if (!success) revert ERC6492DeployFailed(err);
}
} else {
sigToValidate = _signature;
Expand Down
Loading

0 comments on commit 38e3171

Please sign in to comment.