Skip to content

Commit

Permalink
Merge pull request #5 from permissivelabs/zerodev/kernel-v2
Browse files Browse the repository at this point in the history
Zerodev/kernel v2
  • Loading branch information
Flydexo authored Jun 6, 2023
2 parents 90a6e96 + 0d1a344 commit 8c91bcb
Show file tree
Hide file tree
Showing 26 changed files with 580 additions and 714 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ jobs:

- name: Run tests
run: forge test -vvv

- name: Check formatting
run: forge fmt --check
12 changes: 8 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
[submodule "lib/Solidity-RLP"]
path = lib/Solidity-RLP
url = https://github.com/hamdiallam/Solidity-RLP
branch = v2.0.7
branch = master
[submodule "lib/account-abstraction"]
path = lib/account-abstraction
url = https://github.com/eth-infinitism/account-abstraction
branch = v0.4.0
branch = ver0.6.0
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
branch = v4.8.2
branch = master
[submodule "lib/solidity-bytes-utils"]
path = lib/solidity-bytes-utils
url = https://github.com/GNSPS/solidity-bytes-utils
branch = v0.8.0
branch = master
[submodule "lib/safe-contracts"]
path = lib/safe-contracts
url = https://github.com/safe-global/safe-contracts
[submodule "lib/zerodev-wallet-kernel"]
path = lib/zerodev-wallet-kernel
url = https://github.com/zerodevapp/zerodev-wallet-kernel
branch = kernel_v2
2 changes: 1 addition & 1 deletion lib/Solidity-RLP
2 changes: 1 addition & 1 deletion lib/account-abstraction
Submodule account-abstraction updated 0 files
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts
2 changes: 1 addition & 1 deletion lib/safe-contracts
1 change: 1 addition & 0 deletions lib/zerodev-wallet-kernel
Submodule zerodev-wallet-kernel added at c5c5e1
34 changes: 30 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Deployments
## Deployments

| factory | account implementation | fee manager | safe factory |
| ------------------------------------------ | ------------------------------------------ | ------------------------------------------ | ------------------------------------------ |
| 0x499dcb87582897b050fa0579eb0d5fe71ce491b3 | 0x031d104686cde4d7ac2a31831efe36eee888af2c | 0x2ad29cc25d9fb3647b304353a0a609f27afe380b | 0x0c850e3c696871e6b72a410bea7b1c96870e0715 |
## Core

### PermissiveFactory

`0x499dcb87582897b050fa0579eb0d5fe71ce491b3`

### PermissiveAccount

`0x031d104686cde4d7ac2a31831efe36eee888af2c`

### FeeManager

`0x2ad29cc25d9fb3647b304353a0a609f27afe380b`

## Safe

### SafeFactory

`0x0c850e3c696871e6b72a410bea7b1c96870e0715`

### SafeModule

`0x536e29988dcdab2d8e2f2d7621eb2eee7393df28`

## Zerodev

### PermissiveValidator

### PermissiveExecutor
3 changes: 2 additions & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
@openzeppelin/=lib/openzeppelin-contracts/
bytes/=lib/solidity-bytes-utils/contracts/
safe/=lib/safe-contracts/contracts/
safe/=lib/safe-contracts/contracts/
zerodev/=lib/zerodev-wallet-kernel/src/
90 changes: 32 additions & 58 deletions src/core/AllowanceCalldata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ pragma solidity ^0.8.18;

import "Solidity-RLP/RLPReader.sol";

uint constant ANY = 0;
uint constant NE = 1;
uint constant EQ = 2;
uint constant GT = 3;
uint constant LT = 4;
uint constant AND = 5;
uint constant OR = 6;
uint256 constant ANY = 0;
uint256 constant NE = 1;
uint256 constant EQ = 2;
uint256 constant GT = 3;
uint256 constant LT = 4;
uint256 constant AND = 5;
uint256 constant OR = 6;

