From c56308795edcea30cdbee5bc866d4018611cf185 Mon Sep 17 00:00:00 2001 From: Vectorized Date: Wed, 18 Dec 2024 01:32:40 +0000 Subject: [PATCH 1/3] Allow encodeMode to be inlinable --- src/accounts/LibERC7579.sol | 12 ++++-------- test/LibERC7579.t.sol | 7 +++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/accounts/LibERC7579.sol b/src/accounts/LibERC7579.sol index 5f0ae4c69..e3f20d880 100644 --- a/src/accounts/LibERC7579.sol +++ b/src/accounts/LibERC7579.sol @@ -41,14 +41,10 @@ library LibERC7579 { pure returns (bytes32 result) { - /// @solidity memory-safe-assembly - assembly { - mstore(0x00, callType) - mstore(0x01, execType) - mstore(0x02, shr(32, selector)) // Clean the lower bytes of `execType`. - mstore(0x0a, payload) - result := mload(0x00) - } + return bytes32( + uint256(bytes32(callType)) | (uint256(bytes32(execType)) >> 8) + | (uint256(bytes32(selector)) >> 48) | (uint256(uint176(payload))) + ); } /// @dev Returns the call type of the mode. diff --git a/test/LibERC7579.t.sol b/test/LibERC7579.t.sol index ecb99513e..9016110b7 100644 --- a/test/LibERC7579.t.sol +++ b/test/LibERC7579.t.sol @@ -20,6 +20,13 @@ contract LibERC7579Test is SoladyTest { } } + function testEncodeAndDecodeMode() public { + bytes32 mode = LibERC7579.encodeMode( + 0x01, 0x00, 0x11223344, 0xffaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabb + ); + assertEq(mode, 0x01000000000011223344ffaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabb); + } + struct Call { address target; uint256 value; From e994fd90e5854336ff66a7be6b06f7a08ad6a673 Mon Sep 17 00:00:00 2001 From: Vectorized Date: Wed, 18 Dec 2024 01:44:43 +0000 Subject: [PATCH 2/3] Optimize --- src/accounts/LibERC7579.sol | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/accounts/LibERC7579.sol b/src/accounts/LibERC7579.sol index e3f20d880..5a58a49c1 100644 --- a/src/accounts/LibERC7579.sol +++ b/src/accounts/LibERC7579.sol @@ -41,10 +41,20 @@ library LibERC7579 { pure returns (bytes32 result) { - return bytes32( - uint256(bytes32(callType)) | (uint256(bytes32(execType)) >> 8) - | (uint256(bytes32(selector)) >> 48) | (uint256(uint176(payload))) - ); + /// @solidity memory-safe-assembly + assembly { + result := + or( + shl( + 176, + or( + shr(224, selector), + shl(64, or(shl(8, byte(0, callType)), byte(0, execType))) + ) + ), + shr(80, payload) + ) + } } /// @dev Returns the call type of the mode. From ea4328c16a862e39d12872a2d0e8f2b2bde9f483 Mon Sep 17 00:00:00 2001 From: Vectorized Date: Wed, 18 Dec 2024 01:47:04 +0000 Subject: [PATCH 3/3] T --- src/accounts/LibERC7579.sol | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/accounts/LibERC7579.sol b/src/accounts/LibERC7579.sol index 5a58a49c1..e60361d6d 100644 --- a/src/accounts/LibERC7579.sol +++ b/src/accounts/LibERC7579.sol @@ -43,17 +43,9 @@ library LibERC7579 { { /// @solidity memory-safe-assembly assembly { - result := - or( - shl( - 176, - or( - shr(224, selector), - shl(64, or(shl(8, byte(0, callType)), byte(0, execType))) - ) - ), - shr(80, payload) - ) + result := or(shl(8, byte(0, callType)), byte(0, execType)) + result := or(shr(224, selector), shl(64, result)) + result := or(shr(80, payload), shl(176, result)) } }