Skip to content

Commit 9ebc75c

Browse files
committed
pruned some codes to reduce code size
1 parent 9d63b0f commit 9ebc75c

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

src/Kernel.sol

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
110110
bytes[] calldata initConfig
111111
) external {
112112
ValidationStorage storage vs = _validationStorage();
113-
require(
114-
ValidationId.unwrap(vs.rootValidator) == bytes21(0) && bytes2(address(this).code) != EIP7702_PREFIX,
115-
AlreadyInitialized()
116-
);
113+
if(
114+
ValidationId.unwrap(vs.rootValidator) != bytes21(0) || bytes2(address(this).code) == EIP7702_PREFIX) {
115+
revert AlreadyInitialized();
116+
}
117117
if (ValidationId.unwrap(_rootValidator) == bytes21(0)) {
118118
revert InvalidValidator();
119119
}
@@ -140,7 +140,7 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
140140
bytes calldata hookData
141141
) external payable onlyEntryPointOrSelfOrRoot {
142142
ValidationStorage storage vs = _validationStorage();
143-
if (ValidationId.unwrap(_rootValidator) == bytes21(0) || bytes2(address(this).code) == EIP7702_PREFIX) {
143+
if (ValidationId.unwrap(_rootValidator) == bytes21(0)) {
144144
revert InvalidValidator();
145145
}
146146
ValidationType vType = ValidatorLib.getType(_rootValidator);
@@ -444,7 +444,9 @@ contract Kernel is IAccount, IAccountExecute, IERC7579Account, ValidationManager
444444
if (target == address(0)) {
445445
return;
446446
}
447-
require(target == module, InvalidSelector());
447+
if (target != module) {
448+
revert InvalidSelector();
449+
}
448450
deInitData = deInitData[4:];
449451
} else if (moduleType == MODULE_TYPE_HOOK) {
450452
ValidationId vId = _validationStorage().rootValidator;

src/core/ValidationManager.sol

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
6969
error InvalidMode();
7070
error InvalidValidator();
7171
error InvalidSignature();
72+
error InvalidSelectorData();
7273
error EnableNotApproved();
7374
error PolicySignatureOrderError();
7475
error SignerPrefixNotPresent();
@@ -334,7 +335,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
334335
)
335336
);
336337
} else if (vType == VALIDATION_TYPE_7702) {
337-
validationData = _verify7702Signature(userOpHash, userOpSig) == ERC1271_MAGICVALUE
338+
validationData = _verify7702Signature(ECDSA.toEthSignedMessageHash(userOpHash), userOpSig) == ERC1271_MAGICVALUE
338339
? ValidationData.wrap(0)
339340
: ValidationData.wrap(1);
340341
} else {
@@ -491,8 +492,10 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
491492
) internal view returns (ValidationConfig memory config, bytes32 digest) {
492493
ValidationStorage storage state = _validationStorage();
493494
config.hook = IHook(hook);
494-
config.nonce =
495-
state.validationConfig[vId].nonce == state.currentNonce ? state.currentNonce + 1 : state.currentNonce;
495+
unchecked {
496+
config.nonce =
497+
state.validationConfig[vId].nonce == state.currentNonce ? state.currentNonce + 1 : state.currentNonce;
498+
}
496499

497500
bytes32 structHash = keccak256(
498501
abi.encode(
@@ -536,7 +539,9 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
536539
_installHook(IHook(address(bytes20(selectorData[24:44]))), data.hookInitData);
537540
} else {
538541
// set without install
539-
require(selectorData.length == 4, "Invalid selectorData");
542+
if (selectorData.length != 4) {
543+
revert InvalidSelectorData();
544+
}
540545
}
541546
}
542547

src/utils/ExecLib.sol

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,24 @@ library ExecLib {
6969
function execute(bytes32[] calldata pointers) internal returns (bytes[] memory result) {
7070
uint256 length = pointers.length;
7171
result = new bytes[](length);
72-
for (uint256 i; i < length; i++) {
73-
(address target, uint256 value, bytes calldata data) = LibERC7579.getExecution(pointers, i);
74-
result[i] = execute(target, value, data);
72+
unchecked {
73+
for (uint256 i; i < length; i++) {
74+
(address target, uint256 value, bytes calldata data) = LibERC7579.getExecution(pointers, i);
75+
result[i] = execute(target, value, data);
76+
}
7577
}
7678
}
7779

7880
function tryExecute(bytes32[] calldata pointers) internal returns (bytes[] memory result) {
7981
uint256 length = pointers.length;
8082
result = new bytes[](length);
81-
for (uint256 i; i < length; i++) {
82-
(address target, uint256 value, bytes calldata data) = LibERC7579.getExecution(pointers, i);
83-
bool success;
84-
(success, result[i]) = tryExecute(target, value, data);
85-
if (!success) emit TryExecuteUnsuccessful(i, result[i]);
83+
unchecked {
84+
for (uint256 i; i < length; i++) {
85+
(address target, uint256 value, bytes calldata data) = LibERC7579.getExecution(pointers, i);
86+
bool success;
87+
(success, result[i]) = tryExecute(target, value, data);
88+
if (!success) emit TryExecuteUnsuccessful(i, result[i]);
89+
}
8690
}
8791
}
8892

test/base/Kernel7702TestBase.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ contract Kernel7702TestBase is TestPlus, Test {
426426
virtual
427427
returns (bytes memory)
428428
{
429-
return _rootSignDigest(userOpHash, success);
429+
return _rootSignDigest(ECDSA.toEthSignedMessageHash(userOpHash), success);
430430
}
431431

432432
function _validatorSignUserOp(PackedUserOperation memory, bytes32 userOpHash, bool success)

0 commit comments

Comments
 (0)