PaladinRewardReserve.sol may have potential bugs if it uses new tokens as rewards
The contract's approvedSpenders mapping does not record which token a spender is approved for, so if a new token is added as a reward, existing approvals from a previous token carry over. An attacker already approved for one token could then call updateSpenderAllowance for the new token.
Originally disclosed on Code4rena
Submitted by TerrierLover
PaladinRewardReserve.sol may have potential bugs if it uses new tokens as rewards.
Proof of Concept
Currently, PaladinRewardReserve.sol has following behaviors:
mapping(address => bool) public approvedSpendersdoes not store the info regarding which token it targetssetNewSpender,updateSpenderAllowance,removeSpenderandtransferTokenfunctions can settokenarbitrarily
Hence, some corner cases may happen as follows:
-
Use TokenA at PaladinRewardReserve.sol and do operations.
-
Start TokenB as rewards at PaladinRewardReserve.sol.
-
All the information stored in
approvedSpenderswas intended for TokenA. So it is possible that following corner cases happen:setNewSpenderfunction cannot set new token- If userA is already added in
approvedSpendersfor TokenA, it can callupdateSpenderAllowance.
Recommended Mitigation Steps
Do either of followings depending on the product specification:
(1) If PAL token is only used and other token will never be used at PaladinRewardReserve.sol, stop having address token argument at setNewSpender, updateSpenderAllowance, removeSpender and transferToken functions. Instead, set token at the constructor or other ways, and limit the ability to flexibly set token from functions.
(2) If other tokens potentially will be used at PaladinRewardReserve.sol, update data structure of approvedSpenders mapping and change the logic. Firstly, it should also contain the info which token it targets such as mapping(address => address => bool). Secondly, it should rewrite the require logic at each function as follows.
require(!approvedSpenders[spender][token], "Already Spender on the specified Token");
require(approvedSpenders[spender][token], "Not approved Spender on the specified Token");
Kogaroshi (Paladin) confirmed, resolved, and commented:
Changes made in the PR: PaladinFinance/Paladin-Tokenomics#11.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the approvedSpenders mapping is keyed only by spender address, so approvals are not scoped to a specific token.
Impact
A spender approved for one token could potentially update their allowance for a different token, though the report only describes this as a possible corner case.
What the attacker needed
Contract uses more than one token as reward; attacker already approved for the old token
The fix
The issue was fixed by changing the mapping to include the token address and updating the require checks accordingly.
How it was found
- Use TokenA at PaladinRewardReserve.sol and do operations.
- Start TokenB as rewards at PaladinRewardReserve.sol.
- If userA is already added in approvedSpenders for TokenA, it can call updateSpenderAllowance.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract keeps a list of who is allowed to move its reward tokens. That list only records the person's address, not which token they were approved for. If the contract later starts using a different token, someone approved for the old token may still be treated as approved for the new one.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.