You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 12, 2025. It is now read-only.
function deposit(
uint256periodId,
uint256tokenId,
uint256deltaAmount
) public onlyVoter { //@audit only voter can call deposit, otherwise things will be messed up_modify(periodId, tokenId, deltaAmount.toInt256(), false);
emitDeposited(periodId, tokenId, _pool(), deltaAmount);
}
any call to Voter::vote function will be reverted if there exist at least one BribeRewarder for current epoch, the only fix will be to either ignore all bribe rewarders by moving into next epoch which does not have any rewarders, however, since rewarders can be created an added into an epoch by anyone, this approach might not be feasable, making the impact of this issue higher.
Code Snippet
Tool used
Manual Review
Recommendation
to resolve this issue, pass msg.sender (the address who invoked Voter::vote) into BribeRewarder::deposit function, this requires BribeRewarder::deposit and BribeRewarder::_modify to be changed slightly taking one more parameter (caster):
BribeRewarder.sol:
function deposit(
uint256periodId,
uint256tokenId,
uint256deltaAmountaddress caster //address casting votes
) public onlyVoter {
_modify(periodId, tokenId, deltaAmount.toInt256(), caster, false);
emitDeposited(periodId, tokenId, _pool(), deltaAmount);
}
function _modify(
uint256periodId,
uint256tokenId,
int256deltaAmount,
addresscaster,
boolisPayOutReward
) privatereturns (uint256rewardAmount) {
//pass vote caster as owner of this positionif (!IVoter(_caller).ownerOf(tokenId, caster)) {
revertBribeRewarder__NotOwner();
}
//...
}
Voter.sol:
function _notifyBribes(
uint256periodId,
addresspool,
uint256tokenId,
uint256deltaAmount
) private {
IBribeRewarder[] storage rewarders = _bribesPerPriod[periodId][pool];
for (uint256 i =0; i < rewarders.length; ++i) {
if (address(rewarders[i]) !=address(0)) {
//@audit-fix pass msg.sender as voter
rewarders[i].deposit(periodId, tokenId, deltaAmount, msg.sender);
_userBribesPerPeriod[periodId][tokenId].push(rewarders[i]);
}
}
}
sherlock-admin4
changed the title
Sticky Hickory Hare - BribeRewarder uses wrong address to check owner of tokenId
rsam_eth - BribeRewarder uses wrong address to check owner of tokenId
Jul 29, 2024
rsam_eth
High
BribeRewarder uses wrong address to check owner of tokenId
Summary
Vulnerability Detail
after casting a vote for a pid, the voted amount will be deposited into a
BribeRewarder
:https://github.com/sherlock-audit/2024-06-magicsea/blob/main/magicsea-staking/src/Voter.sol#L211
_notifyBribes(_currentVotingPeriodId, pool, tokenId, deltaAmount);
the
BribeRewarder::deposit
function is called here fromVoter
:https://github.com/sherlock-audit/2024-06-magicsea/blob/main/magicsea-staking/src/Voter.sol#L225
we can see that only voter contract is able to call
BribeRewarder::deposit
:https://github.com/sherlock-audit/2024-06-magicsea/blob/main/magicsea-staking/src/rewarders/BribeRewarder.sol#L143-L147
However, on the next line,
_modify
function is passing wrong address (msg.sender which is address of voter) asaccount parameter
inVoter::ownerOf
function:https://github.com/sherlock-audit/2024-06-magicsea/blob/main/magicsea-staking/src/rewarders/BribeRewarder.sol#L264-L266
Voter::ownerOf
function expects second parameter (account
) to be owner oftokenId
, but since voter doesn't own that nft, deposit function will revert, which in result revertsVote::vote
function rendering voting process impossible:https://github.com/sherlock-audit/2024-06-magicsea/blob/main/magicsea-staking/src/Voter.sol#L402-L404
Impact
any call to
Voter::vote
function will be reverted if there exist at least oneBribeRewarder
for current epoch, the only fix will be to either ignore all bribe rewarders by moving into next epoch which does not have any rewarders, however, since rewarders can be created an added into an epoch by anyone, this approach might not be feasable, making the impact of this issue higher.Code Snippet
Tool used
Manual Review
Recommendation
to resolve this issue, pass
msg.sender
(the address who invokedVoter::vote
) intoBribeRewarder::deposit
function, this requiresBribeRewarder::deposit
andBribeRewarder::_modify
to be changed slightly taking one more parameter (caster
):BribeRewarder.sol:
Voter.sol:
Duplicate of #39
The text was updated successfully, but these errors were encountered: