-
Notifications
You must be signed in to change notification settings - Fork 24
feat: StatelessValidatorMultiPlexer #23
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
4
commits into
main
Choose a base branch
from
feat/stateless-validator-multiplex
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 all commits
Commits
Show all changes
4 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 |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "solidity.compileUsingRemoteVersion": "v0.8.28+commit.7893614a" | ||
| } |
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,5 +1,5 @@ | ||
| [profile.default] | ||
| solc = "0.8.25" | ||
| solc = "0.8.28" | ||
| evm_version = "cancun" | ||
| src = "src" | ||
| out = "out" | ||
|
|
||
107 changes: 107 additions & 0 deletions
107
src/StatelessValidatorMultiPlexer/StatelessValidatorMultiPlexer.sol
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,107 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-only | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| // Contracts | ||
| import { ERC7579StatelessValidatorBase } from "modulekit/Modules.sol"; | ||
|
|
||
| // Constants | ||
| import { MODULE_TYPE_STATELESS_VALIDATOR } from "modulekit/module-bases/utils/ERC7579Constants.sol"; | ||
|
|
||
| /** | ||
| * @title StatelessValidatorMultiPlexer | ||
| * @dev A stateless validator multiplexer that allows multiple stateless validators to be used in a | ||
| * single module. | ||
| * @author highskore | ||
| */ | ||
| contract StatelessValidatorMultiPlexer is ERC7579StatelessValidatorBase { | ||
| /*////////////////////////////////////////////////////////////////////////// | ||
| ERRORS | ||
| //////////////////////////////////////////////////////////////////////////*/ | ||
|
|
||
| error MismatchedValidatorsAndDataLength(); | ||
|
|
||
| /*////////////////////////////////////////////////////////////////////////// | ||
| CONFIG | ||
| //////////////////////////////////////////////////////////////////////////*/ | ||
|
|
||
| /// @notice Called when the module is installed on a smart account | ||
| function onInstall(bytes calldata) external override { } | ||
|
|
||
| /// @notice Called when the module is uninstalled from a smart account | ||
| function onUninstall(bytes calldata) external override { } | ||
|
|
||
| /// @notice Checks if the module is initialized for a smart account | ||
| function isInitialized(address smartAccount) external view override returns (bool) { } | ||
|
|
||
| /// @notice Returns the type of the module | ||
| /// @dev Implements interface to indicate validator capabilities | ||
| /// @param typeID Type identifier to check | ||
| /// @return bool True if this module supports the specified type | ||
| function isModuleType(uint256 typeID) external pure override returns (bool) { | ||
| return typeID == MODULE_TYPE_STATELESS_VALIDATOR; | ||
| } | ||
|
|
||
| /*////////////////////////////////////////////////////////////////////////// | ||
| VALIDATION | ||
| //////////////////////////////////////////////////////////////////////////*/ | ||
|
|
||
| /// @notice Validates a signature with data by multiplexing through stateless validators | ||
| /// @param hash The hash of the data to validate | ||
| /// @param signature The signatures to validate | ||
| /// @param data The data to validate against the signature, | ||
| /// the data is encoded in the following format: | ||
| /// abi.encode(address[] validators, bytes[] data) | ||
| /// @return bool True if the signature is valid for all validators | ||
| function validateSignatureWithData( | ||
| bytes32 hash, | ||
| bytes calldata signature, | ||
| bytes calldata data | ||
| ) | ||
| external | ||
| view | ||
| override | ||
| returns (bool) | ||
| { | ||
| // Decode the signatures array | ||
| bytes[] memory signatures = abi.decode(signature, (bytes[])); | ||
|
|
||
| // Decode the data to get the list of validators and their corresponding data | ||
| (address[] memory validators, bytes[] memory validatorData, uint8 threshold) = | ||
| abi.decode(data, (address[], bytes[], uint8)); | ||
|
|
||
| // Ensure the threshold is not zero | ||
| if (threshold == 0) { | ||
| return false; | ||
| } | ||
|
|
||
| // Cache the length of the validators array | ||
| uint256 validatorsLength = validators.length; | ||
|
|
||
| // Ensure the number of validators matches the number of data entries | ||
| require( | ||
| ((validatorsLength == validatorData.length) && (validatorsLength == signatures.length)), | ||
| MismatchedValidatorsAndDataLength() | ||
| ); | ||
|
|
||
| // Count the number of valid signatures | ||
| uint8 validCount = 0; | ||
|
|
||
| // Validate each signature with its corresponding data | ||
| for (uint256 i = 0; i < validatorsLength; i++) { | ||
| // Call the validateSignatureWithData function on each validator | ||
| bool validSig = ERC7579StatelessValidatorBase(validators[i]).validateSignatureWithData( | ||
| hash, signatures[i], validatorData[i] | ||
| ); | ||
| if (validSig) { | ||
| validCount++; | ||
| } | ||
| } | ||
|
|
||
| if (validCount >= threshold) { | ||
| // If we have enough valid signatures, we can return true | ||
| return true; | ||
| } | ||
| // If we do not have enough valid signatures, return false | ||
| return false; | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.