Skip to content

Commit b886ab4

Browse files
committed
fix: only check conditions for param that is changing when changing provision params (OZ L-05)
Signed-off-by: Tomás Migone <[email protected]>
1 parent 3881b28 commit b886ab4

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

Diff for: packages/horizon/contracts/interfaces/internal/IHorizonStakingMain.sol

+6-1
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,15 @@ interface IHorizonStakingMain {
699699

700700
/**
701701
* @notice Stages a provision parameter update. Note that the change is not effective until the verifier calls
702-
* {acceptProvisionParameters}.
702+
* {acceptProvisionParameters}. Calling this function is a no-op if the new parameters are the same as the current
703+
* ones.
703704
* @dev This two step update process prevents the service provider from changing the parameters
704705
* without the verifier's consent.
705706
*
707+
* Requirements:
708+
* - `thawingPeriod` must be less than or equal to `_maxThawingPeriod`. Note that if `_maxThawingPeriod` changes the
709+
* function will not revert if called with the same thawing period as the current one.
710+
*
706711
* Emits a {ProvisionParametersStaged} event if at least one of the parameters changed.
707712
*
708713
* @param serviceProvider The service provider address

Diff for: packages/horizon/contracts/staking/HorizonStaking.sol

+16-9
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,26 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
202202
uint32 newMaxVerifierCut,
203203
uint64 newThawingPeriod
204204
) external override notPaused onlyAuthorized(serviceProvider, verifier) {
205-
require(PPMMath.isValidPPM(newMaxVerifierCut), HorizonStakingInvalidMaxVerifierCut(newMaxVerifierCut));
206-
require(
207-
newThawingPeriod <= _maxThawingPeriod,
208-
HorizonStakingInvalidThawingPeriod(newThawingPeriod, _maxThawingPeriod)
209-
);
210-
211205
// Provision must exist
212206
Provision storage prov = _provisions[serviceProvider][verifier];
213207
require(prov.createdAt != 0, HorizonStakingInvalidProvision(serviceProvider, verifier));
214208

215-
if ((prov.maxVerifierCutPending != newMaxVerifierCut) || (prov.thawingPeriodPending != newThawingPeriod)) {
216-
prov.maxVerifierCutPending = newMaxVerifierCut;
217-
prov.thawingPeriodPending = newThawingPeriod;
209+
bool verifierCutChanged = prov.maxVerifierCutPending != newMaxVerifierCut;
210+
bool thawingPeriodChanged = prov.thawingPeriodPending != newThawingPeriod;
211+
212+
if (verifierCutChanged || thawingPeriodChanged) {
213+
if (verifierCutChanged) {
214+
require(PPMMath.isValidPPM(newMaxVerifierCut), HorizonStakingInvalidMaxVerifierCut(newMaxVerifierCut));
215+
prov.maxVerifierCutPending = newMaxVerifierCut;
216+
}
217+
if (thawingPeriodChanged) {
218+
require(
219+
newThawingPeriod <= _maxThawingPeriod,
220+
HorizonStakingInvalidThawingPeriod(newThawingPeriod, _maxThawingPeriod)
221+
);
222+
prov.thawingPeriodPending = newThawingPeriod;
223+
}
224+
218225
prov.lastParametersStagedAt = block.timestamp;
219226
emit ProvisionParametersStaged(serviceProvider, verifier, newMaxVerifierCut, newThawingPeriod);
220227
}

Diff for: packages/horizon/test/staking/provision/parameters.t.sol

+35
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,41 @@ contract HorizonStakingProvisionParametersTest is HorizonStakingTest {
7070
staking.setProvisionParameters(users.indexer, subgraphDataServiceAddress, maxVerifierCut, thawingPeriod);
7171
}
7272

73+
function test_ProvisionParametersSet_MaxMaxThawingPeriodChanged(
74+
uint256 amount,
75+
uint32 maxVerifierCut,
76+
uint64 thawingPeriod
77+
) public useIndexer {
78+
vm.assume(amount > 0);
79+
vm.assume(amount <= MAX_STAKING_TOKENS);
80+
vm.assume(maxVerifierCut <= MAX_PPM);
81+
82+
// create provision with initial parameters
83+
uint32 initialMaxVerifierCut = 1000;
84+
uint64 initialThawingPeriod = 14 days; // Max thawing period is 28 days
85+
_createProvision(users.indexer, subgraphDataServiceAddress, amount, initialMaxVerifierCut, initialThawingPeriod);
86+
87+
// change the max thawing period allowed so that the initial thawing period is not valid anymore
88+
uint64 newMaxThawingPeriod = 7 days;
89+
resetPrank(users.governor);
90+
_setMaxThawingPeriod(newMaxThawingPeriod);
91+
92+
// set the verifier cut to a new value - keep the thawing period the same, it should be allowed
93+
resetPrank(users.indexer);
94+
_setProvisionParameters(users.indexer, subgraphDataServiceAddress, maxVerifierCut, initialThawingPeriod);
95+
96+
// now try to change the thawing period to a new value that is invalid
97+
vm.assume(thawingPeriod > initialThawingPeriod);
98+
vm.expectRevert(
99+
abi.encodeWithSelector(
100+
IHorizonStakingMain.HorizonStakingInvalidThawingPeriod.selector,
101+
thawingPeriod,
102+
newMaxThawingPeriod
103+
)
104+
);
105+
staking.setProvisionParameters(users.indexer, subgraphDataServiceAddress, maxVerifierCut, thawingPeriod);
106+
}
107+
73108
function test_ProvisionParametersAccept(
74109
uint256 amount,
75110
uint32 maxVerifierCut,

0 commit comments

Comments
 (0)