Skip to content

Commit

Permalink
Merge pull request #119 from Gearbox-protocol/mixbytes-fixes
Browse files Browse the repository at this point in the history
fix: fixes based on the Mixbytes audit
  • Loading branch information
Van0k authored Mar 26, 2024
2 parents d001146 + 501b6ce commit 814a6c2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 23 deletions.
20 changes: 20 additions & 0 deletions contracts/adapters/convex/ConvexV1_BaseRewardPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ contract ConvexV1BaseRewardPoolAdapter is AbstractAdapter, IConvexV1BaseRewardPo
/// @notice Address of a reward token of the second extra reward pool, if any
address public immutable override extraReward2;

/// @notice Address of a reward token of the third extra reward pool, if any
address public immutable override extraReward3;

/// @notice Address of a reward token of the fourth extra reward pool, if any
address public immutable override extraReward4;

/// @notice Collateral token mask of a Curve LP token in the credit manager
uint256 public immutable override curveLPTokenMask;

Expand Down Expand Up @@ -77,6 +83,8 @@ contract ConvexV1BaseRewardPoolAdapter is AbstractAdapter, IConvexV1BaseRewardPo

address _extraReward1;
address _extraReward2;
address _extraReward3;
address _extraReward4;
uint256 extraRewardLength = IBaseRewardPool(_baseRewardPool).extraRewardsLength();

if (extraRewardLength >= 1) {
Expand All @@ -87,11 +95,23 @@ contract ConvexV1BaseRewardPoolAdapter is AbstractAdapter, IConvexV1BaseRewardPo
if (extraRewardLength >= 2) {
(_extraReward2, _extraRewardMask) = _getExtraReward(1);
_rewardTokensMask = _rewardTokensMask.enable(_extraRewardMask);

if (extraRewardLength >= 3) {
(_extraReward3, _extraRewardMask) = _getExtraReward(2);
_rewardTokensMask = _rewardTokensMask.enable(_extraRewardMask);

if (extraRewardLength >= 4) {
(_extraReward4, _extraRewardMask) = _getExtraReward(3);
_rewardTokensMask = _rewardTokensMask.enable(_extraRewardMask);
}
}
}
}

extraReward1 = _extraReward1; // U:[CVX1R-2]
extraReward2 = _extraReward2; // U:[CVX1R-2]
extraReward3 = _extraReward3;
extraReward4 = _extraReward4;
rewardTokensMask = _rewardTokensMask; // U:[CVX1R-2]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ interface IConvexV1BaseRewardPoolAdapter is IAdapter {

function extraReward2() external view returns (address);

function extraReward3() external view returns (address);

function extraReward4() external view returns (address);

function curveLPTokenMask() external view returns (uint256);

