-
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
Open
kumaryash90
wants to merge
2
commits into
main
Choose a base branch
from
yash/validateuserop-7702
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
validate user op #29
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -63,16 +69,24 @@ contract MinimalAccount is EIP712, IERC721Receiver, IERC1155Receiver { | |
error UIDAlreadyProcessed(); // 0x26748493 | ||
error SessionExpired(); // 0x1fd05a4a | ||
error NoCallsToExecute(); // 0xf4a0814c | ||
error SignatureValidationFailed(); // 0x2fdec18b | ||
error InvalidSelector(); // 0x7352d91c | ||
error NotFromEntrypoint(); // 0xca433742 | ||
|
||
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 +115,71 @@ 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); | ||
_payPrefund(missingAccountFunds); | ||
} | ||
|
||
function isValidSignature( | ||
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 (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 +283,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; | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite limited though. Just checking if recovered is this EOA.