Skip to content

Commit f468a7d

Browse files
authored
Merge pull request from GHSA-pcvp-3h5m-87rf
Advisory fix 1
2 parents 7ed8000 + 2be870b commit f468a7d

File tree

5 files changed

+21
-193
lines changed

5 files changed

+21
-193
lines changed

contracts/staking/IStaking.sol

-6
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ interface IStaking {
7070
address authorizer
7171
) external;
7272

73-
/// @notice Refresh Keep stake owner. Can be called only by the old owner
74-
/// or their staking provider.
75-
/// @dev The staking provider in T staking contract is the legacy KEEP
76-
/// staking contract operator.
77-
function refreshKeepStakeOwner(address stakingProvider) external;
78-
7973
/// @notice Allows the Governance to set the minimum required stake amount.
8074
/// This amount is required to protect against griefing the staking
8175
/// contract and individual applications are allowed to require

contracts/staking/TokenStaking.sol

+11-27
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
214214
_;
215215
}
216216

217+
modifier onlyOwnerOf(address stakingProvider) {
218+
require(
219+
stakingProviders[stakingProvider].owner == msg.sender,
220+
"Caller is not owner"
221+
);
222+
_;
223+
}
224+
217225
/// @param _token Address of T token contract
218226
/// @param _keepStakingContract Address of Keep staking contract
219227
/// @param _nucypherStakingContract Address of NuCypher staking contract
@@ -400,28 +408,6 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
400408
);
401409
}
402410

