Skip to content
Smart contracts Audit finding Intermediate

Contract BasicSale is missing an approve(address(vestLock), 2**256-1) call

The BasicSale contract lacks an approve call to the vesting contract, so its withdrawShare function always reverts with an allowance error, permanently locking all mainToken sent to it.

Reigada Follow

Originally disclosed on Code4rena

Submitted by Reigada, also found by WatchPug

Impact

As we can see in the contracts AirdropDistribution and InvestorDistribution, they both have the following approve() call: mainToken.approve(address(vestLock), 2\*\*256-1);

This is necessary because both contracts transfer tokens to the vesting contract by calling its vest() function:

The code of the vest() function in the Vesting contract performs a transfer from msg.sender to Vesting contract address -> vestingToken.transferFrom(msg.sender, address(this), \_amount); https://github.com/code-423n4/2021-11-bootfinance/blob/main/vesting/contracts/Vesting.sol#L95

Same is done in the BasicSale contract: https://github.com/code-423n4/2021-11-bootfinance/blob/main/tge/contracts/PublicSale.sol#L225

The problem is that this contract is missing the approve() call. For that reason, the contract is totally useless as the function \_withdrawShare() will always revert with the following message: revert reason: ERC20: transfer amount exceeds allowance. This means that all the mainToken sent to the contract would be stuck there forever. No way to retrieve them.

How this issue was not detected in the testing phase? Very simple. The mock used by the team has an empty vest() function that performs no transfer call. https://github.com/code-423n4/2021-11-bootfinance/blob/main/tge/contracts/helper/MockVesting.sol#L10

Proof of Concept

See below Brownie’s custom output:

Calling -> publicsale.withdrawShare(1, 1, {'from': user2})
Transaction sent: 0x9976e4f48bd14f9be8e3e0f4d80fdb8f660afab96a7cbd64fa252510154e7fde
Gas price: 0.0 gwei   Gas limit: 6721975   Nonce: 5
BasicSale.withdrawShare confirmed (ERC20: transfer amount exceeds allowance)   Block: 13577532   Gas used: 323334 (4.81%)

Call trace for '0x9976e4f48bd14f9be8e3e0f4d80fdb8f660afab96a7cbd64fa252510154e7fde':
Initial call cost  \[21344 gas]
BasicSale.withdrawShare  0:3724  \[16114 / -193010 gas]
├── BasicSale.\_withdrawShare  111:1109  \[8643 / 63957 gas]
│   ├── BasicSale.\_updateEmission  116:405  \[53294 / 55739 gas]
│   │   └── BasicSale.getDayEmission  233:248  \[2445 gas]
│   ├── BasicSale.\_processWithdrawal  437:993  \[-7726 / -616 gas]
│   │   ├── BasicSale.getEmissionShare  484:859  \[4956 / 6919 gas]
│   │   │   │
│   │   │   └── MockERC20.balanceOf  \[STATICCALL]  616:738  \[1963 gas]
│   │   │           ├── address: mockerc20.address
│   │   │           ├── input arguments:
│   │   │           │   └── account: publicsale.address
│   │   │           └── return value: 100000000000000000000
│   │   │
│   │   └── SafeMath.sub  924:984  \[191 gas]
│   └── SafeMath.sub  1040:1100  \[191 gas]
│
├── MockERC20.transfer  \[CALL]  1269:1554  \[1115 / 30109 gas]
│   │   ├── address: mockerc20.address
│   │   ├── value: 0
│   │   ├── input arguments:
│   │   │   ├── recipient: user2.address
│   │   │   └── amount: 27272727272727272727
│   │   └── return value: True
│   │
│   └── ERC20.transfer  1366:1534  \[50 / 28994 gas]
│       └── ERC20.\_transfer  1374:1526  \[28944 gas]
└── Vesting.vest  \[CALL]  1705:3712  \[-330491 / -303190 gas]
│   ├── address: vesting.address
│   ├── value: 0
│   ├── input arguments:
│   │   ├── \_beneficiary: user2.address
│   │   ├── \_amount: 63636363636363636363
│   │   └── \_isRevocable: 0
│   └── revert reason: ERC20: transfer amount exceeds allowance <-------------
│
├── SafeMath.add  1855:1883  \[94 gas]
├── SafeMath.add  3182:3210  \[94 gas]
├── SafeMath.add  3236:3264  \[94 gas]
│
└── MockERC20.transferFrom  \[CALL]  3341:3700  \[99923 / 27019 gas]
│   ├── address: mockerc20.address
│   ├── value: 0
│   ├── input arguments:
│   │   ├── sender: publicsale.address
│   │   ├── recipient: vesting.address
│   │   └── amount: 63636363636363636363
│   └── revert reason: ERC20: transfer amount exceeds allowance
│
└── ERC20.transferFrom  3465:3700  \[-97648 / -72904 gas]
└── ERC20.\_transfer  3473:3625  \[24744 gas]

Tools Used

Manual testing

Recommended Mitigation Steps

The following approve() call should be added in the constructor of the BasicSale contract: mainToken.approve(address(vestLock), 2\*\*256-1);

chickenpie347 (Boot Finance) confirmed

The original report as published on Code4rena, by Reigada. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 BasicSale contract does not call approve on the main token for the vesting contract, so the vesting contract cannot transfer tokens from BasicSale.

Impact

All mainToken sent to the BasicSale contract would be stuck forever, as withdrawShare always reverts.

What the attacker needed

None

The fix

The approve call should be added in the constructor of the BasicSale contract.

How it was found

  1. Call withdrawShare on the BasicSale contract.
  2. The function attempts to transfer tokens to the vesting contract via vest().
  3. The transfer fails because the allowance is zero, causing a revert.

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.

In Ethereum, a smart contract must give another contract permission to take its tokens; this is called an allowance. The BasicSale contract never gave that permission to the vesting contract, so when it tried to move tokens, the transfer failed and the tokens became stuck forever.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Reigada

View all

3 more disclosed reports, best first.

More from Boot Finance contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.