Skip to content

Commit 092c5e9

Browse files
committed
moved some assembly logic to solidity
1 parent 2332f45 commit 092c5e9

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/common/relay/core/GasRelayHelper.sol

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,17 @@ abstract contract GasRelayHelper is GasRelayConstants {
179179
// default owner, which results in the same UX. The exception is if it's a task.
180180
if (address(msg.sender).code.length != 0 && callerType != CallerType.Task) return;
181181

182-
bytes32 _packedUnderlyingCaller;
182+
bytes32 _packedUnderlyingCaller = bytes32(uint256(uint160(address(msg.sender)))) | _IN_USE_BIT;
183183

184-
if (callerType == CallerType.Owner) {
185-
_packedUnderlyingCaller = bytes32(uint256(uint160(address(msg.sender)))) | _IN_USE_BIT;
186-
} else if (callerType == CallerType.SessionKey) {
187-
_packedUnderlyingCaller = bytes32(uint256(uint160(address(msg.sender)))) | _IN_USE_AS_SESSION_KEY_BITS;
188-
} else if (callerType == CallerType.Task) {
189-
_packedUnderlyingCaller = bytes32(uint256(uint160(address(msg.sender)))) | _IN_USE_AS_TASK_BITS;
190-
} else {
191-
revert UnknownMsgSenderType();
184+
// NOTE: This treats tasks as session keys!
185+
if (callerType != CallerType.Owner) {
186+
_packedUnderlyingCaller |= _IS_SESSION_KEY_BIT;
192187
}
188+
189+
if (callerType == CallerType.Task) {
190+
_packedUnderlyingCaller |= _IS_TASK_BIT;
191+
}
192+
193193
bytes32 _underlyingCallerTransientSlot = _UNDERLYING_CALLER_NAMESPACE();
194194
assembly {
195195
tstore(_underlyingCallerTransientSlot, _packedUnderlyingCaller)
@@ -305,19 +305,17 @@ abstract contract GasRelayHelper is GasRelayConstants {
305305
/// @return sessionKey Session key data
306306
function _loadSessionKey(address sessionKeyAddress) internal view returns (SessionKey memory sessionKey) {
307307
bytes32 _sessionKeyStorageSlot = keccak256(abi.encodePacked(sessionKeyAddress, _SESSION_KEY_NAMESPACE()));
308-
address _owner;
309-
uint256 _expiration;
310-
bool _isTask;
308+
bytes32 _packedSessionKey;
311309
assembly {
312-
let _packedSessionKey := sload(_sessionKeyStorageSlot)
313-
_owner := and(_packedSessionKey, 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff)
314-
_expiration :=
315-
and(shr(192, _packedSessionKey), 0x000000000000000000000000000000000000000000000000ffffffffffffffff)
316-
_isTask := gt(and(_packedSessionKey, _IS_TASK_BIT), 0)
310+
_packedSessionKey := sload(_sessionKeyStorageSlot)
317311
}
318-
sessionKey.owner = _owner;
319-
sessionKey.expiration = uint64(_expiration);
320-
sessionKey.isTask = _isTask;
312+
sessionKey.owner = address(
313+
uint160(uint256(_packedSessionKey & 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff))
314+
);
315+
sessionKey.expiration = uint64(
316+
uint256(_packedSessionKey >> 192) & 0x000000000000000000000000000000000000000000000000ffffffffffffffff
317+
);
318+
sessionKey.isTask = _packedSessionKey & _IS_TASK_BIT != 0;
321319
}
322320

323321
/// @notice Load session key from owner address

0 commit comments

Comments
 (0)