ZeroLend token is not behaving properly while c
The ZeroLend token's transfer check used a condition that blocked whitelisted users whenever the contract was paused, instead of allowing them through. As a result, whitelisted users could not transfer tokens during the prelaunch paused phase, contrary to the intended design.
- Disclosed after under an hour
29137 - [SC - High] ZeroLend token is not behaving properly while c...
Submitted on Mar 8th 2024 at 09:38:30 UTC by @dontonka for Boost | ZeroLend
Report ID: #29137
Report type: Smart Contract
Report severity: High
Target: https://github.com/zerolend/governance
Impacts:
- ZeroLendToken not properly behaving in prelaunch phase
Description
Brief/Intro
ZeroLendToken should allow to operate with Whitelisted users even if contract is paused, which is not the case in the current implementation which seems to warrant Low severity.
Vulnerability Details
The current condition is inaccurate.
Impact Details
Whitelisted user will not be able to use the contract while the contract is paused.
Recommendation
Apply the following changes.
function _update(
address from,
address to,
uint256 value
) internal virtual override {
require(!blacklisted[from] && !blacklisted[to], "blacklisted");
- require(!paused && !whitelisted[from], "paused");
+ require(!paused || (whitelisted[from] || whitelisted[to]), "paused");
super._update(from, to, value);
}
Proof of Concept
Run the following command to create the fresh testing environnement based on Foundry.
foundryup
forge init zerolend
cd zerolend
forge install OpenZeppelin/openzeppelin-contracts
Create `ZeroLendToken.sol` in src
Create `ZeroLendToken.t.sol` in test
rm src/Counter.sol
rm test/Counter.t.sol
forge test --match-test
[PASS] test_owner_transfer_to_bl() (gas: 15619)
[PASS] test_owner_transfer_to_normal() (gas: 17743)
[FAIL. Reason: revert: paused] test_owner_transfer_to_wl() (gas: 14356)
Suite result: FAILED. 2 passed; 1 failed; 0 skipped; finished in 1.22ms (231.74µs CPU time)
Ran 1 test suite in 385.67ms (1.22ms CPU time): 2 tests passed, 1 failed, 0 skipped (3 total tests)
Failing tests:
Encountered 1 failing test in test/ZeroLendToken.t.sol:ZeroLendTokenTest
[FAIL. Reason: revert: paused] test_owner_transfer_to_wl() (gas: 14356)
Apply the recommended fix and test will pass as follow.
Ran 3 tests for test/ZeroLendToken.t.sol:ZeroLendTokenTest
[PASS] test_owner_transfer_to_bl() (gas: 15619)
[PASS] test_owner_transfer_to_normal() (gas: 22152)
[PASS] test_owner_transfer_to_wl() (gas: 48299)
Suite result: ok. 3 passed; 0 failed; 0 skipped; finished in 1.31ms (312.34µs CPU time)
ZeroLendToken.sol, the original file.
ZeroLendToken.t.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Test, console} from "forge-std/Test.sol";
import {ZeroLend} from "../src/ZeroLendToken.sol";
contract ZeroLendTokenTest is Test {
ZeroLend public zero;
address alice = address(1); //WL
address bob = address(2); //BL
address tom = address(3); // normal
function setUp() public {
zero = new ZeroLend();
zero.toggleWhitelist(alice, true);
zero.toggleBlacklist(bob, true);
// prelaunch - contract is paused!
// confirm everything is accurate
assertEq(zero.whitelisted(alice), true);
assertEq(zero.blacklisted(alice), false);
assertEq(zero.whitelisted(bob), false);
assertEq(zero.blacklisted(bob), true);
assertEq(zero.blacklisted(tom), false);
assertEq(zero.whitelisted(tom), false);
assertEq(zero.whitelisted(address(this)), false);
assertEq(zero.blacklisted(address(this)), false);
}
function test_owner_transfer_to_bl() public {
vm.expectRevert(bytes("blacklisted"));
zero.transfer(bob, 1);
}
function test_owner_transfer_to_normal() public {
vm.expectRevert(bytes("paused"));
zero.transfer(tom, 1);
}
function test_owner_transfer_to_wl() public {
zero.transfer(alice, 1); // FAILs bc condition is wrong (bug)
}
}
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/whitelist guard used a boolean expression that rejected every transfer while paused, including those from whitelisted addresses, rather than exempting whitelisted users.
Impact
Whitelisted users could not move tokens while the contract was paused, breaking the intended prelaunch behaviour; the reporter themselves suggests this may only warrant Low severity.
What the attacker needed
Contract is paused (prelaunch); caller is whitelisted
The fix
The guard should be changed so a transfer is permitted when the contract is not paused, or when either the sender or recipient is whitelisted.
How it was found
- Set up a Foundry project and install the OpenZeppelin contracts dependency.
- Add the token contract and a test file, then remove the default Counter files.
- In the test, whitelist one address, blacklist another, and leave the contract paused.
- Attempt a transfer to the whitelisted address and observe it reverts with 'paused'.
- Apply the recommended change to the guard and rerun the tests to see them pass.
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 token contract can be 'paused' so nobody can move tokens, and it can keep a list of 'whitelisted' users who are meant to be exempt from that pause. The code that decides whether a transfer is allowed combined these two rules wrongly, so even whitelisted users were blocked while paused. The fix rewrites the check so a transfer is allowed when the contract is not paused, or when either side of the transfer is whitelisted.
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.