forked from zerodevapp/kernel
-
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.
* updated dependencies * updates solady to latest * weighted ecdsa to valdiate the userOp for the last sig * removed toEthSignedMessage * test done
- Loading branch information
Showing
6 changed files
with
185 additions
and
17 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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/solady"] | ||
path = lib/solady | ||
url = https://github.com/vectorized/solady | ||
[submodule "lib/I4337"] | ||
path = lib/I4337 | ||
url = https://github.com/leekt/I4337 | ||
[submodule "lib/FreshCryptoLib"] | ||
path = lib/FreshCryptoLib | ||
url = https://github.com/rdubois-crypto/FreshCryptoLib | ||
[submodule "lib/solady"] | ||
path = lib/solady | ||
url = https://github.com/vectorized/solady |
Submodule FreshCryptoLib
updated
6 files
Submodule forge-std
updated
8 files
+1 −0 | .gitattributes | |
+1 −1 | package.json | |
+635 −0 | scripts/vm.py | |
+5 −1 | src/StdChains.sol | |
+757 −470 | src/Vm.sol | |
+3 −1 | test/StdError.t.sol | |
+2 −2 | test/StdUtils.t.sol | |
+2 −2 | test/Vm.t.sol |
Submodule solady
updated
53 files
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,158 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import {IEntryPoint} from "I4337/interfaces/IEntryPoint.sol"; | ||
import "src/Kernel.sol"; | ||
import "src/validator/WeightedECDSAValidator.sol"; | ||
// test artifacts | ||
// test utils | ||
import "forge-std/Test.sol"; | ||
import {ERC4337Utils} from "src/utils/ERC4337Utils.sol"; | ||
import {KernelTestBase} from "src/utils/KernelTestBase.sol"; | ||
import {TestExecutor} from "src/mock/TestExecutor.sol"; | ||
import {TestValidator} from "src/mock/TestValidator.sol"; | ||
import {IKernel} from "src/interfaces/IKernel.sol"; | ||
|
||
using ERC4337Utils for IEntryPoint; | ||
|
||
contract KernelWeightedECDSATest is KernelTestBase { | ||
address[] public owners; | ||
uint256[] public ownerKeys; | ||
uint24[] public weights; | ||
uint24 public threshold; | ||
uint48 public delay; | ||
|
||
function setUp() public virtual { | ||
_initialize(); | ||
defaultValidator = new WeightedECDSAValidator(); | ||
owners = new address[](3); | ||
ownerKeys = new uint256[](3); | ||
(owners[0], ownerKeys[0]) = makeAddrAndKey("owner0"); | ||
(owners[1], ownerKeys[1]) = makeAddrAndKey("owner1"); | ||
(owners[2], ownerKeys[2]) = makeAddrAndKey("owner2"); | ||
weights = [uint24(1), uint24(2), uint24(3)]; | ||
threshold = 3; | ||
delay = 0; | ||
_setAddress(); | ||
_setExecutionDetail(); | ||
} | ||
|
||
function test_ignore() external {} | ||
|
||
function _setExecutionDetail() internal virtual override { | ||
executionDetail.executor = address(new TestExecutor()); | ||
executionSig = TestExecutor.doNothing.selector; | ||
executionDetail.validator = new TestValidator(); | ||
} | ||
|
||
function getEnableData() internal view virtual override returns (bytes memory) { | ||
return ""; | ||
} | ||
|
||
function getValidatorSignature(UserOperation memory) internal view virtual override returns (bytes memory) { | ||
return ""; | ||
} | ||
|
||
function getOwners() internal view override returns (address[] memory) { | ||
return owners; | ||
} | ||
|
||
function getInitializeData() internal view override returns (bytes memory) { | ||
bytes memory data = abi.encode(owners, weights, threshold, delay); | ||
return abi.encodeWithSelector(KernelStorage.initialize.selector, defaultValidator, data); | ||
} | ||
|
||
function test_external_call_execute_success() external override { | ||
vm.skip(true); | ||
} | ||
|
||
function test_external_call_default() external override { | ||
vm.skip(true); | ||
} | ||
|
||
function test_external_call_execute_delegatecall_success() external override { | ||
vm.skip(true); | ||
} | ||
|
||
function test_external_call_batch_execute_success() external override { | ||
vm.skip(true); | ||
} | ||
|
||
function signUserOp(UserOperation memory op) internal view override returns (bytes memory) { | ||
bytes32 calldataAndNonceHash = keccak256(abi.encode(op.sender, op.callData, op.nonce)); | ||
|
||
bytes32 digest = keccak256( | ||
abi.encode( | ||
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"), | ||
keccak256("WeightedECDSAValidator"), | ||
keccak256("0.0.2"), | ||
block.chainid, | ||
address(defaultValidator) | ||
) | ||
); | ||
|
||
bytes32 structHash = | ||
keccak256(abi.encode(keccak256("Approve(bytes32 callDataAndNonceHash)"), calldataAndNonceHash)); | ||
assembly { | ||
// Compute the digest. | ||
mstore(0x00, 0x1901000000000000) // Store "\x19\x01". | ||
mstore(0x1a, digest) // Store the domain separator. | ||
mstore(0x3a, structHash) // Store the struct hash. | ||
digest := keccak256(0x18, 0x42) | ||
// Restore the part of the free memory slot that was overwritten. | ||
mstore(0x3a, 0) | ||
} | ||
|
||
(uint8 v0, bytes32 r0, bytes32 s0) = vm.sign(ownerKeys[0], digest); | ||
(uint8 v1, bytes32 r1, bytes32 s1) = vm.sign(ownerKeys[1], digest); | ||
bytes memory opSig = entryPoint.signUserOpHash(vm, ownerKeys[2], op); | ||
return abi.encodePacked(bytes4(0x00000000), r0, s0, v0, r1, s1, v1, opSig); | ||
} | ||
|
||
function getWrongSignature(UserOperation memory op) internal view override returns (bytes memory) { | ||
return abi.encodePacked(bytes4(0x00000000), entryPoint.signUserOpHash(vm, ownerKeys[0], op)); | ||
} | ||
|
||
function signHash(bytes32 hash) internal view override returns (bytes memory) { | ||
(uint8 v0, bytes32 r0, bytes32 s0) = vm.sign(ownerKeys[0], hash); | ||
(uint8 v1, bytes32 r1, bytes32 s1) = vm.sign(ownerKeys[1], hash); | ||
(uint8 v2, bytes32 r2, bytes32 s2) = vm.sign(ownerKeys[2], hash); | ||
return abi.encodePacked(r0, s0, v0, r1, s1, v1, r2, s2, v2); | ||
} | ||
|
||
function getWrongSignature(bytes32 hash) internal view override returns (bytes memory) { | ||
(uint8 v0, bytes32 r0, bytes32 s0) = vm.sign(ownerKeys[0], hash); | ||
(uint8 v1, bytes32 r1, bytes32 s1) = vm.sign(ownerKeys[1] + 1, hash); | ||
(uint8 v2, bytes32 r2, bytes32 s2) = vm.sign(ownerKeys[2] + 1, hash); | ||
return abi.encodePacked(r0, s0, v0, r1, s1, v1, r2, s2, v2); | ||
} | ||
|
||
function test_default_validator_enable() external override { | ||
//UserOperation memory op = buildUserOperation( | ||
// abi.encodeWithSelector( | ||
// IKernel.execute.selector, | ||
// address(defaultValidator), | ||
// 0, | ||
// abi.encodeWithSelector(ECDSAValidator.enable.selector, abi.encodePacked(address(0xdeadbeef))), | ||
// Operation.Call | ||
// ) | ||
//); | ||
//performUserOperationWithSig(op); | ||
//(address owner) = ECDSAValidator(address(defaultValidator)).ecdsaValidatorStorage(address(kernel)); | ||
//assertEq(owner, address(0xdeadbeef), "owner should be 0xdeadbeef"); | ||
} | ||
|
||
function test_default_validator_disable() external override { | ||
//UserOperation memory op = buildUserOperation( | ||
// abi.encodeWithSelector( | ||
// IKernel.execute.selector, | ||
// address(defaultValidator), | ||
// 0, | ||
// abi.encodeWithSelector(ECDSAValidator.disable.selector, ""), | ||
// Operation.Call | ||
// ) | ||
//); | ||
//performUserOperationWithSig(op); | ||
//(address owner) = ECDSAValidator(address(defaultValidator)).ecdsaValidatorStorage(address(kernel)); | ||
//assertEq(owner, address(0), "owner should be 0"); | ||
} | ||
} |