Skip to content
DoS Audit finding Advanced

ERC20TokenEmitter will not work after a certain period of time

The VRGDAC contract's yToX function reverts when timeSinceStart exceeds a certain value due to precision loss, causing the ERC20TokenEmitter's buyToken function to always revert after a period of time. An attacker could not directly exploit this, but the protocol would become unusable for buying tokens after approximately 400 days under certain conditions.

zhaojie Follow with jerseyjoewalcott

Originally disclosed on Code4rena

Submitted by zhaojie, also found by jerseyjoewalcott

The timeSinceStart in the vrgdac.xToY function will revert over a certain value, resulting in the ERC20TokenEmitter#buyToken function always revert.

Proof of Concept

Initialize the VRGDAC using the parameters in the test code.

    VRGDAC vrgdac = new VRGDAC(1 ether, 1e18 / 10, 1_000 * 1e18);

The timeSinceStart is set to 394 days in the test code:

    function testVRGDAC_time() public {
        VRGDAC vrgdac = new VRGDAC(1 ether, 1e18 / 10, 1_000 * 1e18);
        int256 x = vrgdac.yToX({
            timeSinceStart: toDaysWadUnsafe(86400 * 400),
            sold: 1000 ether,
            amount: 1 ether
        });
        uint256 xx = uint256(x);
        console.log(xx + 1);
        console.log(xx / 1e18);
    }

Run the forge test -vvvv, console to output:

[FAIL. Reason: UNDEFINED] testVRGDAC_time() (gas: 554525)
Traces:
  [106719] CounterTest::setUp()
    ├─ [49499] → new Counter@0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
    │   └─ ← 247 bytes of code
    ├─ [2390] Counter::setNumber(0)
    │   └─ ← ()
    └─ ← ()

  [554525] CounterTest::testVRGDAC_time()
    ├─ [517512] → new VRGDAC@0x2e234DAe75C793f67A35089C9d99245E1C58470b
    │   └─ ← 2578 bytes of code
    ├─ [3617] VRGDAC::yToX(400000000000000000000, 1000000000000000000000, 1000000000000000000) [staticcall]
    │   └─ ← "UNDEFINED"
    └─ ← "UNDEFINED"

Changing the timeSinceStart to toDaysWadUnsafe(86400 * 365) will work.

When this function is used in ERC20TokenEmitter#buyToken, the timeSinceStart is: block.timestamp-startTime

    function buyTokenQuote(uint256 amount) public view returns (int spentY) {
        require(amount > 0, "Amount must be greater than 0");
        return
            vrgdac.xToY({
                timeSinceStart: toDaysWadUnsafe(block.timestamp - startTime),
                sold: emittedTokenWad,
                amount: int(amount)
            });
    }

startTime is set during the initialization of the ERC20TokenEmitter contract:

    function initialize(
        address _initialOwner,
        address _erc20Token,
        address _treasury,
        address _vrgdac,
        address _creatorsAddress
    ) external initializer {
        .....
        startTime = block.timestamp;
    }

In other words, if the ERC20TokenEmitter contract is deployed and initialized and becomes unavailable after 400 days(400 days is the test value, the actual value will be affected by other parameters), calling the buyToken function will always revert.

Tools Used

VScode

Recommended Mitigation Steps

Optimize the vrgdac.yToX function, or set a minimum timeSinceStart value, which is used when the minimum is exceeded.

rocketman-21 (Revolution) confirmed and commented:

Looked into this extensively, it operates under the assumption that the token emission schedule (# sold) will be way off schedule. eg: over a year, 75%+ lower than expected according to the target sale per time unit.

In that case, after a prolonged amount of time, the math in the VRGDA will break due to a param reaching 0 in the available fixed point decimals. given the VRGDA pricing mechanism decreases the price, my assumption is that in a rational market we will never reach the above case, because tokens will become cheaper and cheaper. or the DAO/community will be dead and no one wants to buy tokens anymore.

However, upon second look here - I do think this is valid.

I was able to reproduce the VRGDA breaking in multiple different scenarios due to precision loss in the VRGDA math

even if the supply was way off schedule, there could be scenarios imho where the community sets a large perTimeUnit and targetPrice and never meets that volume, and after 1+ years their vrgda will likely break

fix here: https://github.com/collectivexyz/revolution-protocol/commit/2bd0b35df870097be166a0d57af0a1f0d62a7518

0xTheC0der (Judge) commented:

@rocketman-21 Thanks for this insight, as far as I can reproduce the PoCs it’s hard to distinguish if this can have an impact on the protocol or just arises under unrealistic assumptions.

Nevertheless, it seems like there could be realistic scenarios where this is a problem.


The original report as published on Code4rena, by zhaojie. 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

Likely precision loss in the VRGDA fixed-point math causes a parameter to reach zero, leading to a revert when timeSinceStart is large.

Impact

After a certain period (e.g., 400 days under test parameters), the buyToken function will always revert, making the token emitter unusable for purchases; the actual time depends on other parameters and may require unrealistic conditions.

What the attacker needed

Contract deployed and initialized; timeSinceStart exceeds threshold (e.g., 400 days); token emission schedule far off target

The fix

The VRGDA yToX function was fixed to handle precision loss, as shown in the provided commit.

How it was found

  1. Deploy VRGDAC with parameters (1 ether, 1e18/10, 1000e18).
  2. Call yToX with timeSinceStart set to 400 days (toDaysWadUnsafe(86400 * 400)), sold=1000 ether, amount=1 ether.
  3. Observe the call reverts with UNDEFINED.
  4. Change timeSinceStart to 365 days and the call succeeds.

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.

This is a smart contract bug where a mathematical function used for pricing tokens stops working after a long time. The function calculates a price based on how long the contract has been running, but after about 400 days the numbers become too small to handle correctly, causing the function to fail and preventing anyone from buying tokens.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by zhaojie

View all

9 more disclosed reports, best first.

More from Revolution Protocol

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.