-
Notifications
You must be signed in to change notification settings - Fork 22
fix(1271): separate policyData and signature #177
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
highskore
wants to merge
2
commits into
main
Choose a base branch
from
fix/1271-data
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -66,10 +66,7 @@ contract SmartSession is ISmartSession, SmartSessionBase, SmartSessionERC7739 { | |
| * @param userOpHash The hash of the user operation | ||
| * @return vd ValidationData containing the validation result | ||
| */ | ||
| function validateUserOp( | ||
| PackedUserOperation calldata userOp, | ||
| bytes32 userOpHash | ||
| ) | ||
| function validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash) | ||
| external | ||
| override | ||
| returns (ValidationData vd) | ||
|
|
@@ -166,8 +163,7 @@ contract SmartSession is ISmartSession, SmartSessionBase, SmartSessionERC7739 { | |
|
|
||
| // Enable ERC1271 policies | ||
| $enabledERC7739.enable({ | ||
| contexts: enableData.sessionToEnable.erc7739Policies.allowedERC7739Content, | ||
| permissionId: permissionId | ||
| contexts: enableData.sessionToEnable.erc7739Policies.allowedERC7739Content, permissionId: permissionId | ||
| }); | ||
|
|
||
| // Enabel ERC1271 policies | ||
|
|
@@ -181,9 +177,7 @@ contract SmartSession is ISmartSession, SmartSessionBase, SmartSessionERC7739 { | |
|
|
||
| // Enable action policies | ||
| $actionPolicies.enable({ | ||
| permissionId: permissionId, | ||
| actionPolicyDatas: enableData.sessionToEnable.actions, | ||
| useRegistry: false | ||
| permissionId: permissionId, actionPolicyDatas: enableData.sessionToEnable.actions, useRegistry: false | ||
| }); | ||
|
|
||
| _setPermit4337Paymaster(permissionId, enableData.sessionToEnable.permitERC4337Paymaster); | ||
|
|
@@ -279,25 +273,27 @@ contract SmartSession is ISmartSession, SmartSessionBase, SmartSessionERC7739 { | |
| // DEFAULT EXEC & BATCH CALL | ||
| else if (callType == CALLTYPE_BATCH) { | ||
| vd = vd.intersect( | ||
| $actionPolicies.actionPolicies.checkBatch7579Exec({ | ||
| userOp: userOp, | ||
| permissionId: permissionId, | ||
| minPolicies: 1 // minimum of one actionPolicy must be set. | ||
| }) | ||
| $actionPolicies.actionPolicies | ||
| .checkBatch7579Exec({ | ||
| userOp: userOp, | ||
| permissionId: permissionId, | ||
| minPolicies: 1 // minimum of one actionPolicy must be set. | ||
| }) | ||
| ); | ||
| } | ||
| // DEFAULT EXEC & SINGLE CALL | ||
| else if (callType == CALLTYPE_SINGLE) { | ||
| (address target, uint256 value, bytes calldata callData) = | ||
| userOp.callData.decodeUserOpCallData().decodeSingle(); | ||
| vd = vd.intersect( | ||
| $actionPolicies.actionPolicies.checkSingle7579Exec({ | ||
| permissionId: permissionId, | ||
| target: target, | ||
| value: value, | ||
| callData: callData, | ||
| minPolicies: 1 // minimum of one actionPolicy must be set. | ||
| }) | ||
| $actionPolicies.actionPolicies | ||
| .checkSingle7579Exec({ | ||
| permissionId: permissionId, | ||
| target: target, | ||
| value: value, | ||
| callData: callData, | ||
| minPolicies: 1 // minimum of one actionPolicy must be set. | ||
| }) | ||
| ); | ||
| } | ||
| // DelegateCalls are not supported by SmartSession | ||
|
|
@@ -319,7 +315,8 @@ contract SmartSession is ISmartSession, SmartSessionBase, SmartSessionERC7739 { | |
| ActionId actionId = account.toActionId(bytes4(userOp.callData[:4])); | ||
|
|
||
| vd = vd.intersect( | ||
| $actionPolicies.actionPolicies[actionId].check({ | ||
| $actionPolicies.actionPolicies[actionId] | ||
| .check({ | ||
| permissionId: permissionId, | ||
| callOnIPolicy: abi.encodeCall( | ||
| IActionPolicy.checkAction, | ||
|
|
@@ -332,7 +329,7 @@ contract SmartSession is ISmartSession, SmartSessionBase, SmartSessionERC7739 { | |
| ) | ||
| ), | ||
| minPolicies: 1 // minimum of one actionPolicy must be set. | ||
| }) | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -342,10 +339,7 @@ contract SmartSession is ISmartSession, SmartSessionBase, SmartSessionERC7739 { | |
| // perform signature check with ISessionValidator | ||
| // this function will revert if no ISessionValidator is set for this permissionId | ||
| bool validSig = $sessionValidators.isValidISessionValidator({ | ||
| hash: userOpHash, | ||
| account: account, | ||
| permissionId: permissionId, | ||
| signature: decompressedSignature | ||
| hash: userOpHash, account: account, permissionId: permissionId, signature: decompressedSignature | ||
| }); | ||
|
|
||
| // if the ISessionValidator signature is invalid, the userOp is invalid | ||
|
|
@@ -372,11 +366,7 @@ contract SmartSession is ISmartSession, SmartSessionBase, SmartSessionERC7739 { | |
| * contentsType, | ||
| * uint16(contentsType.length)) | ||
| */ | ||
| function isValidSignatureWithSender( | ||
| address sender, | ||
| bytes32 hash, | ||
| bytes calldata signature | ||
| ) | ||
| function isValidSignatureWithSender(address sender, bytes32 hash, bytes calldata signature) | ||
| external | ||
| view | ||
| override | ||
|
|
@@ -427,7 +417,6 @@ contract SmartSession is ISmartSession, SmartSessionBase, SmartSessionERC7739 { | |
| bytes32 contentHash = string(contents).hashERC7739Content(); | ||
| // isolate the PermissionId and actual signature from the supplied signature param | ||
| PermissionId permissionId = PermissionId.wrap(bytes32(signature[0:32])); | ||
| signature = signature[32:]; | ||
|
|
||
| // forgefmt: disable-next-item | ||
| if ( | ||
|
|
@@ -437,12 +426,18 @@ contract SmartSession is ISmartSession, SmartSessionBase, SmartSessionERC7739 { | |
| || !$enabledERC7739.enabledContentNames[permissionId][appDomainSeparator].contains(msg.sender, contentHash) | ||
| ) return false; | ||
|
|
||
| // Extract the length of the policy data | ||
| uint256 policyDataLength = uint256(bytes32(signature[32:64])); | ||
|
|
||
| // Calculate remaining signature offset | ||
| uint256 remainingSignatureOffset = 64 + policyDataLength; | ||
|
highskore marked this conversation as resolved.
|
||
|
|
||
| // check the ERC-1271 policy | ||
| bool valid = $erc1271Policies.checkERC1271({ | ||
| account: msg.sender, | ||
| requestSender: sender, | ||
| hash: hash, | ||
| signature: signature, | ||
| signature: signature[64:remainingSignatureOffset], // extract policy data from the signature | ||
|
highskore marked this conversation as resolved.
Outdated
highskore marked this conversation as resolved.
Outdated
Contributor
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. 👍 |
||
| permissionId: permissionId, | ||
| configId: permissionId.toErc1271PolicyId().toConfigId(), | ||
| minPoliciesToEnforce: 1 | ||
|
|
@@ -455,7 +450,7 @@ contract SmartSession is ISmartSession, SmartSessionBase, SmartSessionERC7739 { | |
| hash: hash, | ||
| account: msg.sender, | ||
| permissionId: permissionId, | ||
| signature: signature | ||
| signature: signature[remainingSignatureOffset:] // extract the validator signature from the signature | ||
|
highskore marked this conversation as resolved.
highskore marked this conversation as resolved.
|
||
| }); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.