Pausing WardenPledge contract, which takes effect immediately, by its owner can unexpectedly block pledge creator from calling closePledge or retrievePledgeRewards function
The WardenPledge contract's pause function, callable by the owner, immediately blocks pledge creators from calling closePledge or retrievePledgeRewards, which use the whenNotPaused modifier. This can unexpectedly prevent creators from withdrawing their deposited reward tokens, potentially causing financial hardship.
rbserver Follow with 0x1f8b, 0xSmartContract and 5 others
Originally disclosed on Code4rena
Submitted by rbserver, also found by 0x1f8b, 0xSmartContract, Trust, hansfriese, ctf_sec, cccz, and codexploder
https://github.com/code-423n4/2022-10-paladin/blob/main/contracts/WardenPledge.sol#L636-L638
https://github.com/code-423n4/2022-10-paladin/blob/main/contracts/WardenPledge.sol#L488-L515
https://github.com/code-423n4/2022-10-paladin/blob/main/contracts/WardenPledge.sol#L456-L480
Impact
The owner of the WardenPledge contract is able to call the pause function to pause this contract. When the WardenPledge contract is paused, calling the closePledge or retrievePledgeRewards function that uses the whenNotPaused modifier reverts, and the pledge creator is not able to get back any of the reward token amount, which was deposited by the creator previously. Because calling the pause function takes effect immediately, it can be unexpected to the creator for suddenly not being able to call the closePledge or retrievePledgeRewards function. For instance, when an emergency occurs that requires an increase of cash flow, the creator wants to close the pledge early so she or he can use the remaining deposited reward token amount. However, just before the creator’s closePledge transaction is executed, the pause transaction has been sent by the owner of the WardenPledge contract for some reason and executed. Without knowing in advance that the WardenPledge contract would be paused, the creator anticipates receiving the remaining deposited reward token amount but this is not the case since calling the closePledge function reverts. Because the creator unexpectedly fails to receive such amount and might fail to deal with the emergency, disputes with the protocol can occur, and the user experience becomes degraded.
https://github.com/code-423n4/2022-10-paladin/blob/main/contracts/WardenPledge.sol#L636-L638
function pause() external onlyOwner {
_pause();
}
https://github.com/code-423n4/2022-10-paladin/blob/main/contracts/WardenPledge.sol#L488-L515
function closePledge(uint256 pledgeId, address receiver) external whenNotPaused nonReentrant {
...
// Get the current remaining amount of rewards not distributed for the Pledge
uint256 remainingAmount = pledgeAvailableRewardAmounts[pledgeId];
if(remainingAmount > 0) {
// Transfer the non used rewards and reset storage
pledgeAvailableRewardAmounts[pledgeId] = 0;
IERC20(pledgeParams.rewardToken).safeTransfer(receiver, remainingAmount);
...
}
...
}
https://github.com/code-423n4/2022-10-paladin/blob/main/contracts/WardenPledge.sol#L456-L480
function retrievePledgeRewards(uint256 pledgeId, address receiver) external whenNotPaused nonReentrant {
...
// Get the current remaining amount of rewards not distributed for the Pledge
uint256 remainingAmount = pledgeAvailableRewardAmounts[pledgeId];
...
if(remainingAmount > 0) {
// Transfer the non used rewards and reset storage
pledgeAvailableRewardAmounts[pledgeId] = 0;
IERC20(pledgeParams.rewardToken).safeTransfer(receiver, remainingAmount);
...
}
}
Proof of Concept
Please append the following test in the pause & unpause describe block in test\wardenPledge.test.ts. This test will pass to demonstrate the described scenario.
it.only('Pausing WardenPledge contract, which takes effect immediately, by its owner can unexpectedly block pledge creator from calling closePledge function', async () => {
// before calling the createPledge function, the wardenPledge contract owns no rewardToken1
const rewardToken1BalanceWardenPledgeBefore = await rewardToken1.balanceOf(wardenPledge.address)
expect(rewardToken1BalanceWardenPledgeBefore).to.be.eq(0)
const rewardToken1BalanceCreatorBefore = await rewardToken1.balanceOf(creator.address)
// creator calls the createPledge function
await wardenPledge.connect(creator).createPledge(
receiver.address,
rewardToken1.address,
target_votes,
reward_per_vote,
end_timestamp,
max_total_reward_amount,
max_fee_amount
)
// after one week, admin, who is the owner of the wardenPledge contract, calls the pause function, which takes effect immediately
await advanceTime(WEEK.toNumber())
await wardenPledge.connect(admin).pause()
// Since an emergency that requires an increase of cash flow occurs, creator decides to close the pledge for getting back the deposited rewardToken1 amount.
// Without knowing in advance that the wardenPledge contract would be paused,
// creator calls the closePledge function and anticipates to receive the deposited rewardToken1 amount.
// Unfortunately, admin's pause transaction has been executed just before creator's closePledge transaction is executed, which causes creator's closePledge transaction to revert.
await expect(
wardenPledge.connect(creator).closePledge(pledge_id, creator.address)
).to.be.revertedWith("Pausable: paused")
// after creator's closePledge transaction reverts, creator does not receive the deposited rewardToken1 amount, which is unexpected to her or him
const rewardToken1BalanceCreatorAfter = await rewardToken1.balanceOf(creator.address)
expect(rewardToken1BalanceCreatorAfter).to.be.lt(rewardToken1BalanceCreatorBefore)
// meanwhile, the wardenPledge contract still holds the creator's deposited rewardToken1 amount
const rewardToken1BalanceWardenPledgeAfter = await rewardToken1.balanceOf(wardenPledge.address)
expect(rewardToken1BalanceWardenPledgeAfter).to.be.gt(0)
});
Tools Used
VSCode
Recommended Mitigation Steps
The pause function can be updated to be time-delayed so the pledge creator can have more time to react. One way would be making this function only callable by a timelock governance contract.
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
The pause function takes effect immediately and blocks functions that return funds to users, without any delay or grace period.
Impact
A pledge creator may be unable to retrieve their deposited reward tokens when the contract is paused, potentially causing financial difficulties, though this requires the owner to pause the contract.
What the attacker needed
Creator has an active pledge with deposited rewards; contract owner pauses the contract
The fix
The pause function should be time-delayed, for example by making it only callable by a timelock governance contract, to give creators time to react.
How it was found
- Creator calls createPledge to deposit reward tokens.
- After some time, the contract owner calls pause, which takes effect immediately.
- Creator attempts to call closePledge to withdraw remaining rewards, but the transaction reverts due to the whenNotPaused modifier.
- The creator does not receive the deposited tokens, and the contract still holds them.
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 can have a pause button that stops certain actions. Here, the owner can pause the contract at any time, and when paused, users cannot withdraw their deposited tokens. This means a user might suddenly be unable to get their money back, which is unfair if they need it urgently.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.