Skip to content

Commit

Permalink
🎨 Format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
insulineru committed Nov 10, 2023
1 parent 2ac513a commit 9f6d4d3
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 136 deletions.
60 changes: 28 additions & 32 deletions src/SMv3SessionValidationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ pragma solidity 0.8.18;
import {ECDSA} from "src/openzeppelin/ECDSA.sol";
import {IEngine} from "src/kwenta/smv3/IEngine.sol";
import {EIP7412} from "src/kwenta/smv3/EIP7412.sol";
import {ISessionValidationModule, UserOperation} from "src/biconomy/interfaces/ISessionValidationModule.sol";
import {
ISessionValidationModule,
UserOperation
} from "src/biconomy/interfaces/ISessionValidationModule.sol";

/**
* @title Kwenta Smart Margin v3 Session Validation Module for Biconomy Smart Accounts
Expand Down Expand Up @@ -32,10 +35,8 @@ contract SMv3SessionValidationModule is ISessionValidationModule {
bytes calldata _sessionKeyData,
bytes calldata /*_callSpecificData*/
) external pure override returns (address) {
(address sessionKey, address smv3Engine) = abi.decode(
_sessionKeyData,
(address, address)
);
(address sessionKey, address smv3Engine) =
abi.decode(_sessionKeyData, (address, address));

/// @dev ensure destinationContract is the smv3Engine
if (destinationContract != smv3Engine) {
Expand All @@ -45,12 +46,12 @@ contract SMv3SessionValidationModule is ISessionValidationModule {
/// @dev ensure the function selector is the a valid IEngine selector
bytes4 funcSelector = bytes4(_funcCallData[0:4]);
if (
funcSelector != IEngine.modifyCollateral.selector &&
funcSelector != IEngine.commitOrder.selector &&
funcSelector != IEngine.invalidateUnorderedNonces.selector &&
funcSelector != EIP7412.fulfillOracleQuery.selector &&
funcSelector != IEngine.depositEth.selector &&
funcSelector != IEngine.withdrawEth.selector
funcSelector != IEngine.modifyCollateral.selector
&& funcSelector != IEngine.commitOrder.selector
&& funcSelector != IEngine.invalidateUnorderedNonces.selector
&& funcSelector != EIP7412.fulfillOracleQuery.selector
&& funcSelector != IEngine.depositEth.selector
&& funcSelector != IEngine.withdrawEth.selector
) {
revert InvalidSMv3Selector();
}
Expand Down Expand Up @@ -92,18 +93,16 @@ contract SMv3SessionValidationModule is ISessionValidationModule {
/// or
/// `execute_ncC(address,uint256,bytes)`
if (
bytes4(_op.callData[0:4]) != EXECUTE_SELECTOR &&
bytes4(_op.callData[0:4]) != EXECUTE_OPTIMIZED_SELECTOR
bytes4(_op.callData[0:4]) != EXECUTE_SELECTOR
&& bytes4(_op.callData[0:4]) != EXECUTE_OPTIMIZED_SELECTOR
) {
revert InvalidSelector();
}

(address sessionKey, address smv3Engine) = abi.decode(
_sessionKeyData,
(address, address)
);
(address sessionKey, address smv3Engine) =
abi.decode(_sessionKeyData, (address, address));

(address destinationContract, uint256 callValue, ) = abi.decode(
(address destinationContract, uint256 callValue,) = abi.decode(
_op.callData[4:], // skip selector; already checked
(address, uint256, bytes)
);
Expand All @@ -118,21 +117,20 @@ contract SMv3SessionValidationModule is ISessionValidationModule {
bytes calldata data;
{
uint256 offset = uint256(bytes32(_op.callData[4 + 64:4 + 96]));
uint256 length = uint256(
bytes32(_op.callData[4 + offset:4 + offset + 32])
);
uint256 length =
uint256(bytes32(_op.callData[4 + offset:4 + offset + 32]));
data = _op.callData[4 + offset + 32:4 + offset + 32 + length];
}

/// @dev ensure the function selector is the a valid IEngine selector
bytes4 funcSelector = bytes4(data[0:4]);
if (
funcSelector != IEngine.modifyCollateral.selector &&
funcSelector != IEngine.commitOrder.selector &&
funcSelector != IEngine.invalidateUnorderedNonces.selector &&
funcSelector != EIP7412.fulfillOracleQuery.selector &&
funcSelector != IEngine.depositEth.selector &&
funcSelector != IEngine.withdrawEth.selector
funcSelector != IEngine.modifyCollateral.selector
&& funcSelector != IEngine.commitOrder.selector
&& funcSelector != IEngine.invalidateUnorderedNonces.selector
&& funcSelector != EIP7412.fulfillOracleQuery.selector
&& funcSelector != IEngine.depositEth.selector
&& funcSelector != IEngine.withdrawEth.selector
) {
revert InvalidSMv3Selector();
}
Expand All @@ -152,10 +150,8 @@ contract SMv3SessionValidationModule is ISessionValidationModule {

/// @dev this method of signature validation is out-of-date
/// see https://github.com/OpenZeppelin/openzeppelin-sdk/blob/7d96de7248ae2e7e81a743513ccc617a2e6bba21/packages/lib/contracts/cryptography/ECDSA.sol#L6
return
ECDSA.recover(
ECDSA.toEthSignedMessageHash(_userOpHash),
_sessionKeySignature
) == sessionKey;
return ECDSA.recover(
ECDSA.toEthSignedMessageHash(_userOpHash), _sessionKeySignature
) == sessionKey;
}
}
Loading

0 comments on commit 9f6d4d3

Please sign in to comment.