Skip to content

Commit

Permalink
Sequence v2 (#145)
Browse files Browse the repository at this point in the history
* NonceUtils initial commit

* Add SessionUtils

* Add read gap nonce hook

* Fix error names and add session tests

* Add comments to SessionUtils

* Patch lazy octopus require main modolue upgradable

* Deploy session utils script

* Deploy contract on networks

* Commit factory build

* Push Solidity version to 0.8.14

* Remove visivility of constructors

* Implement native gapNonce and noNonce

* Adapt tests to updated hardhat

* Fix benchmark

* Fix test coverage

* Test special nonce types

* Add tests for special nonce types

* Replace string errors with type errors

* Reduce gas costs using unchecked

* Extend ModuleAuthUpgradable for ModuleIgnoreAuthUpgradable

* Extend ModuleCalls for ModuleIgnoreNonceCalls

* Compute subdigest during signature validation

* Add alternative signature encoding schemas

* Add support for signatures without chainId

* Better signature dispatcher

* Decode signatures without memory copy

* Fix coverage tests

* Update ts-node

* Alternative signature dispatcher

* Implement updateImageHash for ModuleAuthFixed

* Fix benchmark runner

* Recover signatures prefixed with lazy octops transactions

* Fix lazy octopus prefixed signatures subdigest

* Simplify tests

* Remove unused contracts

* Simplify repo and uncommit artifacts

* wip chained signatures

* better chained signatures

* Cleanup libbytes and remove out of bounds checks

* Fix github actions

* Sequence merkle signatures (#146)

* initial implementation recursive merkle signatures

* Implement merkle signature encoding and decoding

* Use merkle and legacy encoding, given size of config

* Better benchmarker report

* Optimize hash tree nodes

* Fix new compiler warnings

* Fix old compiler warnings

* Optimize and simplify signature reading

* Fix test to avoid generating wallets without signers

* v2 - foundry changes (#147)

* Remove subDigest from ModuleAuth

* Remove unused LibBytes methods

* Add foundry tests

* Add foundry tests for utils

* Add Foundry tests for SequenceBaseSig

* Add SequenceDynamicSig tests

* SequenceChainedSig tests and fixes

* Add SubModuleNonceTest tests

* Implementation and calls tests

* Add more long array tests

* Foundry tests

* Fix implementation foundry test

* ModuleCalls gas golfing

* Keep transactions in calldata

* Reduce runs github ci

* Push to Solidity 0.8.16

* V2 - better signatures (#148)

* Add ModuleExtraAuth

* Foundry tests for module extra auth

* Add ModuleStaticAuth module

* Add ModuleStaticAuth foundry tests

* Simplify ModuleExtraAuth

* Add ModuleStaticMerkleAuth module

* Bound chainId and heavy tests

* Bound big foundry test

* Move static subdigest signing to imageHash

* Implement EIP-5719 (#149)

* V2 better signatures (#150)

* Add ModuleExtraAuth

* Foundry tests for module extra auth

* Add ModuleStaticAuth module

* Add ModuleStaticAuth foundry tests

* Simplify ModuleExtraAuth

* Add ModuleStaticMerkleAuth module

* Bound chainId and heavy tests

* Bound big foundry test

* Move static subdigest signing to imageHash

* Add base EIP-4337 implementation (#151)

* Push Solidity to 0.8.17

* V2 simplify (#152)

* Remove EIP-4337 support

* Remove alternative nonce types

* V2 - 3 bytes size for signatures (#153)

* Add readUint24 utility function

* Use uint24 for chained signature size

* Use 3 bytes for dynamic signature

* Use 3 bytes for signature branchs

* LibString

* GuestModule

* MainModule

* SequenceBaseSig

* SequenceNoChainIdSig

* thershold -> threshold

* Amend SignatureValidator comments

* minor v2 changes (#157)

* GuestModule: DelegateCallNotAllowed() -> DelegateCallNotAllowed(uint256 _index)

* NotEnoughGas: add transaction index

* ModuleStaticAuth: check static digests first

* reuse SubModuleNonce constants

* Integrate checkpoint into imagehash (#154)

* Embed checkpoint in imageHash

* Fix setImplementation match wallet test

* Fix checkpoint order on tests

* thershold -> threshold

Co-authored-by: William Hua <[email protected]>

* Minor renames (#158)

* imagehash -> image hash
* typehash -> type hash

* sub digest -> subdigest

* leaf -> node

* compare directly

* whitespace

* developpers -> developers

* joinAddrAndWeight -> leafForAddressAndWeight

* ImageHashNode | ConfigLeaf -> ConfigTopology

* fix unnecessary casts

* iddle -> idle

* Converter -> Convertor

* mainmodule -> main module

* fix incorrect comments

* V2 nested configs (#155)

* V2 - convenience Auth + IPFS (#159)

* Implement nested signature part

* Fix foundry test for invalid sig type

* Add tests for nested wallet configs

* Add tests for unique leafs

* Add ipfs + imageHash convenience method

* Update hardhat

* deploy contracts using EIP-2470

* Delete unused contract

* Use node v18 for ci

* Move v1 audits to v1 folder

* Add onlyDelegatecall module

* Fix comments

* Remove redundant static auth

* Foundry test fixes

* Update outdated arcadeum comments

* Better Tx executed events

* Deploy new version

* Fix type GuestModule comment

* Update to Solidity 0.8.18

* erc-165 tests: remove duplicate IModuleHooks, add IModuleAuth (#165)

* Comments and formatting

* Add docs for ModuleAuth

* MainModuleGasEstimation: simulateExecute (#167)

* V2 - Consensys audit fixes (#168)

* Fix right padded hooks selector issue

* Fix multicall blockNumber wrong value

* Revert isValidSignature if wrong signature length

* Emit events when changing hooks

* Revert if factory failed to deploy wallet

* Remove unused imports and fix solhint

* Implement ERC165 missing modules

* Remove duplicated decodeNonce code

* Move gas-estimation modules to subdir

* Remove outdated experimental pragma

* Fix foundry test

* Revert contract creation if deploy failed

* Deploy new contracts on some chains

* Deploy Sequence v2 contracts

* fix: requireNonExpired inclusion (#170)

* Hooks (#169)

* Hook implements IERC223Receiver

* Add IERC777Receiver

* Test stability (#171)

* Bump forge deps

* Improve test stability

* Fix foundry test edge cases

* Add v2 audit reports

---------

Co-authored-by: William Hua <[email protected]>
Co-authored-by: Ignacio Mazzara <[email protected]>
Co-authored-by: Michael Standen <[email protected]>
  • Loading branch information
4 people authored Jun 21, 2023
1 parent 38e0719 commit 4683828
Show file tree
Hide file tree
Showing 508 changed files with 26,497 additions and 46,364 deletions.
67 changes: 41 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
node_modules
*/*/node_modules
key: ${{ runner.os }}-lerna-${{ hashFiles('**/package.json', '**/yarn.lock') }}
- run: yarn build
- run: yarn benchmark

lint-ts:
Expand Down Expand Up @@ -92,32 +93,11 @@ jobs:
node_modules
*/*/node_modules
key: ${{ runner.os }}-lerna-${{ hashFiles('**/package.json', '**/yarn.lock') }}
- run: yarn build
- run: yarn test

# coverage:
# name: Coverage
# runs-on: ubuntu-latest
# needs: [install]
# steps:
# - uses: actions/checkout@v1
# - uses: actions/setup-node@v1
# with:
# node-version: 18
# - uses: actions/cache@master
# id: yarn-cache
# with:
# path: |
# node_modules
# */*/node_modules
# key: ${{ runner.os }}-lerna-${{ hashFiles('**/package.json', '**/yarn.lock') }}
# - run: yarn coverage || true
# - name: Coveralls
# uses: coverallsapp/github-action@master
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}

build:
name: Is latest build commited?
coverage:
name: Coverage
runs-on: ubuntu-latest
needs: [install]
steps:
Expand All @@ -132,5 +112,40 @@ jobs:
node_modules
*/*/node_modules
key: ${{ runner.os }}-lerna-${{ hashFiles('**/package.json', '**/yarn.lock') }}
- run: yarn test
- run: git diff --exit-code
- run: yarn coverage || true
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

foundry-tests:
name: Foundry tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run tests
run: FOUNDRY_FUZZ_RUNS=2048 MAX_ARRAY_LEN=32 forge test -vvv

foundry-tests-long-arrays:
name: Foundry tests (long arrays)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run tests
run: FOUNDRY_FUZZ_RUNS=1024 forge test -vvv
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
.devcontainer
node_modules/

npm-debug.log*
Expand All @@ -12,3 +13,9 @@ coverage
coverage.json

config/*.env

artifacts
foundry_artifacts

cache
gen
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
6 changes: 4 additions & 2 deletions .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
"func-order": "off",
"imports-on-top": "off",
"ordering": "off",
"no-unused-vars": "off",
"no-global-import": "off",
"no-unused-vars": "error",
"not-rely-on-time": "off",
"no-inline-assembly": "off",
"visibility-modifier-order": "off",
"compiler-version": ["error", "0.7.6"],
"compiler-version": ["error", "0.8.18"],
"func-visibility": ["warn", {"ignoreConstructors":true}],
"reason-string": ["warn", {"maxLength": 96}]
}
Expand Down
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,3 @@
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

File renamed without changes.
File renamed without changes.
Binary file not shown.
8 changes: 6 additions & 2 deletions src/contracts/Factory.sol → contracts/Factory.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
pragma solidity 0.8.18;

import "./Wallet.sol";


contract Factory {
error DeployFailed(address _mainModule, bytes32 _salt);

/**
* @notice Will deploy a new wallet instance
* @param _mainModule Address of the main module to be used by the wallet
Expand All @@ -14,7 +17,8 @@ contract Factory {
* passed for each transaction.
*/
function deploy(address _mainModule, bytes32 _salt) public payable returns (address _contract) {
bytes memory code = abi.encodePacked(Wallet.creationCode, uint256(_mainModule));
bytes memory code = abi.encodePacked(Wallet.creationCode, uint256(uint160(_mainModule)));
assembly { _contract := create2(callvalue(), add(code, 32), mload(code), _salt) }
if (_contract == address(0)) revert DeployFailed(_mainModule, _salt);
}
}
2 changes: 1 addition & 1 deletion src/contracts/Wallet.sol → contracts/Wallet.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
pragma solidity 0.8.18;

/**
Minimal upgradeable proxy implementation, delegates all calls to the address
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
pragma solidity 0.8.18;


interface IERC1271Wallet {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
pragma solidity 0.8.18;


interface IERC1155Receiver {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
pragma solidity 0.8.18;


interface IERC223Receiver {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
pragma solidity 0.8.18;


interface IERC721Receiver {
Expand Down
6 changes: 6 additions & 0 deletions contracts/interfaces/receivers/IERC777Receiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.18;

interface IERC777Receiver {
function tokensReceived(address, address, address, uint256, bytes calldata, bytes calldata) external;
}
9 changes: 9 additions & 0 deletions contracts/mocks/AlwaysRevertMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.18;


contract AlwaysRevertMock {
fallback() external payable {
revert("AlwaysRevertMock#fallback: ALWAYS_REVERT");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
pragma solidity 0.8.18;


contract CallReceiverMock {
Expand All @@ -8,7 +8,7 @@ contract CallReceiverMock {

bool revertFlag;

constructor() public payable { }
constructor() payable { }

function setRevertFlag(bool _revertFlag) external {
revertFlag = _revertFlag;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
pragma solidity 0.8.18;


contract DelegateCallMock {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
pragma solidity 0.8.18;


contract ERC165CheckerMock {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
pragma solidity 0.8.18;


contract GasBurnerMock {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
pragma solidity 0.8.18;

import "../interfaces/receivers/IERC1155Receiver.sol";
import "../interfaces/receivers/IERC721Receiver.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
pragma solidity 0.8.18;


contract HookMock {
Expand Down
36 changes: 36 additions & 0 deletions contracts/mocks/LibBytesImpl.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.18;

import "../utils/LibBytes.sol";


contract LibBytesImpl {
using LibBytes for bytes;

function readBytes32(
bytes calldata data,
uint256 index
) external pure returns (
bytes32 a
) {
return LibBytes.readBytes32(data, index);
}

function readUint8(
bytes calldata data,
uint256 index
) external pure returns (
uint8 a
) {
return LibBytes.readUint8(data, index);
}

function readUint32(
bytes calldata data,
uint256 index
) external pure returns (
uint32 a
) {
return LibBytes.readUint32(data, index);
}
}
48 changes: 48 additions & 0 deletions contracts/mocks/LibBytesPointerImpl.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.18;

import "../utils/LibBytesPointer.sol";


contract LibBytesPointerImpl {
using LibBytesPointer for bytes;

function readFirstUint16(
bytes calldata data
) external pure returns (
uint16 a,
uint256 newPointer
) {
return LibBytesPointer.readFirstUint16(data);
}

function readUint16(
bytes calldata data,
uint256 index
) external pure returns (
uint16 a,
uint256 newPointer
) {
return LibBytesPointer.readUint16(data, index);
}

function readUint24(
bytes calldata data,
uint256 index
) external pure returns (
uint24 a,
uint256 newPointer
) {
return LibBytesPointer.readUint24(data, index);
}

function readUint64(
bytes calldata data,
uint256 index
) external pure returns (
uint64 a,
uint256 newPointer
) {
return LibBytesPointer.readUint64(data, index);
}
}
25 changes: 25 additions & 0 deletions contracts/mocks/LibStringImp.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.18;

import "../utils/LibString.sol";


contract LibStringImp {
using LibString for string;

function prefixBase32(string calldata data) external pure returns (string memory) {
return LibString.prefixBase32(data);
}

function prefixHexadecimal(string calldata data) external pure returns (string memory) {
return LibString.prefixHexadecimal(data);
}

function bytesToBase32(bytes calldata data) external pure returns (string memory) {
return LibString.bytesToBase32(data);
}

function bytesToHexadecimal(bytes calldata data) external pure returns (string memory) {
return LibString.bytesToHexadecimal(data);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.7.6;
pragma solidity 0.8.18;


contract ModuleMock {
Expand Down
Loading

0 comments on commit 4683828

Please sign in to comment.