Skip to content

Commit 4df5ec0

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 d68a5fe commit 4df5ec0

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

packages/horizon/contracts/interfaces/internal/IHorizonStakingMain.sol

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

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

packages/horizon/contracts/staking/HorizonStaking.sol

+16-9
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,26 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
219219
uint32 newMaxVerifierCut,
220220
uint64 newThawingPeriod
221221
) external override notPaused onlyAuthorized(serviceProvider, verifier) {
222-
require(PPMMath.isValidPPM(newMaxVerifierCut), HorizonStakingInvalidMaxVerifierCut(newMaxVerifierCut));
223-
require(
224-
newThawingPeriod <= _maxThawingPeriod,
225-
HorizonStakingInvalidThawingPeriod(newThawingPeriod, _maxThawingPeriod)
226-
);
227-
228222
// Provision must exist
229223
Provision storage prov = _provisions[serviceProvider][verifier];
230224
require(prov.createdAt != 0, HorizonStakingInvalidProvision(serviceProvider, verifier));
231225

232-
if ((prov.maxVerifierCutPending != newMaxVerifierCut) || (prov.thawingPeriodPending != newThawingPeriod)) {
233-
prov.maxVerifierCutPending = newMaxVerifierCut;
234-
prov.thawingPeriodPending = newThawingPeriod;
226+
bool verifierCutChanged = prov.maxVerifierCutPending != newMaxVerifierCut;
227+
bool thawingPeriodChanged = prov.thawingPeriodPending != newThawingPeriod;
228+
229+
if (verifierCutChanged || thawingPeriodChanged) {
230+
if (verifierCutChanged) {
231+
require(PPMMath.isValidPPM(newMaxVerifierCut), HorizonStakingInvalidMaxVerifierCut(newMaxVerifierCut));
232+
prov.maxVerifierCutPending = newMaxVerifierCut;
233+
}
234+
if (thawingPeriodChanged) {
235+
require(
236+
newThawingPeriod <= _maxThawingPeriod,
237+
HorizonStakingInvalidThawingPeriod(newThawingPeriod, _maxThawingPeriod)
238+
);
239+
prov.thawingPeriodPending = newThawingPeriod;
240+
}
241+
235242
prov.lastParametersStagedAt = block.timestamp;
236243
emit ProvisionParametersStaged(serviceProvider, verifier, newMaxVerifierCut, newThawingPeriod);
237244
}

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)