Skip to content

Commit 314c6da

Browse files
Merge pull request #1110 from graphprotocol/ma/horizon-authorizable
Use Authorizable for GraphTallyCollector
2 parents 1869d06 + 9dc80f9 commit 314c6da

File tree

16 files changed

+800
-327
lines changed

16 files changed

+800
-327
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
pragma solidity 0.8.27;
3+
4+
/**
5+
* @title Interface for the {Authorizable} contract
6+
* @notice Implements an authorization scheme that allows authorizers to
7+
* authorize signers to sign on their behalf.
8+
*/
9+
interface IAuthorizable {
10+
/**
11+
* @notice Details for an authorizer-signer pair
12+
* @dev Authorizations can be removed only after a thawing period
13+
*/
14+
struct Authorization {
15+
// Resource owner
16+
address authorizer;
17+
// Timestamp at which thawing period ends (zero if not thawing)
18+
uint256 thawEndTimestamp;
19+
// Whether the signer authorization was revoked
20+
bool revoked;
21+
}
22+
23+
/**
24+
* @notice Emitted when a signer is authorized to sign for a authorizer
25+
* @param authorizer The address of the authorizer
26+
* @param signer The address of the signer
27+
*/
28+
event SignerAuthorized(address indexed authorizer, address indexed signer);
29+
30+
/**
31+
* @notice Emitted when a signer is thawed to be de-authorized
32+
* @param authorizer The address of the authorizer thawing the signer
33+
* @param signer The address of the signer to thaw
34+
* @param thawEndTimestamp The timestamp at which the thawing period ends
35+
*/
36+
event SignerThawing(address indexed authorizer, address indexed signer, uint256 thawEndTimestamp);
37+
38+
/**
39+
* @dev Emitted when the thawing of a signer is cancelled
40+
* @param authorizer The address of the authorizer cancelling the thawing
41+
* @param signer The address of the signer
42+
* @param thawEndTimestamp The timestamp at which the thawing period was scheduled to end
43+
*/
44+
event SignerThawCanceled(address indexed authorizer, address indexed signer, uint256 thawEndTimestamp);
45+
46+
/**
47+
* @dev Emitted when a signer has been revoked after thawing
48+
* @param authorizer The address of the authorizer revoking the signer
49+
* @param signer The address of the signer
50+
*/
51+
event SignerRevoked(address indexed authorizer, address indexed signer);
52+
53+
/**
54+
* Thrown when attempting to authorize a signer that is already authorized
55+
* @param authorizer The address of the authorizer
56+
* @param signer The address of the signer
57+
* @param revoked The revoked status of the authorization
58+
*/
59+
error AuthorizableSignerAlreadyAuthorized(address authorizer, address signer, bool revoked);
60+
61+
/**
62+
* Thrown when the signer proof deadline is invalid
63+
* @param proofDeadline The deadline for the proof provided
64+
* @param currentTimestamp The current timestamp
65+
*/
66+
error AuthorizableInvalidSignerProofDeadline(uint256 proofDeadline, uint256 currentTimestamp);
67+
68+
/**
69+
* Thrown when the signer proof is invalid
70+
*/
71+
error AuthorizableInvalidSignerProof();
72+
73+
/**
74+
* Thrown when the signer is not authorized by the authorizer
75+
* @param authorizer The address of the authorizer
76+
* @param signer The address of the signer
77+
*/
78+
error AuthorizableSignerNotAuthorized(address authorizer, address signer);
79+
80+
/**
81+
* Thrown when the signer is not thawing
82+
* @param signer The address of the signer
83+
*/
84+
error AuthorizableSignerNotThawing(address signer);
85+
86+
/**
87+
* Thrown when the signer is still thawing
88+
* @param currentTimestamp The current timestamp
89+
* @param thawEndTimestamp The timestamp at which the thawing period ends
90+
*/
91+
error AuthorizableSignerStillThawing(uint256 currentTimestamp, uint256 thawEndTimestamp);
92+
93+
/**
94+
* @notice Authorize a signer to sign on behalf of the authorizer
95+
* @dev Requirements:
96+
* - `signer` must not be already authorized
97+
* - `proofDeadline` must be greater than the current timestamp
98+
* - `proof` must be a valid signature from the signer being authorized
99+
*
100+
* Emits a {SignerAuthorized} event
101+
* @param signer The addres of the signer
102+
* @param proofDeadline The deadline for the proof provided by the signer
103+
* @param proof The proof provided by the signer to be authorized by the authorizer
104+
* consists of (chain id, verifying contract address, domain, proof deadline, authorizer address)
105+
*/
106+
function authorizeSigner(address signer, uint256 proofDeadline, bytes calldata proof) external;
107+
108+
/**
109+
* @notice Starts thawing a signer to be de-authorized
110+
* @dev Thawing a signer signals that signatures from that signer will soon be deemed invalid.
111+
* Once a signer is thawed, they should be viewed as revoked regardless of their revocation status.
112+
* If a signer is already thawing and this function is called, the thawing period is reset.
113+
* Requirements:
114+
* - `signer` must be authorized by the authorizer calling this function
115+
*
116+
* Emits a {SignerThawing} event
117+
* @param signer The address of the signer to thaw
118+
*/
119+
function thawSigner(address signer) external;
120+
121+
/**
122+
* @notice Stops thawing a signer.
123+
* @dev Requirements:
124+
* - `signer` must be thawing and authorized by the function caller
125+
*
126+
* Emits a {SignerThawCanceled} event
127+
* @param signer The address of the signer to cancel thawing
128+
*/
129+
function cancelThawSigner(address signer) external;
130+
131+
/**
132+
* @notice Revokes a signer if thawed.
133+
* @dev Requirements:
134+
* - `signer` must be thawed and authorized by the function caller
135+
*
136+
* Emits a {SignerRevoked} event
137+
* @param signer The address of the signer
138+
*/
139+
function revokeAuthorizedSigner(address signer) external;
140+
141+
/**
142+
* @notice Returns the timestamp at which the thawing period ends for a signer
143+
*/
144+
function getThawEnd(address signer) external view returns (uint256);
145+
146+
/**
147+
* @notice Returns true if the signer is authorized by the authorizer
148+
*/
149+
function isAuthorized(address authorizer, address signer) external view returns (bool);
150+
}