403-
/// @notice Refresh Keep stake owner. Can be called only by the old owner
404-
/// or their staking provider.
405-
/// @dev The staking provider in T staking contract is the legacy KEEP
406-
/// staking contract operator.
407-
function refreshKeepStakeOwner(address stakingProvider)
408-
external
409-
override
410-
onlyOwnerOrStakingProvider(stakingProvider)
411-
{
412-
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
413-
stakingProvider
414-
];
415-
address newOwner = keepStake.resolveOwner(stakingProvider);
416-
417-
emit OwnerRefreshed(
418-
stakingProvider,
419-
stakingProviderStruct.owner,
420-
newOwner
421-
);
422-
stakingProviderStruct.owner = newOwner;
423-
}
424-
425411
/// @notice Allows the Governance to set the minimum required stake amount.
426412
/// This amount is required to protect against griefing the staking
427413
/// contract and individual applications are allowed to require
@@ -480,6 +466,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
480466
address application,
481467
uint96 amount
482468
) external override onlyAuthorizerOf(stakingProvider) {
469+
require(amount > 0, "Parameters must be specified");
483470
ApplicationInfo storage applicationStruct = applicationInfo[
484471
application
485472
];
@@ -763,7 +750,7 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
763750
function topUpNu(address stakingProvider)
764751
external
765752
override
766-
onlyOwnerOrStakingProvider(stakingProvider)
753+
onlyOwnerOf(stakingProvider)
767754
{
768755
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
769756
stakingProvider
@@ -1420,14 +1407,11 @@ contract TokenStaking is Initializable, IStaking, Checkpoints {
14201407
internal
14211408
virtual
14221409
override
1410+
onlyOwnerOf(stakingProvider)
14231411
{
14241412
StakingProviderInfo storage stakingProviderStruct = stakingProviders[
14251413
stakingProvider
14261414
];
1427-
require(
1428-
stakingProviderStruct.owner == msg.sender,
1429-
"Caller is not owner"
1430-
);
14311415
uint96 stakingProviderBalance = stakingProviderStruct.tStake +
14321416
stakingProviderStruct.keepInTStake +
14331417
stakingProviderStruct.nuInTStake;

contracts/test/KeepRegistryStub.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ contract KeepRegistryStub is IKeepRegistry {
99

1010
event OperatorContractApproved(address operatorContract);
1111

12-
constructor() public {
12+
constructor() {
1313
registryKeeper = msg.sender;
1414
}
1515

docs/rfc-1-staking-contract.adoc

-4
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,6 @@ additionally appointing beneficiary and authorizer roles. Caches the amount
307307
staked in NU staking contract. Can be called only by the original delegation
308308
owner.
309309

310-
==== `refreshKeepStakeOwner(address stakingProvider) external onlyOwnerOf(stakingProvider)`
311-
312-
Refresh Keep stake owner. Can be called only by the old owner.
313-
314310
==== `setMinimumStakeAmount(uint96 amount) external onlyGovernance`
315311

316312
Allows the governance to set the minimum required stake amount. This amount is

test/staking/TokenStaking.test.js

+9-155
Original file line numberDiff line numberDiff line change
@@ -852,152 +852,6 @@ describe("TokenStaking", () => {
852852
})
853853
})
854854

855-
describe("refreshKeepManagedGrantOwner", () => {
856-
context("when staking provider has no delegated stake", () => {
857-
it("should revert", async () => {
858-
await expect(
859-
tokenStaking
860-
.connect(stakingProvider)
861-
.refreshKeepStakeOwner(stakingProvider.address)
862-
).to.be.revertedWith("Not owner or provider")
863-
})
864-
})
865-
866-
context("when caller is neither old owner nor staking provider", () => {
867-
it("should revert", async () => {
868-
await tToken
869-
.connect(staker)
870-
.approve(tokenStaking.address, initialStakerBalance)
871-
await tokenStaking
872-
.connect(staker)
873-
.stake(
874-
stakingProvider.address,
875-
beneficiary.address,
876-
authorizer.address,
877-
initialStakerBalance
878-
)
879-
await expect(
880-
tokenStaking
881-
.connect(authorizer)
882-
.refreshKeepStakeOwner(stakingProvider.address)
883-
).to.be.revertedWith("Not owner or provider")
884-
})
885-
})
886-
887-
const contextRefreshKeepStakeOwner = (getCaller) => {
888-
context("when grantee was not changed", () => {
889-
let tx
890-
891-
beforeEach(async () => {
892-
const createdAt = 1
893-
await keepStakingMock.setOperator(
894-
stakingProvider.address,
895-
staker.address,
896-
beneficiary.address,
897-
authorizer.address,
898-
createdAt,
899-
0,
900-
initialStakerBalance
901-
)
902-
await keepStakingMock.setEligibility(
903-
stakingProvider.address,
904-
tokenStaking.address,
905-
true
906-
)
907-
await tokenStaking.stakeKeep(stakingProvider.address)
908-
909-
tx = await tokenStaking
910-
.connect(getCaller())
911-
.refreshKeepStakeOwner(stakingProvider.address)
912-
})
913-
914-
it("should not update owner", async () => {
915-
expect(
916-
await tokenStaking.rolesOf(stakingProvider.address)
917-
).to.deep.equal([
918-
staker.address,
919-
beneficiary.address,
920-
authorizer.address,
921-
])
922-
})
923-
924-
it("should emit OwnerRefreshed", async () => {
925-
await expect(tx)
926-
.to.emit(tokenStaking, "OwnerRefreshed")
927-
.withArgs(stakingProvider.address, staker.address, staker.address)
928-
})
929-
})
930-
931-
context("when grantee was changed", () => {
932-
let tx
933-
934-
beforeEach(async () => {
935-
const createdAt = 1
936-
await keepStakingMock.setOperator(
937-
stakingProvider.address,
938-
otherStaker.address,
939-
beneficiary.address,
940-
authorizer.address,
941-
createdAt,
942-
0,
943-
initialStakerBalance
944-
)
945-
await keepStakingMock.setEligibility(
946-
stakingProvider.address,
947-
tokenStaking.address,
948-
true
949-
)
950-
await tokenStaking.stakeKeep(stakingProvider.address)
951-
952-
await keepStakingMock.setOperator(
953-
stakingProvider.address,
954-
staker.address,
955-
beneficiary.address,
956-
authorizer.address,
957-
createdAt,
958-
0,
959-
initialStakerBalance
960-
)
961-
tx = await tokenStaking
962-
.connect(otherStaker)
963-
.refreshKeepStakeOwner(stakingProvider.address)
964-
})
965-
966-
it("should update owner", async () => {
967-
expect(
968-
await tokenStaking.rolesOf(stakingProvider.address)
969-
).to.deep.equal([
970-
staker.address,
971-
beneficiary.address,
972-
authorizer.address,
973-
])
974-
})
975-
976-
it("should emit OwnerRefreshed", async () => {
977-
await expect(tx)
978-
.to.emit(tokenStaking, "OwnerRefreshed")
979-
.withArgs(
980-
stakingProvider.address,
981-
otherStaker.address,
982-
staker.address
983-
)
984-
})
985-
})
986-
}
987-
988-
context("when caller is the old owner", () => {
989-
contextRefreshKeepStakeOwner(() => {
990-
return staker
991-
})
992-
})
993-
994-
context("when caller is the staking provider", () => {
995-
contextRefreshKeepStakeOwner(() => {
996-
return stakingProvider
997-
})
998-
})
999-
})
1000-
1001855
describe("approveApplication", () => {
1002856
context("when caller is not the governance", () => {
1003857
it("should revert", async () => {
@@ -1526,7 +1380,7 @@ describe("TokenStaking", () => {
15261380

15271381
await nucypherStakingMock.setStaker(staker.address, nuStake)
15281382
await tokenStaking
1529-
.connect(stakingProvider)
1383+
.connect(staker)
15301384
.topUpNu(stakingProvider.address)
15311385

15321386
await tToken.connect(staker).approve(tokenStaking.address, tStake)
@@ -3514,12 +3368,12 @@ describe("TokenStaking", () => {
35143368
context("when staking provider has no delegated stake", () => {
35153369
it("should revert", async () => {
35163370
await expect(
3517-
tokenStaking.connect(stakingProvider).topUpNu(stakingProvider.address)
3518-
).to.be.revertedWith("Not owner or provider")
3371+
tokenStaking.connect(staker).topUpNu(stakingProvider.address)
3372+
).to.be.revertedWith("Caller is not owner")
35193373
})
35203374
})
35213375

3522-
context("when caller is not owner or staking provider", () => {
3376+
context("when caller is not owner", () => {
35233377
it("should revert", async () => {
35243378
await tToken
35253379
.connect(staker)
@@ -3533,8 +3387,8 @@ describe("TokenStaking", () => {
35333387
initialStakerBalance
35343388
)
35353389
await expect(
3536-
tokenStaking.connect(authorizer).topUpNu(stakingProvider.address)
3537-
).to.be.revertedWith("Not owner or provider")
3390+
tokenStaking.connect(stakingProvider).topUpNu(stakingProvider.address)
3391+
).to.be.revertedWith("Caller is not owner")
35383392
})
35393393
})
35403394

@@ -3551,7 +3405,7 @@ describe("TokenStaking", () => {
35513405
amount
35523406
)
35533407
await expect(
3554-
tokenStaking.connect(stakingProvider).topUpNu(stakingProvider.address)
3408+
tokenStaking.connect(staker).topUpNu(stakingProvider.address)
35553409
).to.be.revertedWith("Nothing to top-up")
35563410
})
35573411
})
@@ -3684,7 +3538,7 @@ describe("TokenStaking", () => {
36843538
.connect(staker)
36853539
.unstakeNu(stakingProvider.address, nuInTAmount)
36863540
tx = await tokenStaking
3687-
.connect(stakingProvider)
3541+
.connect(staker)
36883542
.topUpNu(stakingProvider.address)
36893543
})
36903544

@@ -3804,7 +3658,7 @@ describe("TokenStaking", () => {
38043658

38053659
await nucypherStakingMock.setStaker(staker.address, nuAmount)
38063660
tx = await tokenStaking
3807-
.connect(stakingProvider)
3661+
.connect(staker)
38083662
.topUpNu(stakingProvider.address)
38093663
})
38103664

0 commit comments

Comments
 (0)