-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: small changes * fix: restore tests and fix crossOrigin bug * fix: typechain --------- Co-authored-by: Lyova Potyomkin <[email protected]>
- Loading branch information
1 parent
b048b1a
commit 0ba93a5
Showing
5 changed files
with
54 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import { SystemContractsCaller } from "@matterlabs/zksync-contracts/l2/system-co | |
import { EfficientCall } from "@matterlabs/zksync-contracts/l2/system-contracts/libraries/EfficientCall.sol"; | ||
import { DEPLOYER_SYSTEM_CONTRACT } from "@matterlabs/zksync-contracts/l2/system-contracts/Constants.sol"; | ||
import { Errors } from "../libraries/Errors.sol"; | ||
import { SelfAuth } from "../auth/SelfAuth.sol"; | ||
|
||
/// @dev Represents an external call data. | ||
/// @param target The address to which the call will be made. | ||
|
@@ -23,16 +24,12 @@ struct Call { | |
/// @custom:security-contact [email protected] | ||
/// @notice Make multiple calls from Account in a single transaction. | ||
/// @notice The implementation is inspired by Clave wallet. | ||
abstract contract BatchCaller { | ||
abstract contract BatchCaller is SelfAuth { | ||
/// @notice Make multiple calls, ensure success if required. | ||
/// @dev The total Ether sent across all calls must be equal to `msg.value` to maintain the invariant | ||
/// that `msg.value` + `tx.fee` is the maximum amount of Ether that can be spent on the transaction. | ||
/// @param _calls Array of Call structs, each representing an individual external call to be made. | ||
function batchCall(Call[] calldata _calls) external payable { | ||
if (msg.sender != address(this)) { | ||
revert Errors.NOT_FROM_SELF(); | ||
} | ||
|
||
function batchCall(Call[] calldata _calls) external payable onlySelf { | ||
uint256 totalValue; | ||
uint256 len = _calls.length; | ||
for (uint256 i = 0; i < len; ++i) { | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,21 @@ | |
pragma solidity ^0.8.24; | ||
|
||
import { IModuleValidator } from "../interfaces/IModuleValidator.sol"; | ||
import "./PasskeyValidator.sol"; | ||
import { VerifierCaller } from "../helpers/VerifierCaller.sol"; | ||
import { JsmnSolLib } from "../libraries/JsmnSolLib.sol"; | ||
import { Strings } from "../helpers/EIP712.sol"; | ||
import { Base64 } from "../helpers/Base64.sol"; | ||
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; | ||
|
||
/// @title AAFactory | ||
/// @author Matter Labs | ||
/// @custom:security-contact [email protected] | ||
/// @dev This contract allows secure user authentication using WebAuthn public keys. | ||
contract WebAuthValidator is VerifierCaller, IModuleValidator { | ||
address constant P256_VERIFIER = address(0x100); | ||
bytes1 constant AUTH_DATA_MASK = 0x05; | ||
bytes32 constant lowSmax = 0x7fffffff800000007fffffffffffffffde737d56d38bcf4279dce5617e3192a8; | ||
|
||
/** | ||
* @title validator contract for passkey r1 signatures | ||
* @author https://getclave.io | ||
*/ | ||
contract WebAuthValidator is PasskeyValidator, IModuleValidator { | ||
// The layout is weird due to EIP-7562 storage read restrictions for validation phase. | ||
mapping(string originDomain => mapping(address accountAddress => bytes32)) public lowerKeyHalf; | ||
mapping(string originDomain => mapping(address accountAddress => bytes32)) public upperKeyHalf; | ||
|
@@ -57,7 +65,7 @@ contract WebAuthValidator is PasskeyValidator, IModuleValidator { | |
bool validChallenge = false; | ||
bool validType = false; | ||
bool validOrigin = false; | ||
bool invalidCrossOrigin = false; | ||
bool validCrossOrigin = true; | ||
for (uint256 index = 1; index < actualNum; index++) { | ||
JsmnSolLib.Token memory t = tokens[index]; | ||
if (t.jsmnType == JsmnSolLib.JsmnType.STRING) { | ||
|
@@ -102,24 +110,45 @@ contract WebAuthValidator is PasskeyValidator, IModuleValidator { | |
JsmnSolLib.Token memory nextT = tokens[index + 1]; | ||
string memory crossOriginValue = JsmnSolLib.getBytes(clientDataJSON, nextT.start, nextT.end); | ||
// this should only be set once, otherwise this is an error | ||
if (!invalidCrossOrigin) { | ||
if (!validCrossOrigin) { | ||
return false; | ||
} | ||
invalidCrossOrigin = Strings.equal("true", crossOriginValue); | ||
validCrossOrigin = Strings.equal("false", crossOriginValue); | ||
} | ||
} | ||
} | ||
|
||
if (!validChallenge || !validType || !validOrigin || invalidCrossOrigin) { | ||
if (!validChallenge || !validType || !validOrigin || !validCrossOrigin) { | ||
return false; | ||
} | ||
|
||
bytes32 message = _createMessage(authenticatorData, bytes(clientDataJSON)); | ||
valid = callVerifier(P256_VERIFIER, message, rs, pubKey); | ||
} | ||
|
||
/// @inheritdoc IERC165 | ||
function supportsInterface(bytes4 interfaceId) public pure override returns (bool) { | ||
return super.supportsInterface(interfaceId) || interfaceId == type(IModuleValidator).interfaceId; | ||
function supportsInterface(bytes4 interfaceId) public pure returns (bool) { | ||
return interfaceId == type(IERC165).interfaceId || interfaceId == type(IModuleValidator).interfaceId; | ||
} | ||
|
||
function _createMessage( | ||
bytes memory authenticatorData, | ||
bytes memory clientData | ||
) internal pure returns (bytes32 message) { | ||
bytes32 clientDataHash = sha256(clientData); | ||
message = sha256(bytes.concat(authenticatorData, clientDataHash)); | ||
} | ||
|
||
function _decodeFatSignature( | ||
bytes memory fatSignature | ||
) internal pure returns (bytes memory authenticatorData, string memory clientDataSuffix, bytes32[2] memory rs) { | ||
(authenticatorData, clientDataSuffix, rs) = abi.decode(fatSignature, (bytes, string, bytes32[2])); | ||
} | ||
|
||
function rawVerify( | ||
bytes32 message, | ||
bytes32[2] calldata rs, | ||
bytes32[2] calldata pubKey | ||
) external view returns (bool valid) { | ||
valid = callVerifier(P256_VERIFIER, message, rs, pubKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters