-
Notifications
You must be signed in to change notification settings - Fork 0
validate user op #29
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
base: main
Are you sure you want to change the base?
validate user op #29
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.26; | ||
|
||
import "account-abstraction-v0.7/core/Helpers.sol"; | ||
import {UserOperationLib} from "account-abstraction-v0.7/core/UserOperationLib.sol"; | ||
import {IEntryPoint} from "account-abstraction-v0.7/interfaces/IEntryPoint.sol"; | ||
import {PackedUserOperation} from "account-abstraction-v0.7/interfaces/PackedUserOperation.sol"; | ||
import {IERC1155Receiver, IERC165} from "../interface/IERC1155Receiver.sol"; | ||
import {IERC721Receiver} from "../interface/IERC721Receiver.sol"; | ||
import {SessionLib} from "../lib/SessionLib.sol"; | ||
import {ECDSA} from "solady/utils/ECDSA.sol"; | ||
import {EIP712} from "solady/utils/EIP712.sol"; | ||
import {EnumerableSetLib} from "solady/utils/EnumerableSetLib.sol"; | ||
import {SignatureCheckerLib} from "solady/utils/SignatureCheckerLib.sol"; | ||
import {Receiver} from "solady/accounts/Receiver.sol"; | ||
import {SignatureCheckerLib} from "solady/utils/SignatureCheckerLib.sol"; | ||
|
||
struct Call { | ||
address target; | ||
|
@@ -50,7 +56,7 @@ library MinimalAccountStorage { | |
|
||
} | ||
|
||
contract MinimalAccount is EIP712, IERC721Receiver, IERC1155Receiver { | ||
contract MinimalAccount is EIP712, Receiver, IERC721Receiver, IERC1155Receiver { | ||
|
||
using EnumerableSetLib for EnumerableSetLib.AddressSet; | ||
using ECDSA for bytes32; | ||
|
@@ -64,15 +70,25 @@ contract MinimalAccount is EIP712, IERC721Receiver, IERC1155Receiver { | |
error SessionExpired(); // 0x1fd05a4a | ||
error NoCallsToExecute(); // 0xf4a0814c | ||
|
||
error SignatureValidationFailed(); | ||
|
||
error InvalidSelector(); | ||
error NotFromEntrypoint(); | ||
|
||
event Executed(address indexed to, uint256 value, bytes data); | ||
event SessionCreated(address indexed signer, SessionLib.SessionSpec sessionSpec); | ||
|
||
address immutable private entrypoint; | ||
bytes32 private constant CALL_TYPEHASH = keccak256("Call(address target,uint256 value,bytes data)"); | ||
bytes32 private constant WRAPPED_CALL_TYPEHASH = | ||
keccak256("WrappedCalls(Call[] calls,bytes32 uid)Call(address target,uint256 value,bytes data)"); | ||
|
||
constructor (address _entrypoint) { | ||
entrypoint = _entrypoint; | ||
} | ||
|
||
function execute(Call[] calldata calls) external payable { | ||
if (msg.sender != address(this)) { | ||
if (msg.sender != address(this) && msg.sender != entrypoint) { | ||
_validate(msg.sender, calls); | ||
} | ||
|
||
|
@@ -101,6 +117,73 @@ contract MinimalAccount is EIP712, IERC721Receiver, IERC1155Receiver { | |
// === View functions | ||
// ====== | ||
|
||
function entryPoint() public view virtual returns (IEntryPoint) { | ||
return IEntryPoint(entrypoint); | ||
} | ||
|
||
function validateUserOp( | ||
PackedUserOperation calldata userOp, | ||
bytes32 userOpHash, | ||
uint256 missingAccountFunds | ||
) external virtual returns (uint256 validationData) { | ||
_requireFromEntryPoint(); | ||
validationData = _validateSignature(userOp, userOpHash); | ||
// _validateNonce(userOp.nonce); | ||
_payPrefund(missingAccountFunds); | ||
} | ||
|
||
function isValidSignature( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another important thing we were missing :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is quite limited though. Just checking if recovered is this EOA. |
||
bytes32 _hash, | ||
bytes memory _signature | ||
) public view virtual returns (bytes4 magicValue) { | ||
address recoveredSigner = _hash.recover(_signature); | ||
|
||
if (recoveredSigner == address(this)) { | ||
return 0x1626ba7e; // ERC-1271 MagicValue | ||
} | ||
} | ||
|
||
function _validateSignature( | ||
PackedUserOperation calldata userOp, | ||
bytes32 userOpHash | ||
) internal virtual returns (uint256 validationData) { | ||
(address signer, bytes memory signature) = abi.decode(userOp.signature, (address, bytes)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this right? dont think signature prepends the address? |
||
bytes32 hash = SignatureCheckerLib.toEthSignedMessageHash(userOpHash); | ||
bool isValidSig = SignatureCheckerLib.isValidSignatureNow(signer, hash, signature); | ||
|
||
if (!isValidSig) { | ||
revert SignatureValidationFailed(); | ||
} | ||
|
||
bytes4 functionSelector = bytes4(userOp.callData[:4]); | ||
|
||
if(functionSelector != this.execute.selector) { | ||
revert InvalidSelector(); | ||
} | ||
|
||
Call[] memory calls = abi.decode(userOp.callData[4:], (Call[])); | ||
// if (!isValidSigner(signer, userOp)) return SIG_VALIDATION_FAILED; | ||
kumaryash90 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if (signer != address(this)) { | ||
_validate(signer, calls); | ||
} | ||
|
||
return _packValidationData(ValidationData(address(0), 0, 0)); | ||
} | ||
|
||
function _requireFromEntryPoint() internal view virtual { | ||
if(msg.sender != entrypoint) { | ||
revert NotFromEntrypoint(); | ||
} | ||
} | ||
|
||
function _payPrefund(uint256 missingAccountFunds) internal virtual { | ||
if (missingAccountFunds != 0) { | ||
(bool success, ) = payable(msg.sender).call{ value: missingAccountFunds, gas: type(uint256).max }(""); | ||
(success); | ||
//ignore failure (its EntryPoint's job to verify, not account.) | ||
} | ||
} | ||
|
||
function getCallPoliciesForSigner(address signer) external view returns (SessionLib.CallSpec[] memory) { | ||
bytes32 sessionUid = _minimalAccountStorage().sessionIds[signer]; | ||
return _minimalAccountStorage().callPolicies[sessionUid]; | ||
|
@@ -204,7 +287,7 @@ contract MinimalAccount is EIP712, IERC721Receiver, IERC1155Receiver { | |
} | ||
} | ||
|
||
function _validate(address _signer, Call[] calldata calls) internal virtual { | ||
function _validate(address _signer, Call[] memory calls) internal virtual { | ||
bytes32 sessionUid = _minimalAccountStorage().sessionIds[_signer]; | ||
uint256 length = calls.length; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.