forked from bcnmy/nexus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request bcnmy#205 from bcnmy/release/nexus-1.0.0
Release/nexus 1.0.0
- Loading branch information
Showing
24 changed files
with
170 additions
and
91 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -161,7 +161,7 @@ jobs: | |
uses: crytic/[email protected] | ||
id: slither | ||
with: | ||
slither-version: "0.10.0" | ||
slither-version: "0.10.1" | ||
node-version: "22" | ||
fail-on: "none" | ||
slither-args: '--solc-args="--evm-version cancun" --exclude "assembly|solc-version|low-level-calls|naming-convention|controlled-delegatecall|write-after-write|divide-before-multiply|incorrect-shift" --exclude-informational --exclude-low --filter-paths "contracts/mock|node_modules" --checklist --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/contracts/' | ||
|
This file contains 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
Binary file not shown.
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -12,13 +12,12 @@ pragma solidity ^0.8.27; | |
// Nexus: A suite of contracts for Modular Smart Accounts compliant with ERC-7579 and ERC-4337, developed by Biconomy. | ||
// Learn more at https://biconomy.io. To report security issues, please contact us at: [email protected] | ||
|
||
import { SignatureCheckerLib } from "solady/utils/SignatureCheckerLib.sol"; | ||
import { ECDSA } from "solady/utils/ECDSA.sol"; | ||
import { PackedUserOperation } from "account-abstraction/interfaces/PackedUserOperation.sol"; | ||
import { ERC7739Validator } from "../../base/ERC7739Validator.sol"; | ||
import { IValidator } from "../../interfaces/modules/IValidator.sol"; | ||
import { EnumerableSet } from "../../lib/EnumerableSet4337.sol"; | ||
import { MODULE_TYPE_VALIDATOR, VALIDATION_SUCCESS, VALIDATION_FAILED } from "../../types/Constants.sol"; | ||
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol"; | ||
|
||
/// @title Nexus - K1Validator (ECDSA) | ||
/// @notice Validator module for smart accounts, verifying user operation signatures | ||
|
@@ -33,7 +32,7 @@ import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/Mes | |
/// @author @zeroknots | Rhinestone.wtf | zeroknots.eth | ||
/// Special thanks to the Solady team for foundational contributions: https://github.com/Vectorized/solady | ||
contract K1Validator is IValidator, ERC7739Validator { | ||
using SignatureCheckerLib for address; | ||
using ECDSA for bytes32; | ||
using EnumerableSet for EnumerableSet.AddressSet; | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
|
@@ -57,6 +56,9 @@ contract K1Validator is IValidator, ERC7739Validator { | |
/// @notice Error to indicate that the new owner cannot be a contract address | ||
error NewOwnerIsContract(); | ||
|
||
/// @notice Error to indicate that the owner cannot be the zero address | ||
error OwnerCannotBeZeroAddress(); | ||
|
||
/// @notice Error to indicate that the data length is invalid | ||
error InvalidDataLength(); | ||
|
||
|
@@ -73,6 +75,7 @@ contract K1Validator is IValidator, ERC7739Validator { | |
require(data.length != 0, NoOwnerProvided()); | ||
require(!_isInitialized(msg.sender), ModuleAlreadyInitialized()); | ||
address newOwner = address(bytes20(data[:20])); | ||
require(newOwner != address(0), OwnerCannotBeZeroAddress()); | ||
require(!_isContract(newOwner), NewOwnerIsContract()); | ||
smartAccountOwners[msg.sender] = newOwner; | ||
if (data.length > 20) { | ||
|
@@ -185,7 +188,7 @@ contract K1Validator is IValidator, ERC7739Validator { | |
/// @notice Returns the version of the module | ||
/// @return The version of the module | ||
function version() external pure returns (string memory) { | ||
return "1.0.0-beta.1"; | ||
return "1.0.0"; | ||
} | ||
|
||
/// @notice Checks if the module is of the specified type | ||
|
@@ -199,6 +202,15 @@ contract K1Validator is IValidator, ERC7739Validator { | |
INTERNAL | ||
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
/// @notice Recovers the signer from a signature | ||
/// @param hash The hash of the data to validate | ||
/// @param signature The signature data | ||
/// @return The recovered signer address | ||
/// @notice tryRecover returns address(0) on invalid signature | ||
function _recoverSigner(bytes32 hash, bytes calldata signature) internal view returns (address) { | ||
return hash.tryRecover(signature); | ||
} | ||
|
||
/// @dev Returns whether the `hash` and `signature` are valid. | ||
/// Obtains the authorized signer's credentials and calls some | ||
/// module's specific internal function to validate the signature | ||
|
@@ -236,12 +248,10 @@ contract K1Validator is IValidator, ERC7739Validator { | |
return false; | ||
} | ||
|
||
if (SignatureCheckerLib.isValidSignatureNowCalldata(owner, hash, signature)) { | ||
return true; | ||
} | ||
if (SignatureCheckerLib.isValidSignatureNowCalldata(owner, MessageHashUtils.toEthSignedMessageHash(hash), signature)) { | ||
return true; | ||
} | ||
// verify signer | ||
// owner can not be zero address in this contract | ||
if (_recoverSigner(hash, signature) == owner) return true; | ||
if (_recoverSigner(hash.toEthSignedMessageHash(), signature) == owner) return true; | ||
return false; | ||
} | ||
|
||
|
This file contains 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 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 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 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,31 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.0 <0.9.0; | ||
pragma solidity >=0.8.0 <0.9.0; | ||
|
||
import { EntryPoint } from "account-abstraction/core/EntryPoint.sol"; | ||
import { IEntryPoint } from "account-abstraction/interfaces/IEntryPoint.sol"; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
|
||
contract HelperConfig is Script { | ||
IEntryPoint public ENTRYPOINT; | ||
address private constant MAINNET_ENTRYPOINT_ADDRESS = 0x0000000071727De22E5E9d8BAf0edAc6f37da032; | ||
|
||
constructor() { | ||
if (block.chainid == 31337) { | ||
setupAnvilConfig(); | ||
} else { | ||
ENTRYPOINT = IEntryPoint(MAINNET_ENTRYPOINT_ADDRESS); | ||
} | ||
} | ||
|
||
function setupAnvilConfig() public { | ||
if(address(ENTRYPOINT) != address(0)){ | ||
return; | ||
} | ||
ENTRYPOINT = new EntryPoint(); | ||
vm.etch(address(MAINNET_ENTRYPOINT_ADDRESS), address(ENTRYPOINT).code); | ||
ENTRYPOINT = IEntryPoint(MAINNET_ENTRYPOINT_ADDRESS); | ||
} | ||
|
||
} |
This file contains 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 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 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 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 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.