Skip to content

Commit

Permalink
fix: eip1271 on sessions module
Browse files Browse the repository at this point in the history
  • Loading branch information
ly0va committed Nov 24, 2024
1 parent d607387 commit c8d0830
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
5 changes: 4 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ const config: HardhatUserConfig = {
},
},
solidity: {
version: "0.8.24",
version: "0.8.28",
settings: {
evmVersion: "cancun",
}
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Base64.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Base64.sol)

pragma solidity 0.8.24;
pragma solidity ^0.8.24;

/**
* @dev Provides a set of functions to operate with Base64 strings.
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/EIP712.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/EIP712.sol)

pragma solidity 0.8.24;
pragma solidity ^0.8.24;

// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/TokenCallbackHandler.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
pragma solidity ^0.8.24;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol";
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/VerifierCaller.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
pragma solidity ^0.8.24;

abstract contract VerifierCaller {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/VerifierCaller.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.24;
pragma solidity ^0.8.24;

abstract contract VerifierCaller {
/**
Expand Down
31 changes: 23 additions & 8 deletions src/validators/SessionKeyValidator.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
pragma solidity ^0.8.24;

import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
Expand Down Expand Up @@ -30,6 +30,15 @@ contract SessionKeyValidator is IValidationHook, IModuleValidator, IModule {
// session hash => session state
mapping(bytes32 => SessionLib.SessionStorage) private sessions;

modifier onlyWithValidationHook(uint256 slot) {
uint256 hookResult;
assembly {
hookResult := tload(slot)
}
require(hookResult == 1, "Can't call this function without calling validationHook");
_;
}

function sessionState(
address account,
SessionLib.SessionSpec calldata spec
Expand Down Expand Up @@ -114,9 +123,9 @@ contract SessionKeyValidator is IValidationHook, IModuleValidator, IModule {
}

/*
* If there are any spend limits configured
* Check if the validator is registered for the smart account
* @param smartAccount The smart account to check
* @return true if spend limits are configured initialized, false otherwise
* @return true if validator is registered for the account, false otherwise
*/
function isInitialized(address smartAccount) external view returns (bool) {
return _isInitialized(smartAccount);
Expand All @@ -127,12 +136,12 @@ contract SessionKeyValidator is IValidationHook, IModuleValidator, IModule {
// && IValidatorManager(smartAccount).isModuleValidator(address(this));
}

/*
* Currently doing 1271 validation, but might update the interface to match the zksync account validation
*/
function isValidSignature(bytes32 hash, bytes memory signature) public view returns (bytes4 magic) {
function isValidSignature(
bytes32 hash,
bytes memory signature
) public view onlyWithValidationHook(uint256(hash)) returns (bytes4 magic) {
// Only succeeds if validationHook has previously succeeded.
magic = EIP1271_SUCCESS_RETURN_VALUE;
// TODO: Does this method have to work standalone? If not, validationHook is sufficient for validation.
}

function validationHook(bytes32 signedHash, Transaction calldata transaction, bytes calldata hookData) external {
Expand All @@ -146,6 +155,12 @@ contract SessionKeyValidator is IValidationHook, IModuleValidator, IModule {
require(recoveredAddress == spec.signer, "Invalid signer");
bytes32 sessionHash = keccak256(abi.encode(spec));
sessions[sessionHash].validate(transaction, spec);

// Set the validation result to 1 for this hash, so that isValidSignature succeeds
uint256 slot = uint256(signedHash);
assembly {
tstore(slot, 1)
}
}

/**
Expand Down

0 comments on commit c8d0830

Please sign in to comment.