function stakingTokenMask() external view returns (uint256);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract BaseRewardPoolMock {
address public rewardToken;

uint256 numExtraRewards;
address[2] public extraRewards;
address[4] public extraRewards;

constructor(uint256 _pid, address _operator, address _stakingToken, address _rewardToken) {
pid = _pid;
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/unit/adapters/AdapterUnitTestHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract AdapterUnitTestHelper is Test, CreditManagerV3MockEvents {
CreditManagerV3Mock creditManager;
AddressProviderV3ACLMock addressProvider;

address[8] tokens;
address[10] tokens;

uint256 diffMintedAmount = 1001;
uint256 diffLeftoverAmount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ contract ConvexV1BaseRewardPoolAdapterUnitTest is AdapterUnitTestHelper {

RewardsMock extraReward1;
RewardsMock extraReward2;
RewardsMock extraReward3;
RewardsMock extraReward4;

address curveLPToken;
address convexStakingToken;
Expand All @@ -41,16 +43,16 @@ contract ConvexV1BaseRewardPoolAdapterUnitTest is AdapterUnitTestHelper {

extraReward1 = new RewardsMock(tokens[5]);
extraReward2 = new RewardsMock(address(new ExtraRewardWrapperMock(tokens[6])));
extraReward3 = new RewardsMock(tokens[7]);
extraReward4 = new RewardsMock(tokens[8]);

baseRewardPool = new BaseRewardPoolMock(42, address(booster), convexStakingToken, crv);
baseRewardPool.setExtraReward(0, address(extraReward1));
baseRewardPool.setExtraReward(1, address(extraReward2));
baseRewardPool.setExtraReward(2, address(extraReward3));
baseRewardPool.setExtraReward(3, address(extraReward4));

adapter = new ConvexV1BaseRewardPoolAdapter(
address(creditManager),
address(baseRewardPool),
stakedPhantomToken
);
adapter = new ConvexV1BaseRewardPoolAdapter(address(creditManager), address(baseRewardPool), stakedPhantomToken);
}

/// @notice U:[CVX1R-1]: Constructor works as expected
Expand All @@ -60,11 +62,7 @@ contract ConvexV1BaseRewardPoolAdapterUnitTest is AdapterUnitTestHelper {
_readsTokenMask(stakedPhantomToken);
_readsTokenMask(crv);
_readsTokenMask(cvx);
adapter = new ConvexV1BaseRewardPoolAdapter(
address(creditManager),
address(baseRewardPool),
stakedPhantomToken
);
adapter = new ConvexV1BaseRewardPoolAdapter(address(creditManager), address(baseRewardPool), stakedPhantomToken);

assertEq(adapter.creditManager(), address(creditManager), "Incorrect creditManager");
assertEq(adapter.addressProvider(), address(addressProvider), "Incorrect addressProvider");
Expand All @@ -74,6 +72,8 @@ contract ConvexV1BaseRewardPoolAdapterUnitTest is AdapterUnitTestHelper {
assertEq(adapter.stakedPhantomToken(), stakedPhantomToken, "Incorrect stakedPhantomToken");
assertEq(adapter.extraReward1(), address(0), "Incorrect extraReward1");
assertEq(adapter.extraReward2(), address(0), "Incorrect extraReward2");
assertEq(adapter.extraReward3(), address(0), "Incorrect extraReward3");
assertEq(adapter.extraReward4(), address(0), "Incorrect extraReward4");
assertEq(adapter.curveLPTokenMask(), 1, "Incorrect curveLPTokenMask");
assertEq(adapter.stakingTokenMask(), 2, "Incorrect stakingTokenMask");
assertEq(adapter.stakedTokenMask(), 4, "Incorrect stakedTokenMask");
Expand All @@ -84,26 +84,40 @@ contract ConvexV1BaseRewardPoolAdapterUnitTest is AdapterUnitTestHelper {
function test_U_CVX1R_02_extra_rewards_are_handled_correctly() public {
baseRewardPool.setNumExtraRewards(1);
_readsTokenMask(tokens[5]);
adapter = new ConvexV1BaseRewardPoolAdapter(
address(creditManager),
address(baseRewardPool),
stakedPhantomToken
);
adapter = new ConvexV1BaseRewardPoolAdapter(address(creditManager), address(baseRewardPool), stakedPhantomToken);
assertEq(adapter.extraReward1(), tokens[5], "Incorrect extraReward1");
assertEq(adapter.extraReward2(), address(0), "Incorrect extraReward1");
assertEq(adapter.rewardTokensMask(), 8 + 16 + 32, "Incorrect rewardTokensMask");

baseRewardPool.setNumExtraRewards(2);
_readsTokenMask(tokens[5]);
_readsTokenMask(tokens[6]);
adapter = new ConvexV1BaseRewardPoolAdapter(
address(creditManager),
address(baseRewardPool),
stakedPhantomToken
);
adapter = new ConvexV1BaseRewardPoolAdapter(address(creditManager), address(baseRewardPool), stakedPhantomToken);
assertEq(adapter.extraReward1(), tokens[5], "Incorrect extraReward1");
assertEq(adapter.extraReward2(), tokens[6], "Incorrect extraReward1");
assertEq(adapter.extraReward2(), tokens[6], "Incorrect extraReward2");
assertEq(adapter.rewardTokensMask(), 8 + 16 + 32 + 64, "Incorrect rewardTokensMask");

baseRewardPool.setNumExtraRewards(3);
_readsTokenMask(tokens[5]);
_readsTokenMask(tokens[6]);
_readsTokenMask(tokens[7]);
adapter = new ConvexV1BaseRewardPoolAdapter(address(creditManager), address(baseRewardPool), stakedPhantomToken);
assertEq(adapter.extraReward1(), tokens[5], "Incorrect extraReward1");
assertEq(adapter.extraReward2(), tokens[6], "Incorrect extraReward2");
assertEq(adapter.extraReward3(), tokens[7], "Incorrect extraReward3");
assertEq(adapter.rewardTokensMask(), 8 + 16 + 32 + 64 + 128, "Incorrect rewardTokensMask");

baseRewardPool.setNumExtraRewards(4);
_readsTokenMask(tokens[5]);
_readsTokenMask(tokens[6]);
_readsTokenMask(tokens[7]);
_readsTokenMask(tokens[8]);
adapter = new ConvexV1BaseRewardPoolAdapter(address(creditManager), address(baseRewardPool), stakedPhantomToken);
assertEq(adapter.extraReward1(), tokens[5], "Incorrect extraReward1");
assertEq(adapter.extraReward2(), tokens[6], "Incorrect extraReward2");
assertEq(adapter.extraReward3(), tokens[7], "Incorrect extraReward3");
assertEq(adapter.extraReward4(), tokens[8], "Incorrect extraReward4");
assertEq(adapter.rewardTokensMask(), 8 + 16 + 32 + 64 + 128 + 256, "Incorrect rewardTokensMask");
}

/// @notice U:[CVX1R-3]: Wrapper functions revert on wrong caller
Expand Down

0 comments on commit 814a6c2

Please sign in to comment.