-
Notifications
You must be signed in to change notification settings - Fork 4
Finish the MVP #3
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
14 commits
Select commit
Hold shift + click to select a range
e8f4bef
feat: migrate AllowedSessionsValidator.sol
ly0va 73fe9a4
feat: more cleanup
ly0va b9c43c0
clean up and tests
ly0va 6252575
more tests
ly0va 8a131ca
add signature validation via erc7739
ly0va a8da035
add a personal sign test
ly0va 18987d3
add factory, deploy script and rework tests
ly0va bd96532
remove unused const
ly0va fea3415
unused imports
ly0va 2538278
slither fix
ly0va 88bcbc2
update comments
ly0va 1674789
fix deploy script
ly0va dab4e71
license and minor fixes
ly0va 8398818
Update test/mocks/MockDelegateTarget.sol
ly0va 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.24; | ||
|
|
||
| import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
| import { UpgradeableBeacon } from "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol"; | ||
| import { Script } from "forge-std/Script.sol"; | ||
|
|
||
| import { MSAFactory } from "src/MSAFactory.sol"; | ||
| import { EOAKeyValidator } from "src/modules/EOAKeyValidator.sol"; | ||
| import { SessionKeyValidator } from "src/modules/SessionKeyValidator.sol"; | ||
| import { WebAuthnValidator } from "src/modules/WebAuthnValidator.sol"; | ||
| import { ModularSmartAccount } from "src/ModularSmartAccount.sol"; | ||
|
|
||
| contract Deploy is Script { | ||
| function run() public { | ||
| // TODO: use correct owner address. | ||
| address owner = msg.sender; | ||
|
|
||
| address[] memory defaultModules = new address[](3); | ||
| defaultModules[0] = address(new TransparentUpgradeableProxy(address(new EOAKeyValidator()), owner, "")); | ||
| defaultModules[1] = address(new TransparentUpgradeableProxy(address(new SessionKeyValidator()), owner, "")); | ||
| defaultModules[2] = address(new TransparentUpgradeableProxy(address(new WebAuthnValidator()), owner, "")); | ||
|
|
||
| address accountImpl = address(new ModularSmartAccount()); | ||
| address beacon = address(new UpgradeableBeacon(accountImpl, owner)); | ||
| address factory = address(new TransparentUpgradeableProxy(address(new MSAFactory(beacon)), owner, "")); | ||
| } | ||
| } |
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,42 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.24; | ||
|
|
||
| import { BeaconProxy } from "@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol"; | ||
|
|
||
| import { IMSA } from "./interfaces/IMSA.sol"; | ||
|
|
||
| /// @title MSAFactory | ||
| /// @author Matter Labs | ||
| /// @custom:security-contact security@matterlabs.dev | ||
| /// @dev This contract is used to deploy SSO accounts as beacon proxies. | ||
| contract MSAFactory { | ||
| /// @dev The address of the beacon contract used for the accounts' beacon proxies. | ||
| address public immutable beacon; | ||
|
|
||
| /// @notice A mapping from unique account IDs to their corresponding deployed account addresses. | ||
| /// TODO: add versioning for upgradeability | ||
| mapping(bytes32 accountId => address deployedAccount) public accountRegistry; | ||
|
|
||
| /// TODO: have this contract be a module registry too? | ||
| // address[] public moduleRegistry; | ||
|
|
||
| /// @notice Emitted when a new account is successfully created. | ||
| /// @param accountAddress The address of the newly created account. | ||
| /// @param accountId A unique identifier for the account. | ||
| event AccountCreated(address indexed accountAddress, bytes32 accountId); | ||
|
|
||
| error AccountAlreadyExists(bytes32 accountId); | ||
|
|
||
| constructor(address _beacon) { | ||
| beacon = _beacon; | ||
| } | ||
|
|
||
| function deployAccount(bytes32 accountId, bytes calldata initData) external returns (address account) { | ||
| require(accountRegistry[accountId] == address(0), AccountAlreadyExists(accountId)); | ||
|
|
||
| accountRegistry[accountId] = address(account); | ||
cpb8010 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| account = address(new BeaconProxy{ salt: accountId }(beacon, initData)); | ||
ly0va marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| emit AccountCreated(account, accountId); | ||
| } | ||
| } | ||
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
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,65 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.24; | ||
|
|
||
| import { ERC1271 } from "solady/accounts/ERC1271.sol"; | ||
| import { IERC1271 } from "@openzeppelin/contracts/interfaces/IERC1271.sol"; | ||
| import { ModuleManager } from "./ModuleManager.sol"; | ||
| import { IValidator } from "../interfaces/IERC7579Module.sol"; | ||
|
|
||
| /// @title ERC1271Handler | ||
| /// @author Matter Labs | ||
| /// @notice Contract which provides ERC1271 signature validation | ||
| /// @notice Uses ERC7739 for signature replay protection | ||
| abstract contract ERC1271Handler is ERC1271, ModuleManager { | ||
| /// @notice Returns the domain name and version for the EIP-712 signature. | ||
| /// @return name string - The name of the domain | ||
| /// @return version string - The version of the domain | ||
| function _domainNameAndVersion() internal pure override returns (string memory name, string memory version) { | ||
| return ("zksync-sso-1271", "1.0.0"); | ||
| } | ||
|
|
||
| /// @notice Indicates whether or not the contract may cache the domain name and version. | ||
| /// @return bool - Whether the domain name and version may change. | ||
| function _domainNameAndVersionMayChange() internal pure override returns (bool) { | ||
| return true; | ||
| } | ||
|
|
||
| // @notice Returns whether the signature provided is valid for the provided hash. | ||
| // @dev Does not run validation hooks. Is used internally after ERC7739 unwrapping. | ||
| // @param hash bytes32 - Hash of the data that is signed | ||
| // @param signature bytes calldata - K1 owner signature OR validator address concatenated to signature | ||
| // @return bool - Whether the signature is valid | ||
| function _erc1271IsValidSignatureNowCalldata( | ||
| bytes32 hash, | ||
| bytes calldata data | ||
| ) | ||
| internal | ||
| view | ||
| virtual | ||
| override | ||
| returns (bool) | ||
| { | ||
| address validator = address(bytes20(data[:20])); | ||
| if (!_isValidatorInstalled(validator)) { | ||
| revert InvalidModule(validator); | ||
| } | ||
| return IValidator(validator).isValidSignatureWithSender(msg.sender, hash, data[20:]) | ||
| == IERC1271.isValidSignature.selector; | ||
| } | ||
|
|
||
| /// @notice This function is not used anywhere in the contract, but is required to be implemented. | ||
| function _erc1271Signer() internal pure override returns (address) { | ||
| revert(); | ||
| } | ||
|
|
||
| /// @dev Returns whether the `msg.sender` is considered safe, such | ||
| /// that we don't need to use the nested EIP-712 workflow. | ||
| /// @return bool - currently, always returns false | ||
| function _erc1271CallerIsSafe() internal pure override returns (bool) { | ||
| return false; | ||
| } | ||
|
|
||
| function domainSeparator() external view returns (bytes32) { | ||
| return _domainSeparator(); | ||
| } | ||
| } |
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.