Skip to content

Commit

Permalink
refactored code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
leekt committed Dec 11, 2024
1 parent b333793 commit 0ff92c6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/core/ExecutorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract contract ExecutorManager {
function _installExecutor(IExecutor executor, bytes calldata executorData, IHook hook) internal {
_installExecutorWithoutInit(executor, hook);
if (executorData.length == 0) {
(bool success,) = address(executor).call(abi.encodeWithSelector(IModule.onInstall.selector, hex""));
(bool success,) = address(executor).call(abi.encodeWithSelector(IModule.onInstall.selector, hex"")); // ignore return value
} else {
executor.onInstall(executorData);
}
Expand Down
24 changes: 4 additions & 20 deletions src/core/ValidationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "../utils/ValidationTypeLib.sol";

import {CALLTYPE_SINGLE, MODULE_TYPE_POLICY, MODULE_TYPE_SIGNER, MODULE_TYPE_VALIDATOR} from "../types/Constants.sol";
import {calldataKeccak, getSender} from "../utils/Utils.sol";

import {PermissionId, getValidationResult, CallType} from "../types/Types.sol";
import {_intersectValidationData} from "../utils/KernelValidationResult.sol";
Expand Down Expand Up @@ -605,26 +606,9 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
return isReplayable ? _chainAgnosticHashTypedData(structHash) : _hashTypedData(structHash);
}

function calldataKeccak(bytes calldata data) internal pure returns (bytes32 ret) {
assembly ("memory-safe") {
let mem := mload(0x40)
let len := data.length
calldatacopy(mem, data.offset, len)
ret := keccak256(mem, len)
}
}

function getSender(PackedUserOperation calldata userOp) internal pure returns (address) {
address data;
//read sender from userOp, which is first userOp member (saves 800 gas...)
assembly {
data := calldataload(userOp)
}
return address(uint160(data));
}

// chain agnostic internal functions
/// @dev Returns the EIP-712 domain separator.
function _buildChainAgnosticDomainSeparator() private view returns (bytes32 separator) {
function _buildChainAgnosticDomainSeparator() internal view returns (bytes32 separator) {
// We will use `separator` to store the name hash to save a bit of gas.
bytes32 versionHash;
(string memory name, string memory version) = _domainNameAndVersion();
Expand All @@ -642,7 +626,7 @@ abstract contract ValidationManager is EIP712, SelectorManager, HookManager, Exe
}
}

function _chainAgnosticHashTypedData(bytes32 structHash) internal view virtual returns (bytes32 digest) {
function _chainAgnosticHashTypedData(bytes32 structHash) internal view returns (bytes32 digest) {
// we don't do cache stuff here
digest = _buildChainAgnosticDomainSeparator();
/// @solidity memory-safe-assembly
Expand Down
8 changes: 4 additions & 4 deletions src/sdk/KernelTestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ abstract contract KernelTestBase is TestPlus, Test {

bytes32 digest;
if (isReplayable) {
digest = _chainAgnosticHashTypedData(address(kernel), "Kernel", "0.3.2", hash);
digest = chainAgnosticHashTypedData(address(kernel), "Kernel", "0.3.2", hash);
} else {
digest =
keccak256(abi.encodePacked("\x19\x01", _buildDomainSeparator("Kernel", "0.3.2", address(kernel)), hash));
Expand Down Expand Up @@ -1184,7 +1184,7 @@ abstract contract KernelTestBase is TestPlus, Test {
}

/// @dev Returns the EIP-712 domain separator.
function _buildChainAgnosticDomainSeparator(address addr, string memory name, string memory version)
function buildChainAgnosticDomainSeparator(address addr, string memory name, string memory version)
private
view
returns (bytes32 separator)
Expand All @@ -1207,14 +1207,14 @@ abstract contract KernelTestBase is TestPlus, Test {
}
}

function _chainAgnosticHashTypedData(address addr, string memory name, string memory version, bytes32 structHash)
function chainAgnosticHashTypedData(address addr, string memory name, string memory version, bytes32 structHash)
internal
view
virtual
returns (bytes32 digest)
{
// we don't do cache stuff here
digest = _buildChainAgnosticDomainSeparator(addr, name, version);
digest = buildChainAgnosticDomainSeparator(addr, name, version);
/// @solidity memory-safe-assembly
assembly {
// Compute the digest.
Expand Down
22 changes: 22 additions & 0 deletions src/utils/Utils.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {PackedUserOperation} from "../interfaces/PackedUserOperation.sol";

function calldataKeccak(bytes calldata data) pure returns (bytes32 ret) {
assembly ("memory-safe") {
let mem := mload(0x40)
let len := data.length
calldatacopy(mem, data.offset, len)
ret := keccak256(mem, len)
}
}

function getSender(PackedUserOperation calldata userOp) pure returns (address) {
address data;
//read sender from userOp, which is first userOp member (saves 800 gas...)
assembly {
data := calldataload(userOp)
}
return address(uint160(data));
}

0 comments on commit 0ff92c6

Please sign in to comment.