library AllowanceCalldata {
function sliceRLPItems(
RLPReader.RLPItem[] memory arguments,
uint start
) internal pure returns (RLPReader.RLPItem[] memory newArguments) {
function sliceRLPItems(RLPReader.RLPItem[] memory arguments, uint256 start)
internal
pure
returns (RLPReader.RLPItem[] memory newArguments)
{
newArguments = new RLPReader.RLPItem[](arguments.length - start);
uint initialStart = start;
uint256 initialStart = start;
for (; start < arguments.length; start++) {
newArguments[start - initialStart] = arguments[start];
}
Expand All @@ -29,51 +30,33 @@ library AllowanceCalldata {
bool isOr
) internal view returns (bool canPass) {
if (allowedArguments.length == 0) return true;
for (uint i = 0; i < allowedArguments.length; i++) {
RLPReader.RLPItem[] memory prefixAndArg = RLPReader.toList(
allowedArguments[i]
);
uint prefix = RLPReader.toUint(prefixAndArg[0]);
for (uint256 i = 0; i < allowedArguments.length; i++) {
RLPReader.RLPItem[] memory prefixAndArg = RLPReader.toList(allowedArguments[i]);
uint256 prefix = RLPReader.toUint(prefixAndArg[0]);

if (prefix == ANY) {} else if (prefix == EQ) {
bytes memory allowedArgument = RLPReader.toBytes(
prefixAndArg[1]
);
bytes memory allowedArgument = RLPReader.toBytes(prefixAndArg[1]);
bytes memory argument = RLPReader.toBytes(arguments[i]);
canPass = keccak256(allowedArgument) == keccak256(argument);
} else if (prefix == LT) {
uint allowedArgument = RLPReader.toUint(prefixAndArg[1]);
uint argument = RLPReader.toUint(arguments[i]);
uint256 allowedArgument = RLPReader.toUint(prefixAndArg[1]);
uint256 argument = RLPReader.toUint(arguments[i]);
canPass = argument < allowedArgument;
} else if (prefix == GT) {
uint allowedArgument = RLPReader.toUint(prefixAndArg[1]);
uint argument = RLPReader.toUint(arguments[i]);
uint256 allowedArgument = RLPReader.toUint(prefixAndArg[1]);
uint256 argument = RLPReader.toUint(arguments[i]);
canPass = argument > allowedArgument;
} else if (prefix == OR) {
RLPReader.RLPItem[] memory subAllowance = RLPReader.toList(
prefixAndArg[1]
);
canPass = validateArguments(
subAllowance,
sliceRLPItems(arguments, i),
true
);
RLPReader.RLPItem[] memory subAllowance = RLPReader.toList(prefixAndArg[1]);
canPass = validateArguments(subAllowance, sliceRLPItems(arguments, i), true);
i++;
} else if (prefix == NE) {
bytes memory allowedArgument = RLPReader.toBytes(
prefixAndArg[1]
);
bytes memory allowedArgument = RLPReader.toBytes(prefixAndArg[1]);
bytes memory argument = RLPReader.toBytes(arguments[i]);
canPass = keccak256(allowedArgument) != keccak256(argument);
} else if (prefix == AND) {
RLPReader.RLPItem[] memory subAllowance = RLPReader.toList(
prefixAndArg[1]
);
canPass = validateArguments(
subAllowance,
sliceRLPItems(arguments, i),
false
);
RLPReader.RLPItem[] memory subAllowance = RLPReader.toList(prefixAndArg[1]);
canPass = validateArguments(subAllowance, sliceRLPItems(arguments, i), false);
i++;
} else {
revert("Invalid calldata prefix");
Expand All @@ -85,31 +68,22 @@ library AllowanceCalldata {
return canPass;
}

function isAllowedCalldata(
bytes memory allowed,
bytes memory data
) internal view returns (bool isOk) {
function isAllowedCalldata(bytes memory allowed, bytes memory data) internal view returns (bool isOk) {
RLPReader.RLPItem memory RLPAllowed = RLPReader.toRlpItem(allowed);
RLPReader.RLPItem[] memory allowedArguments = RLPReader.toList(
RLPAllowed
);
RLPReader.RLPItem[] memory allowedArguments = RLPReader.toList(RLPAllowed);
RLPReader.RLPItem memory RLPData = RLPReader.toRlpItem(data);
RLPReader.RLPItem[] memory arguments = RLPReader.toList(RLPData);
if (allowedArguments.length != arguments.length)
if (allowedArguments.length != arguments.length) {
revert("Invalid arguments length");
}
isOk = validateArguments(allowedArguments, arguments, false);
}

function RLPtoABI(
bytes memory data
) internal pure returns (bytes memory abiEncoded) {
function RLPtoABI(bytes memory data) internal pure returns (bytes memory abiEncoded) {
RLPReader.RLPItem memory RLPData = RLPReader.toRlpItem(data);
RLPReader.RLPItem[] memory arguments = RLPReader.toList(RLPData);
for (uint256 i = 0; i < arguments.length; i++) {
abiEncoded = bytes.concat(
abiEncoded,
RLPReader.toBytes(arguments[i])
);
abiEncoded = bytes.concat(abiEncoded, RLPReader.toBytes(arguments[i]));
}
}
}
3 changes: 2 additions & 1 deletion src/core/FeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import "@openzeppelin/contracts/access/Ownable.sol";
contract FeeManager is Ownable {
uint256 public fee = 2000;
bool initialized;
event FeePaid(address indexed from, uint amount);

event FeePaid(address indexed from, uint256 amount);

function initialize(address owner) external {
require(!initialized);
Expand Down
Loading

0 comments on commit 8c91bcb

Please sign in to comment.