packages/horizon/contracts/interfaces/IGraphTallyCollector.sol

Lines changed: 0 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@ import { IGraphPayments } from "./IGraphPayments.sol";
1212
* payments using a GraphTally RAV (Receipt Aggregate Voucher).
1313
*/
1414
interface IGraphTallyCollector is IPaymentsCollector {
15-
/// @notice Details for a payer-signer pair
16-
/// @dev Signers can be removed only after a thawing period
17-
struct PayerAuthorization {
18-
// Payer the signer is authorized to sign for
19-
address payer;
20-
// Timestamp at which thawing period ends (zero if not thawing)
21-
uint256 thawEndTimestamp;
22-
// Whether the signer authorization was revoked
23-
bool revoked;
24-
}
25-
2615
/// @notice The Receipt Aggregate Voucher (RAV) struct
2716
struct ReceiptAggregateVoucher {
2817
// The ID of the collection "bucket" the RAV belongs to. Note that multiple RAVs can be collected for the same collection id.
@@ -50,36 +39,6 @@ interface IGraphTallyCollector is IPaymentsCollector {
5039
bytes signature;
5140
}
5241

53-
/**
54-
* @notice Emitted when a signer is authorized to sign RAVs for a payer
55-
* @param payer The address of the payer authorizing the signer
56-
* @param authorizedSigner The address of the authorized signer
57-
*/
58-
event SignerAuthorized(address indexed payer, address indexed authorizedSigner);
59-
60-
/**
61-
* @notice Emitted when a signer is thawed to be removed from the authorized signers list
62-
* @param payer The address of the payer thawing the signer
63-
* @param authorizedSigner The address of the signer to thaw
64-
* @param thawEndTimestamp The timestamp at which the thawing period ends
65-
*/
66-
event SignerThawing(address indexed payer, address indexed authorizedSigner, uint256 thawEndTimestamp);
67-
68-
/**
69-
* @dev Emitted when the thawing of a signer is cancelled
70-
* @param payer The address of the payer cancelling the thawing
71-
* @param authorizedSigner The address of the authorized signer
72-
* @param thawEndTimestamp The timestamp at which the thawing period ends
73-
*/
74-
event SignerThawCanceled(address indexed payer, address indexed authorizedSigner, uint256 thawEndTimestamp);
75-
76-
/**
77-
* @dev Emitted when a authorized signer has been revoked
78-
* @param payer The address of the payer revoking the signer
79-
* @param authorizedSigner The address of the authorized signer
80-
*/
81-
event SignerRevoked(address indexed payer, address indexed authorizedSigner);
82-
8342
/**
8443
* @notice Emitted when a RAV is collected
8544
* @param collectionId The ID of the collection "bucket" the RAV belongs to.
@@ -102,70 +61,11 @@ interface IGraphTallyCollector is IPaymentsCollector {
10261
bytes signature
10362
);
10463

105-
/**
106-
* Thrown when the signer is already authorized
107-
* @param authorizingPayer The address of the payer authorizing the signer
108-
* @param signer The address of the signer
109-
*/
110-
error GraphTallyCollectorSignerAlreadyAuthorized(address authorizingPayer, address signer);
111-
112-
/**
113-
* Thrown when the signer proof deadline is invalid
114-
* @param proofDeadline The deadline for the proof provided by the signer
115-
* @param currentTimestamp The current timestamp
116-
*/
117-
error GraphTallyCollectorInvalidSignerProofDeadline(uint256 proofDeadline, uint256 currentTimestamp);
118-
119-
/**
120-
* Thrown when the signer proof is invalid
121-
*/
122-
error GraphTallyCollectorInvalidSignerProof();
123-
124-
/**
125-
* Thrown when the signer is not authorized by the payer
126-
* @param payer The address of the payer
127-
* @param signer The address of the signer
128-
*/
129-
error GraphTallyCollectorSignerNotAuthorizedByPayer(address payer, address signer);
130-
131-
/**
132-
* Thrown when the attempting to revoke a signer that was already revoked
133-
* @param signer The address of the signer
134-
*/
135-
error GraphTallyCollectorAuthorizationAlreadyRevoked(address payer, address signer);
136-
137-
/**
138-
* Thrown when attempting to thaw a signer that is already thawing
139-
* @param signer The address of the signer
140-
* @param thawEndTimestamp The timestamp at which the thawing period ends
141-
*/
142-
error GraphTallyCollectorSignerAlreadyThawing(address signer, uint256 thawEndTimestamp);
143-
144-
/**
145-
* Thrown when the signer is not thawing
146-
* @param signer The address of the signer
147-
*/
148-
error GraphTallyCollectorSignerNotThawing(address signer);
149-
150-
/**
151-
* Thrown when the signer is still thawing
152-
* @param currentTimestamp The current timestamp
153-
* @param thawEndTimestamp The timestamp at which the thawing period ends
154-
*/
155-
error GraphTallyCollectorSignerStillThawing(uint256 currentTimestamp, uint256 thawEndTimestamp);
156-
15764
/**
15865
* Thrown when the RAV signer is invalid
15966
*/
16067
error GraphTallyCollectorInvalidRAVSigner();
16168

162-
/**
163-
* Thrown when the RAV payer does not match the signers authorized payer
164-
* @param authorizedPayer The address of the authorized payer
165-
* @param ravPayer The address of the RAV payer
166-
*/
167-
error GraphTallyCollectorInvalidRAVPayer(address authorizedPayer, address ravPayer);
168-
16969
/**
17070
* Thrown when the RAV is for a data service the service provider has no provision for
17171
* @param dataService The address of the data service
@@ -194,55 +94,6 @@ interface IGraphTallyCollector is IPaymentsCollector {
19494
*/
19595
error GraphTallyCollectorInvalidTokensToCollectAmount(uint256 tokensToCollect, uint256 maxTokensToCollect);
19696

197-
/**
198-
* @notice Authorize a signer to sign on behalf of the payer.
199-
* A signer can not be authorized for multiple payers even after revoking previous authorizations.
200-
* @dev Requirements:
201-
* - `signer` must not be already authorized
202-
* - `proofDeadline` must be greater than the current timestamp
203-
* - `proof` must be a valid signature from the signer being authorized
204-
*
205-
* Emits an {SignerAuthorized} event
206-
* @param signer The addres of the authorized signer
207-
* @param proofDeadline The deadline for the proof provided by the signer
208-
* @param proof The proof provided by the signer to be authorized by the payer, consists of (chainID, proof deadline, sender address)
209-
*/
210-
function authorizeSigner(address signer, uint256 proofDeadline, bytes calldata proof) external;
211-
212-
/**
213-
* @notice Starts thawing a signer to be removed from the authorized signers list
214-
* @dev Thawing a signer alerts receivers that signatures from that signer will soon be deemed invalid.
215-
* Receivers without existing signed receipts or RAVs from this signer should treat them as unauthorized.
216-
* Those with existing signed documents from this signer should work towards settling their engagements.
217-
* Once a signer is thawed, they should be viewed as revoked regardless of their revocation status.
218-
* Requirements:
219-
* - `signer` must be authorized by the payer calling this function
220-
*
221-
* Emits a {SignerThawing} event
222-
* @param signer The address of the signer to thaw
223-
*/
224-
function thawSigner(address signer) external;
225-
226-
/**
227-
* @notice Stops thawing a signer.
228-
* @dev Requirements:
229-
* - `signer` must be thawing and authorized by the payer calling this function
230-
*
231-
* Emits a {SignerThawCanceled} event
232-
* @param signer The address of the signer to cancel thawing
233-
*/
234-
function cancelThawSigner(address signer) external;
235-
236-
/**
237-
* @notice Revokes a signer from the authorized signers list if thawed.
238-
* @dev Requirements:
239-
* - `signer` must be thawed and authorized by the payer calling this function
240-
*
241-
* Emits a {SignerRevoked} event
242-
* @param signer The address of the signer
243-
*/
244-
function revokeAuthorizedSigner(address signer) external;
245-
24697
/**
24798
* @notice See {IPaymentsCollector.collect}
24899
* This variant adds the ability to partially collect a RAV by specifying the amount of tokens to collect.

packages/horizon/contracts/mocks/ControllerMock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ contract ControllerMock is IController {
103103
* @param id Contract id (keccak256 hash of contract name)
104104
* @return Address of the proxy contract for the provided id
105105
*/
106-
function getContractProxy(bytes32 id) external view override returns (address) {
106+
function getContractProxy(bytes32 id) external view virtual override returns (address) {
107107
return _registry[id];
108108
}
109109

0 commit comments

Comments
 (0)