Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestognw committed Sep 23, 2024
1 parent 8b46711 commit 62d8164
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {MessageHashUtils} from "../utils/cryptography/MessageHashUtils.sol";
import {EIP712NestedUtils} from "../utils/cryptography/EIP712NestedUtils.sol";
import {ShortStrings} from "../utils/ShortStrings.sol";

abstract contract EIP712ReadableSigner is EIP712, IERC1271 {
abstract contract ERC1271TypedSigner is EIP712, IERC1271 {
error MismatchedTypedData();

function isValidSignature(bytes32 hash, bytes calldata signature) public view virtual returns (bytes4 result) {
Expand Down
26 changes: 10 additions & 16 deletions contracts/account/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,25 @@ This directory includes contracts to build accounts for ERC-4337.

{{AccountBase}}

{{AccountFactory}}

== Signers

{{AccountSigner}}

{{EIP712ReadableSigner}}
{{AccountERC7579}}

{{SignerECDSA}}
{{ERC1271TypedSigner}}

{{SignerEOA}}
== Modules

{{SignerP256}}
=== Validators

{{SignerRSA}}
{{ECDSAValidator}}

== ERC7579
{{P256Validator}}

{{AccountERC7579}}
{{RSAValidator}}

{{ERC7579ModuleConfig}}
{{MultisigValidator}}

=== Modules
=== Executors

{{ERC7579MultisigValidator}}
{{TypedExecutor}}

== Utilities

Expand Down
4 changes: 2 additions & 2 deletions contracts/account/modules/ECDSAValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {IERC1271} from "../../interfaces/IERC1271.sol";
import {PackedUserOperation} from "../../interfaces/IERC4337.sol";
import {ECDSA} from "../../utils/cryptography/ECDSA.sol";
import {IERC7579Validator, MODULE_TYPE_VALIDATOR} from "../../interfaces/IERC7579Module.sol";
import {EIP712ReadableSigner} from "../EIP712ReadableSigner.sol";
import {ERC1271TypedSigner} from "../ERC1271TypedSigner.sol";
import {ERC4337Utils} from "../utils/ERC4337Utils.sol";

abstract contract ECDSAValidator is IERC7579Validator, EIP712ReadableSigner {
abstract contract ECDSAValidator is IERC7579Validator, ERC1271TypedSigner {
mapping(address => address) private _associatedSigner;

event ECDSASignerAssociated(address indexed account, address indexed signer);
Expand Down
4 changes: 2 additions & 2 deletions contracts/account/modules/P256Validator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {IERC1271} from "../../interfaces/IERC1271.sol";
import {PackedUserOperation} from "../../interfaces/IERC4337.sol";
import {P256} from "../../utils/cryptography/P256.sol";
import {IERC7579Validator, MODULE_TYPE_VALIDATOR} from "../../interfaces/IERC7579Module.sol";
import {EIP712ReadableSigner} from "../EIP712ReadableSigner.sol";
import {ERC1271TypedSigner} from "../ERC1271TypedSigner.sol";
import {ERC4337Utils} from "../utils/ERC4337Utils.sol";

abstract contract P256Validator is IERC7579Validator, EIP712ReadableSigner {
abstract contract P256Validator is IERC7579Validator, ERC1271TypedSigner {
mapping(address => bytes32) private _associatedQx;
mapping(address => bytes32) private _associatedQy;

Expand Down
4 changes: 2 additions & 2 deletions contracts/account/modules/RSAValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {IERC1271} from "../../interfaces/IERC1271.sol";
import {PackedUserOperation} from "../../interfaces/IERC4337.sol";
import {RSA} from "../../utils/cryptography/RSA.sol";
import {IERC7579Validator, MODULE_TYPE_VALIDATOR} from "../../interfaces/IERC7579Module.sol";
import {EIP712ReadableSigner} from "../EIP712ReadableSigner.sol";
import {ERC1271TypedSigner} from "../ERC1271TypedSigner.sol";
import {ERC4337Utils} from "../utils/ERC4337Utils.sol";

abstract contract RSAValidator is IERC7579Validator, EIP712ReadableSigner {
abstract contract RSAValidator is IERC7579Validator, ERC1271TypedSigner {
mapping(address => bytes) private _associatedE;
mapping(address => bytes) private _associatedN;

Expand Down
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/account-abstraction.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ An xref:account.adoc#AccountSigner[`AccountSigner`] is useful to create accounts

Generally speaking, blockchains use the properties of https://en.wikipedia.org/wiki/Digital_signature[digital signatures] to authenticate the sender of each transaction. With this in mind, developers can xref:utilities.adoc#checking_signatures_on_chain[verify signatures on-chain] as a way to authenticate user operations for a given off-chain signer (i.e. a private key).

To setup an account signer, start by inheriting from `AccountSigner` and an xref:api:account.adoc#EIP712ReadableSigner[`EIP712ReadableSigner`]:
To setup an account signer, start by inheriting from `AccountSigner` and an xref:api:account.adoc#ERC1271TypedSigner[`ERC1271TypedSigner`]:

```solidity
// contracts/MyAccountECDSA.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {AccountSigner} from "./AccountSigner.sol";
import {EIP712ReadableSigner} from "./EIP712ReadableSigner.sol";
import {ERC1271TypedSigner} from "./ERC1271TypedSigner.sol";
import {SignerECDSA} from "./SignerECDSA.sol";

contract MyAccountECDSA is AccountSigner, SignerECDSA {
constructor(address signerAddr, string memory name, string memory version) EIP712ReadableSigner(name, version) {}
constructor(address signerAddr, string memory name, string memory version) ERC1271TypedSigner(name, version) {}

/// ...
}
Expand All @@ -121,7 +121,7 @@ A common security practice to prevent user operation https://mirror.xyz/curiousa

The problem with this approach is that the user might be prompted by the wallet provider to sign an https://x.com/howydev/status/1780353754333634738[obfuscated message], which is a phishing vector that may lead to a user losing its assets.

To prevent this, each smart contract signer inherits from xref:api:account#EIP712ReadableSigner[`EIP712ReadableSigner`], a utility that implements a defensive rehashing mechanism based on a https://github.com/frangio/eip712-wrapper-for-eip1271[nested EIP-712 approach] to wrap the signature request in a context where there's clearer information for the end user.
To prevent this, each smart contract signer inherits from xref:api:account#ERC1271TypedSigner[`ERC1271TypedSigner`], a utility that implements a defensive rehashing mechanism based on a https://github.com/frangio/eip712-wrapper-for-eip1271[nested EIP-712 approach] to wrap the signature request in a context where there's clearer information for the end user.

=== Modules

Expand Down

0 comments on commit 62d8164

Please sign in to comment.