Skip to content

Commit 5cb29a5

Browse files
Filipp MakarovFilipp Makarov
authored andcommitted
chore: forgelint and reduce size
1 parent 727b621 commit 5cb29a5

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

contracts/nexus/Nexus.sol

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,12 @@ contract Nexus is INexus, BaseAccount, ExecutionHelper, ModuleManager, UUPSUpgra
358358
// Remove the signature from the initData
359359
initData = initData[65:];
360360
// Calculate the hash of the initData
361-
bytes32 initDataHash = keccak256(initData);
361+
bytes32 initDataHash;
362+
assembly {
363+
let ptr := mload(0x40)
364+
calldatacopy(ptr, initData.offset, initData.length)
365+
initDataHash := keccak256(ptr, initData.length)
366+
}
362367
// Make sure the account has not been already initialized
363368
// Means relay can not re-initialize the account
364369
require(!isInitialized(), AccountAlreadyInitialized());
@@ -412,7 +417,7 @@ contract Nexus is INexus, BaseAccount, ExecutionHelper, ModuleManager, UUPSUpgra
412417
// Handle potential ERC7739 support detection request
413418
if (signature.length == 0) {
414419
// Forces the compiler to optimize for smaller bytecode size.
415-
/// forge-lint:disable-next-line(divide-before-multiplModuleManager.sol:716:16y)
420+
/// forge-lint:disable-next-line(divide-before-multiply)
416421
if (uint256(hash) == (~signature.length / 0xffff) * 0x7739) {
417422
return _checkERC7739Support(hash, signature);
418423
}

contracts/nexus/base/ModuleManager.sol

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,25 @@ abstract contract ModuleManager is Storage, EIP712, IModuleManager {
713713
pure
714714
returns (bytes32)
715715
{
716-
return keccak256(abi.encode(MODULE_ENABLE_MODE_TYPE_HASH, module, moduleType, userOpHash, keccak256(initData)));
716+
bytes32 structHash;
717+
assembly {
718+
let ptr := mload(0x40)
719+
mstore(ptr, MODULE_ENABLE_MODE_TYPE_HASH)
720+
mstore(add(ptr, 0x20), module)
721+
mstore(add(ptr, 0x40), moduleType)
722+
mstore(add(ptr, 0x60), userOpHash)
723+
724+
// Hash initData and store at ptr + 0x80
725+
// calldatacopy to copy initData to memory, then hash it
726+
let initDataPtr := add(ptr, 0xa0)
727+
calldatacopy(initDataPtr, initData.offset, initData.length)
728+
let initDataHash := keccak256(initDataPtr, initData.length)
729+
mstore(add(ptr, 0x80), initDataHash)
730+
731+
// Hash the entire struct
732+
structHash := keccak256(ptr, 0xa0)
733+
}
734+
return structHash;
717735
}
718736

719737
function _fallback(bytes calldata callData) private {

0 commit comments

Comments
 (0)