-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathIScribeOptimistic.sol
176 lines (155 loc) · 7.63 KB
/
IScribeOptimistic.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import {IScribe} from "./IScribe.sol";
interface IScribeOptimistic is IScribe {
/// @notice Thrown if attempted to opPoke while a previous opPoke is still
/// in challenge period.
error InChallengePeriod();
/// @notice Thrown if opChallenge called while no challengeable opPoke exists.
error NoOpPokeToChallenge();
/// @notice Thrown if opChallenge called with SchnorrData not matching
/// opPoke's SchnorrData.
/// @param gotHash The truncated keccak256 hash of the SchnorrData argument.
/// @param wantHash The truncated expected keccak256 hash of the SchnorrData
/// argument.
error SchnorrDataMismatch(uint160 gotHash, uint160 wantHash);
/// @notice Thrown if opPoke called with non-feed ECDSA signature.
/// @param signer The ECDSA signature's signer.
error SignerNotFeed(address signer);
/// @notice Emitted when oracles was successfully opPoked.
/// @param caller The caller's address.
/// @param opFeed The feed that signed the opPoke.
/// @param schnorrData The schnorrData opPoked.
/// @param pokeData The pokeData opPoked.
event OpPoked(
address indexed caller,
address indexed opFeed,
IScribe.SchnorrData schnorrData,
IScribe.PokeData pokeData
);
/// @notice Emitted when successfully challenged an opPoke.
/// @param caller The caller's address.
/// @param schnorrData The schnorrData challenged.
/// @param schnorrErr The abi-encoded custom error returned from the failed
/// Schnorr signature verification.
event OpPokeChallengedSuccessfully(
address indexed caller,
IScribe.SchnorrData schnorrData,
bytes schnorrErr
);
/// @notice Emitted when unsuccessfully challenged an opPoke.
/// @param caller The caller's address.
/// @param schnorrData The schnorrData challenged.
event OpPokeChallengedUnsuccessfully(
address indexed caller, IScribe.SchnorrData schnorrData
);
/// @notice Emitted when ETH reward paid for successfully challenging an
/// opPoke.
/// @param challenger The challenger to which the reward was send.
/// @param schnorrData The schnorrData challenged.
/// @param reward The ETH rewards paid.
event OpChallengeRewardPaid(
address indexed challenger, IScribe.SchnorrData schnorrData, uint reward
);
/// @notice Emitted when an opPoke dropped.
/// @dev opPoke's are dropped if security parameters are updated that could
/// lead to an initially valid opPoke becoming invalid or if an opPoke
/// was successfully challenged.
/// @param caller The caller's address.
/// @param pokeData The pokeData dropped.
event OpPokeDataDropped(address indexed caller, IScribe.PokeData pokeData);
/// @notice Emitted when length of opChallengePeriod updated.
/// @param caller The caller's address.
/// @param oldOpChallengePeriod The old opChallengePeriod's length.
/// @param newOpChallengePeriod The new opChallengePeriod's length.
event OpChallengePeriodUpdated(
address indexed caller,
uint16 oldOpChallengePeriod,
uint16 newOpChallengePeriod
);
/// @notice Emitted when maxChallengeReward updated.
/// @param caller The caller's address.
/// @param oldMaxChallengeReward The old maxChallengeReward.
/// @param newMaxChallengeReward The new maxChallengeReward.
event MaxChallengeRewardUpdated(
address indexed caller,
uint oldMaxChallengeReward,
uint newMaxChallengeReward
);
/// @notice Optimistically pokes the oracle.
/// @dev Expects `pokeData`'s age to be greater than the timestamp of the
/// last successful poke.
/// @dev Expects `pokeData`'s age to not be greater than the current time.
/// @dev Expects `ecdsaData` to be a signature from a feed.
/// @dev Expects `ecdsaData` to prove the integrity of the `pokeData` and
/// `schnorrData`.
/// @dev If the `schnorrData` is proven to be invalid via the opChallenge
/// function, the `ecdsaData` signing feed will be dropped.
/// @param pokeData The PokeData being poked.
/// @param schnorrData The SchnorrData optimistically assumed to be
/// proving the `pokeData`'s integrity.
/// @param ecdsaData The ECDSAData proving the integrity of the
/// `pokeData` and `schnorrData`.
function opPoke(
PokeData calldata pokeData,
SchnorrData calldata schnorrData,
ECDSAData calldata ecdsaData
) external;
/// @notice Challenges the current challengeable opPoke.
/// @dev If opPoke is determined to be invalid, the caller receives an ETH
/// bounty. The bounty is defined via the `challengeReward()(uint)`
/// function.
/// @dev If opPoke is determined to be invalid, the corresponding feed is
/// dropped.
/// @param schnorrData The SchnorrData initially provided via
/// opPoke.
/// @return ok True if opPoke declared invalid, false otherwise.
function opChallenge(SchnorrData calldata schnorrData)
external
returns (bool ok);
/// @notice Returns the message expected to be signed via ECDSA for calling
/// opPoke.
/// @dev The message is defined as:
/// H(tag ‖ H(wat ‖ pokeData ‖ schnorrData)), where H() is the keccak256 function.
/// @param pokeData The pokeData being optimistically poked.
/// @param schnorrData The schnorrData proving `pokeData`'s integrity.
/// @return opPokeMessage Message to be signed for an opPoke for `pokeData`
/// and `schnorrData`.
function constructOpPokeMessage(
PokeData calldata pokeData,
SchnorrData calldata schnorrData
) external view returns (bytes32 opPokeMessage);
/// @notice Returns the feed id of the feed last opPoke'd.
/// @return opFeedId Feed id of the feed last opPoke'd.
function opFeedId() external view returns (uint8 opFeedId);
/// @notice Returns the opChallengePeriod security parameter.
/// @return opChallengePeriod The opChallengePeriod security parameter.
function opChallengePeriod()
external
view
returns (uint16 opChallengePeriod);
/// @notice Returns the maxChallengeRewards parameter.
/// @return maxChallengeReward The maxChallengeReward parameter.
function maxChallengeReward()
external
view
returns (uint maxChallengeReward);
/// @notice Returns the ETH rewards being paid for successfully challenging
/// an opPoke.
/// @return challengeReward The ETH reward for successfully challenging an
/// opPoke.
function challengeReward() external view returns (uint challengeReward);
/// @notice Updates the opChallengePeriod security parameter.
/// @dev Only callable by auth'ed address.
/// @dev Reverts if opChallengePeriod is zero.
/// @dev Note that evaluating whether an opPoke is finalized happens via the
/// _current_ opChallengePeriod.
/// This means a finalized opPoke is dropped if opChallengePeriod is
/// decreased to a value less than opPoke's age.
/// @param opChallengePeriod The value to update opChallengePeriod to.
function setOpChallengePeriod(uint16 opChallengePeriod) external;
/// @notice Updates the maxChallengeReward parameter.
/// @dev Only callable by auth'ed address.
/// @param maxChallengeReward The value to update maxChallengeReward to.
function setMaxChallengeReward(uint maxChallengeReward) external;
}