-
Notifications
You must be signed in to change notification settings - Fork 15
/
Verifier.sol
91 lines (84 loc) · 4.35 KB
/
Verifier.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;
import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import { Common, CommonLib } from "@equilibria/root/verifier/types/Common.sol";
import { VerifierBase } from "@equilibria/root/verifier/VerifierBase.sol";
import { IVerifier } from "./interfaces/IVerifier.sol";
import { Intent, IntentLib } from "./types/Intent.sol";
import { OperatorUpdate, OperatorUpdateLib } from "./types/OperatorUpdate.sol";
import { SignerUpdate, SignerUpdateLib } from "./types/SignerUpdate.sol";
import { AccessUpdateBatch, AccessUpdateBatchLib } from "./types/AccessUpdateBatch.sol";
/// @title Verifier
/// @notice Singleton ERC712 signed message verifier for the Perennial protocol.
/// @dev Handles nonce management for verified messages.
/// - nonce is a single use unique value per message that is invalidated after use
/// - group allows for an entire set of messages to be invalidated via a single cancel operation
///
/// Messages verification request must come from the domain address if it is set.
/// - In the case of intent / fills, this means that the market should be set as the domain.
///
contract Verifier is VerifierBase, IVerifier {
/// @dev Initializes the domain separator and parameter caches
constructor() EIP712("Perennial", "1.0.0") { }
/// @notice Verifies the signature of an intent order type
/// @dev Cancels the nonce after verifying the signature
/// Reverts if the signature does not match the signer
/// @param intent The intent order to verify
/// @param signature The signature of the taker for the intent order
function verifyIntent(Intent calldata intent, bytes calldata signature)
external
validateAndCancel(intent.common, signature)
{
if (!SignatureChecker.isValidSignatureNow(
intent.common.signer,
_hashTypedDataV4(IntentLib.hash(intent)),
signature
)) revert VerifierInvalidSignerError();
}
/// @notice Verifies the signature of a operator update type
/// @dev Cancels the nonce after verifying the signature
/// Reverts if the signature does not match the signer
/// @param operatorUpdate The operator update message to verify
/// @param signature The signature of the account for the operator update
function verifyOperatorUpdate(OperatorUpdate calldata operatorUpdate, bytes calldata signature)
external
validateAndCancel(operatorUpdate.common, signature)
{
if (!SignatureChecker.isValidSignatureNow(
operatorUpdate.common.signer,
_hashTypedDataV4(OperatorUpdateLib.hash(operatorUpdate)),
signature
)) revert VerifierInvalidSignerError();
}
/// @notice Verifies the signature of a signer update type
/// @dev Cancels the nonce after verifying the signature
/// Reverts if the signature does not match the signer
/// @param signerUpdate The signer update message to verify
/// @param signature The signature of the account for the signer update
function verifySignerUpdate(SignerUpdate calldata signerUpdate, bytes calldata signature)
external
validateAndCancel(signerUpdate.common, signature)
{
if (!SignatureChecker.isValidSignatureNow(
signerUpdate.common.signer,
_hashTypedDataV4(SignerUpdateLib.hash(signerUpdate)),
signature
)) revert VerifierInvalidSignerError();
}
/// @notice Verifies the signature of an access update batch type
/// @dev Cancels the nonce after verifying the signature
/// Reverts if the signature does not match the signer
/// @param accessUpdateBatch The batch access update (operator and signer) message to verify
/// @param signature The signature of the account for the batch access update
function verifyAccessUpdateBatch(AccessUpdateBatch calldata accessUpdateBatch, bytes calldata signature)
external
validateAndCancel(accessUpdateBatch.common, signature)
{
if (!SignatureChecker.isValidSignatureNow(
accessUpdateBatch.common.signer,
_hashTypedDataV4(AccessUpdateBatchLib.hash(accessUpdateBatch)),
signature
)) revert VerifierInvalidSignerError();
}
}