Skip to content
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

Release/v1.0.1 #226

Merged
merged 58 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
773943f
Merge pull request #204 from bcnmy/release/nexus-1.0.0
livingrockrises Oct 14, 2024
9937eef
feat:add coverage report
livingrockrises Oct 22, 2024
9e7f3ab
Merge pull request #207 from bcnmy/feat/coverage-report-visibility
livingrockrises Oct 22, 2024
70e7e89
readme cleanup
Oct 23, 2024
1a81d3d
fix: linting
Oct 23, 2024
d64df5c
Merge pull request #209 from bcnmy/fix/readme
livingrockrises Oct 23, 2024
fa90983
fix:code updates init for ERc7739 updates
livingrockrises Oct 29, 2024
1bf437e
feat:add defi safety report
livingrockrises Oct 29, 2024
d073e59
fix tests
Oct 29, 2024
58069b5
fix more tests
Oct 29, 2024
db28ef9
fix rest of the tests
Oct 29, 2024
17f12b4
add 7739 detection support
Oct 29, 2024
2e83bed
fix hardhat
Oct 30, 2024
ae30c5f
use as dep
Oct 30, 2024
8797ddd
clean
Oct 30, 2024
94d85f9
fix remappings
Oct 30, 2024
a7f8b32
Merge pull request #214 from bcnmy/stacked/7739-validator-base-as-ext…
livingrockrises Oct 31, 2024
fa415c4
fix:lint
livingrockrises Oct 31, 2024
4aba898
Merge pull request #212 from bcnmy/fix/k1validator-7739
livingrockrises Oct 31, 2024
0351f93
Merge branch 'dev' into feat/add-defi-safety-score
livingrockrises Oct 31, 2024
69f437b
Merge pull request #213 from bcnmy/feat/add-defi-safety-score
livingrockrises Oct 31, 2024
fad4eff
fix
Nov 1, 2024
c109389
fix tests
Nov 1, 2024
4136703
add tests
Nov 1, 2024
bbe68ea
tests
Nov 1, 2024
d015436
Merge pull request #215 from bcnmy/fix/optimize-sig-malleability-prot…
livingrockrises Nov 2, 2024
c4f9b0f
fix iterate over validators
Nov 8, 2024
cdd4d5f
opt 7739 check
Nov 8, 2024
792a770
revert not return
Nov 8, 2024
f40701f
add proper 7739 detection
Nov 11, 2024
3c6af1b
inline doc move
Nov 11, 2024
0fd6769
fix
Nov 11, 2024
72499c9
Merge pull request #216 from bcnmy/fix/cantina-notes-on-7739-update
filmakarov Nov 11, 2024
aca6343
feat: make bootstrap lib functions internal
livingrockrises Nov 15, 2024
28dbede
Merge pull request #217 from bcnmy/feat/change-library-func-visibility
livingrockrises Nov 15, 2024
8f0458d
report 7739
Nov 21, 2024
93241d2
Merge pull request #218 from bcnmy/add/7739-report
filmakarov Nov 21, 2024
673e4c0
space
Nov 21, 2024
26acfa5
version
Nov 21, 2024
984fd2a
fix tests
Nov 21, 2024
4a49a10
Merge pull request #221 from bcnmy/fix/tests-version
filmakarov Nov 21, 2024
bf4fea0
pp
Nov 25, 2024
e81e477
rn
Nov 25, 2024
9849de5
remapping clean
Nov 25, 2024
2a757c4
ff
Nov 25, 2024
5592a2e
Merge pull request #222 from bcnmy/fix/package-json
filmakarov Nov 25, 2024
22c7cf0
sentinellist fix
Nov 25, 2024
8c5e492
fix v
Nov 25, 2024
b54d56b
check limits
Nov 26, 2024
d6d15af
simplify
Nov 26, 2024
1a63642
Revert to last audited commit (9f1c23f6)
Dec 9, 2024
90b2d5a
Merge pull request #224 from bcnmy/release/prepare-revert-check
filmakarov Dec 9, 2024
889e46d
chore: fix deps
joepegler Dec 6, 2024
84d918d
fix: lockfile
joepegler Dec 9, 2024
bc78319
deploy
Dec 10, 2024
b827f46
Merge pull request #225 from bcnmy/chore/update-readme-for-deploy
filmakarov Dec 10, 2024
7c4f41e
deploy link
Dec 10, 2024
43e1a35
fix typo
Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Documentation: (https://github.com/bcnmy/nexus/wiki)

## Getting Started

To kickstart, follow these steps:
To kickstart, follow these steps:

### Prerequisites
Expand Down Expand Up @@ -111,11 +110,10 @@ Generate documentation from NatSpec comments.

### 🚀 Deploy Contracts

```bash
yarn run deploy:hardhat --network hardhat
```
Nexus contracts are pre-deployed on most EVM chains.
Please see the addresses [here](https://docs.biconomy.io/contractsAndAudits).

Deploys contracts onto the blockchain network.
If you need to deploy Nexus on your own chain or you want to deploy the contracts with different addresses, please see [this](https://github.com/bcnmy/nexus/tree/deploy-v1.0.1/scripts/bash-deploy) script. Or the same script on differnet deploy branches.

### 🎨 Lint Code

Expand Down Expand Up @@ -148,20 +146,7 @@ To generate reports of the storage layout for potential upgrades safety using `h
| Auditor | Date | Final Report Link |
| ---------------- | ---------- | ----------------------- |
| CodeHawks-Cyfrin | 17-09-2024 | [View Report](./audits/CodeHawks-Cyfrin-17-09-2024.pdf) |
| Firm Name | DD-MM-YYYY | [View Report](./audits) |

## 🏆 Biconomy Champions League 🏆

Welcome to the Champions League, a place where your contributions to Biconomy are celebrated and immortalized in our Hall of Fame. This elite group showcases individuals who have significantly advanced our mission, from enhancing code efficiency to strengthening security, and enriching our documentation.

### Champions Roster

| 🍊 Contributor | 🛡️ Domain |
| -------------- | ----------------- |
| @user1 | Code Optimization |
| @user2 | Security |
| @user3 | Documentation |
| ... | ... |
| Spearbit | 10/11-2024 | [View Report](./audits/report-cantinacode-biconomy-0708-final.pdf) / [View Add-on](./audits/report-cantinacode-biconomy-erc7739-addon-final.pdf) |

### Entering the League

Expand Down
Binary file not shown.
Binary file not shown.
50 changes: 35 additions & 15 deletions contracts/Nexus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import { ExecLib } from "./lib/ExecLib.sol";
import { INexus } from "./interfaces/INexus.sol";
import { BaseAccount } from "./base/BaseAccount.sol";
import { IERC7484 } from "./interfaces/IERC7484.sol";
import { IERC7739 } from "./interfaces/IERC7739.sol";
import { ModuleManager } from "./base/ModuleManager.sol";
import { ExecutionHelper } from "./base/ExecutionHelper.sol";
import { IValidator } from "./interfaces/modules/IValidator.sol";
import { MODULE_TYPE_VALIDATOR, MODULE_TYPE_EXECUTOR, MODULE_TYPE_FALLBACK, MODULE_TYPE_HOOK, MODULE_TYPE_MULTI, SUPPORTS_NESTED_TYPED_DATA_SIGN } from "./types/Constants.sol";
import { MODULE_TYPE_VALIDATOR, MODULE_TYPE_EXECUTOR, MODULE_TYPE_FALLBACK, MODULE_TYPE_HOOK, MODULE_TYPE_MULTI, SUPPORTS_ERC7739 } from "./types/Constants.sol";
import { ModeLib, ExecutionMode, ExecType, CallType, CALLTYPE_BATCH, CALLTYPE_SINGLE, CALLTYPE_DELEGATECALL, EXECTYPE_DEFAULT, EXECTYPE_TRY } from "./lib/ModeLib.sol";
import { NonceLib } from "./lib/NonceLib.sol";
import { SentinelListLib, SENTINEL, ZERO_ADDRESS } from "sentinellist/SentinelList.sol";
Expand All @@ -39,6 +38,7 @@ contract Nexus is INexus, BaseAccount, ExecutionHelper, ModuleManager, UUPSUpgra
using ModeLib for ExecutionMode;
using ExecLib for bytes;
using NonceLib for uint256;
using SentinelListLib for SentinelListLib.SentinelList;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be using the SentinelList4337 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case it is not needed as the list is in the account storage itself


/// @dev The timelock period for emergency hook uninstallation.
uint256 internal constant _EMERGENCY_TIMELOCK = 1 days;
Expand Down Expand Up @@ -226,6 +226,15 @@ contract Nexus is INexus, BaseAccount, ExecutionHelper, ModuleManager, UUPSUpgra
/// bytes4(keccak256("isValidSignature(bytes32,bytes)") = 0x1626ba7e
/// @dev Delegates the validation to a validator module specified within the signature data.
function isValidSignature(bytes32 hash, bytes calldata signature) external view virtual override returns (bytes4) {
// Handle potential ERC7739 support detection request
if (signature.length == 0) {
// Forces the compiler to optimize for smaller bytecode size.
if (uint256(hash) == (~signature.length / 0xffff) * 0x7739) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow. what's this doing?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is to check that this is the 7739 support request

and no, we can not because we should identify that this is the request at SA level

return checkERC7739Support(hash, signature);
}
}
// else proceed with normal signature verification

// First 20 bytes of data will be validator address and rest of the bytes is complete signature.
address validator = address(bytes20(signature[0:20]));
require(_isValidatorInstalled(validator), ValidatorNotInstalled(validator));
Expand Down Expand Up @@ -320,19 +329,30 @@ contract Nexus is INexus, BaseAccount, ExecutionHelper, ModuleManager, UUPSUpgra
UUPSUpgradeable.upgradeToAndCall(newImplementation, data);
}

/// @dev For automatic detection that the smart account supports the nested EIP-712 workflow
/// Offchain usage only
/// Iterates over all the validators
function supportsNestedTypedDataSign() public view virtual returns (bytes32) {
SentinelListLib.SentinelList storage validators = _getAccountStorage().validators;
address next = validators.entries[SENTINEL];
while (next != ZERO_ADDRESS && next != SENTINEL) {
try IERC7739(next).supportsNestedTypedDataSign() returns (bytes32 res) {
if (res == SUPPORTS_NESTED_TYPED_DATA_SIGN) return SUPPORTS_NESTED_TYPED_DATA_SIGN;
} catch {}
next = validators.entries[next];
/// @dev For automatic detection that the smart account supports the ERC7739 workflow
/// Iterates over all the validators but only if this is a detection request
/// ERC-7739 spec assumes that if the account doesn't support ERC-7739
/// it will try to handle the detection request as it was normal sig verification
/// request and will return 0xffffffff since it won't be able to verify the 0x signature
/// against 0x7739...7739 hash.
/// So this approach is consistent with the ERC-7739 spec.
/// If no validator supports ERC-7739, this function returns false
/// thus the account will proceed with normal signature verification
/// and return 0xffffffff as a result.
function checkERC7739Support(bytes32 hash, bytes calldata signature) public view virtual returns (bytes4) {
bytes4 result;
unchecked {
SentinelListLib.SentinelList storage validators = _getAccountStorage().validators;
address next = validators.entries[SENTINEL];
while (next != ZERO_ADDRESS && next != SENTINEL) {
bytes4 support = IValidator(next).isValidSignatureWithSender(msg.sender, hash, signature);
if (bytes2(support) == bytes2(SUPPORTS_ERC7739) && support > result) {
result = support;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we break the loop in the case of result = support?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we want to find the latest supported version, so no, we can't

}
next = validators.getNext(next);
}
}
return bytes4(0xffffffff);
return result == bytes4(0) ? bytes4(0xffffffff) : result;
}

/// @dev Ensures that only authorized callers can upgrade the smart contract implementation.
Expand All @@ -343,6 +363,6 @@ contract Nexus is INexus, BaseAccount, ExecutionHelper, ModuleManager, UUPSUpgra
/// @dev EIP712 domain name and version.
function _domainNameAndVersion() internal pure override returns (string memory name, string memory version) {
name = "Nexus";
version = "1.0.0";
version = "1.0.1";
}
}
Loading
Loading