-
Notifications
You must be signed in to change notification settings - Fork 75
Add p256 validator #48
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
90fa72e
Dev (#47)
leekt e09c0e6
Initial commit
de33 0a18888
Merge branch 'zerodevapp:main' into add-p256Validator
de33 6a410d1
Update P256Validator.t.sol
de33 f18737d
forge install: FreshCryptoLib
de33 b69fda3
Refactor with helper functions
de33 871b078
Add P256Validator, tests, deps
de33 c0c44a6
Remove py scripts used for initial testing
de33 c79d1fb
Update foundry.toml
de33 f913ba0
update deps
de33 fa69cc4
add non-malleable signatures
de33 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
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
Submodule FreshCryptoLib
added at
e2830c
Submodule forge-std
updated
6 files
| +1 −1 | package.json | |
| +11 −3 | src/StdChains.sol | |
| +453 −285 | src/Vm.sol | |
| +2 −6 | test/StdChains.t.sol | |
| +1 −1 | test/StdCheats.t.sol | |
| +15 −0 | test/Vm.t.sol |
Submodule p256-verifier
added at
fcaa17
Submodule solady
updated
53 files
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,3 +1,5 @@ | ||
| ds-test/=lib/forge-std/lib/ds-test/src/ | ||
| forge-std/=lib/forge-std/src/ | ||
| solady/=lib/solady/src/ | ||
| p256-verifier/=lib/p256-verifier/src/ | ||
| FreshCryptoLib/=lib/FreshCryptoLib/solidity/src/ |
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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| pragma solidity ^0.8.0; | ||
|
|
||
| import {UserOperation} from "I4337/interfaces/UserOperation.sol"; | ||
| import {ECDSA} from "solady/utils/ECDSA.sol"; | ||
| import {IKernelValidator} from "../interfaces/IKernelValidator.sol"; | ||
| import {ValidationData} from "../common/Types.sol"; | ||
| import {SIG_VALIDATION_FAILED} from "../common/Constants.sol"; | ||
| import {P256} from "p256-verifier/P256.sol"; | ||
|
|
||
| contract P256Validator is IKernelValidator { | ||
| event P256PublicKeysChanged(address indexed kernel, PublicKey indexed oldKeys, PublicKey indexed newKeys); | ||
|
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. Why indexing the |
||
|
|
||
| struct PublicKey { | ||
| uint256 x; | ||
| uint256 y; | ||
| } | ||
|
|
||
| error BadKey(); | ||
|
|
||
| mapping(address => PublicKey) public p256PublicKey; | ||
|
|
||
| function enable(bytes calldata _data) external payable override { | ||
| PublicKey memory key = abi.decode(_data, (PublicKey)); | ||
| if (key.x == 0 || key.y == 0) { | ||
| revert BadKey(); | ||
| } | ||
| PublicKey memory oldKey = p256PublicKey[msg.sender]; | ||
| p256PublicKey[msg.sender] = key; | ||
| emit P256PublicKeysChanged(msg.sender, oldKey, key); | ||
| } | ||
|
|
||
| function disable(bytes calldata) external payable override { | ||
| delete p256PublicKey[msg.sender]; | ||
| } | ||
|
|
||
| function validateUserOp(UserOperation calldata _userOp, bytes32 _userOpHash, uint256) external payable override returns (ValidationData validationData) { | ||
| (uint256 r, uint256 s) = abi.decode(_userOp.signature, (uint256, uint256)); | ||
| PublicKey memory key = p256PublicKey[_userOp.sender]; | ||
| bytes32 hash = ECDSA.toEthSignedMessageHash(_userOpHash); | ||
| if (P256.verifySignature(hash, r, s, key.x, key.y)) { | ||
| return ValidationData.wrap(0); | ||
| } | ||
| if (!P256.verifySignature(_userOpHash, r, s, key.x, key.y)) { | ||
| return SIG_VALIDATION_FAILED; | ||
| } | ||
| } | ||
|
|
||
| function validateSignature(bytes32 hash, bytes calldata signature) external view override returns (ValidationData) { | ||
| (uint256 r, uint256 s) = abi.decode(signature, (uint256, uint256)); | ||
| PublicKey memory key = p256PublicKey[msg.sender]; | ||
| if (P256.verifySignature(hash, r, s, key.x, key.y)) { | ||
| return ValidationData.wrap(0); | ||
| } | ||
| bytes32 ethHash = ECDSA.toEthSignedMessageHash(hash); | ||
| if (!P256.verifySignature(ethHash, r, s, key.x, key.y)) { | ||
| return SIG_VALIDATION_FAILED; | ||
| } | ||
| return ValidationData.wrap(0); | ||
| } | ||
|
|
||
| function validCaller(address _caller, bytes calldata) external view override returns (bool) { | ||
| revert NotImplemented(); | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
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.
if it is not required to use 0.8.21, let's stick with 0.8.19 since there are some L2 that does not support PUSH0 (which is default from 0.8.20 if i remember it correctly)
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.
You actually use the latest solidity version without targeting
shangaievm version (that's the version with push0), just have to specifyevm_version = 'paris'in the foundry config