Rounding errors can cause ERC20RebaseDistributor transfers and mints to fail for underflow
Rounding errors in share calculations can cause transfers and mints involving rebasing addresses to revert due to underflow. This can temporarily block sensitive operations like liquidations and prevent users from exiting rebase.
Here it is possible that the amount is higher than _unmintedRebaseRewards, introducing also in this place a revert condition.
Impact
Transfers and mints from or towards addresses that are rebasing may fail in real-world scenarios. This failure can be used as a means to DoS sensitive operations like liquidations. Addresses who enter this scenario aren’t also able to exit rebase to fix their transfers.
Proof of Concept
Below a foundry PoC (full setup here) which shows a scenario where a transfer (or mint) to a rebasing user can fail by underflow on the _unmintedRebaseRewards - amount operation:
function testM2bis() external {
uint t0 = block.timestamp;
// set up the credit token with the minimum 100e18 rebasing supply
// as indicated here ->
ct.mint(address(1), 100e18);
vm.prank(address(1));
ct.enterRebase();
ct.mint(address(2), 6e11); vm.prank(address(2)); ct.distribute(6e11);
vm.warp(2);
ct.mint(address(2), 3e12); vm.prank(address(2)); ct.distribute(3e12);
vm.warp(3);
ct.mint(address(3), 1e20);
vm.prank(address(3));
// ☢️ this shouldn't revert!
vm.expectRevert();
ct.transfer(address(1), 1e20);
// ☢️ this shouldn't either!
vm.expectRevert();
ct.mint(address(1), 1e20);
// ☢️ this too..
vm.prank(address(1));
vm.expectRevert();
ct.exitRebase();
// ☢️ same here...
vm.startPrank(address(1));
vm.expectRevert();
ct.transfer(address(3), 1e20);
// ☢️ I bet you saw this coming...
ct.approve(address(3), 1e20);
vm.startPrank(address(3));
vm.expectRevert();
ct.transferFrom(address(1), address(3), 1e20);
}
This is with a lower impact because involving a zero-value transfer, the following PoC in Foundry (the full runnable test can be found here) shows a transfer failing on the toSharesAfter - rebasingStateTo.nShares operation:
function testM2() external {
address from = address(uint160(1));
address to = address(uint160(2));
ct.mint(to, 100 ether);
vm.startPrank(to);
ct.enterRebase();
ct.distribute(1 ether);
vm.warp(block.timestamp + 1);
vm.startPrank(from);
vm.expectRevert();
ct.transfer(to, 0);
vm.expectRevert();
ct.transferFrom(from, to, 0);
}
Tools Used
Foundry
Recommended Mitigation Steps
Consider adapting shares calculations to tolerate rounding fluctuations, i.e. by flooring to 0 the mentioned subtractions.
After carefully reviewing the report and discussing it with other auditors, I believe that the severity of this issue should be reassessed.
The problem is that division rounds down and more divisions result in greater precision loss. Specifically, in this report, the calculation of toSharesAfter involves three divisions, which results in underflow during the subsequent subtraction. It is important to note that the underflow issue in the provided POC above is temporary and only lasts for 31 seconds. After this time, the transfer() and mint() functions will work as expected.
Proof of Concept
The variable toSharesAfter is determined by this formula:
@Soul22 - while the attack in the PoC is temporary, new small-amount distributions (which are permissionless) with appropriate timing and amounts can be made to make the DoS last longer.
Although the likelihood is low, the impact of this issue is significant since it can brick Credit token’s minting and transferring, potentially preventing users from unstaking from SurplusGuildMinter in certain cases. The duration of the Denial of Service (DoS) attack is temporary, but users may not be able to unstake promptly to avoid being slashed in SurplusGuildMinter. Therefore, medium severity is appropriate.
The original report as published on Code4rena, by 3docSec. 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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Impact
Transfers and mints involving rebasing addresses may fail, potentially causing a temporary denial of service for sensitive operations like liquidations, and users may be unable to exit rebase to fix their transfers.
What the attacker needed
A rebasing token with active distributions; specific timing and small reward amounts
The fix
The share calculations should be adapted to tolerate rounding fluctuations, for example by flooring the mentioned subtractions to zero.
How it was found
Set up a rebasing token with a minimum rebasing supply.
Mint tokens to a rebasing address and enter rebase.
Distribute small amounts of rewards at specific times.
Attempt a transfer or mint to the rebasing address and observe 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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A rebasing token automatically adjusts each holder's balance over time. The code calculates how many shares a transfer should move, but rounding can make the result slightly too small, so a subtraction goes below zero and the transaction fails. This can temporarily stop transfers and mints for affected users.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.