Skip to content
Business logic Audit finding Intermediate

_payoutEth() calculates balance with an offset, always leaving dust ETH in the contract

The ETH payout function subtracts an estimated gas cost from the contract balance before distributing funds, so a small remainder is always left behind. If that dust is too small, later payout calls revert and the ETH becomes stuck because no other withdrawal function exists.

joestakey Follow

Originally disclosed on Code4rena

Submitted by joestakey, also found by Aymen0909, d3e4, Jeiwan, joestakey, and Trust

PA1D.sol#L391 PA1D.sol#L395

Payout recipients can call getEthPayout() to transfer the ETH balance of the contract to all payout recipients. This function makes an internal call to _payoutEth, which sends the payment to the recipients based on their associated bp.

The issue is that the balance used in the transfer calls is not the contract ETH balance, but the balance minus a gasCost.

This means getEthPayout() calls will leave dust in the contract.

Impact

If the dust is small enough, a subsequent call to getEthPayout is likely to revert because of this check. And enforcer/PA1D does not have any other ETH withdrawal function. While enforcer/PA1D is meant to be used via delegate calls from a NFT collection contract, if the NFT contract does not have any withdrawal function either, this dust mentioned above is effectively lost.

Proof of Concept

Let us take the example of a payout recipient trying to retrieve their share of the balance, equal to 40_000 For simplicity, assume one payout address, owned by Alice:

  • Alice calls getEthPayout(), which in turn calls _payoutEth()
  • gasCost = (23300 * length) + length = 23300 + 1 = 23301
  • balance = address(this).balance = 40000
  • balance - gasCost = 40000 - 23301 = 16699,
  • sending = ((bps[i] * balance) / 10000) = 10000 * 16699 / 10000 = 16699
  • Alice receives 16699.

Alice has to wait for the balance to increase to call getEthPayout() again. But no matter what, there will always be at least a dust of 10000 left in the contract.

Recommended Mitigation Steps

The transfers should be done based on address(this).balance. The gasCost is redundant as the gas amount is specified by the caller of getEthPayout(), the contract does not have to provide gas.

-391: balance = balance - gasCost;
392:     uint256 sending;
393:     // uint256 sent;
394:     for (uint256 i = 0; i < length; i++) {
395:       sending = ((bps[i] * balance) / 10000);
396:       addresses[i].transfer(sending);
397:       // sent = sent + sending;
398:     }

gzeon (judge) commented:

I think this is intended, a bit weird why 23300 is chosen, why gas price is not considered and why the withheld fund is not sent to the caller tho. Related to #164 and #106

Trust (warden) commented:

It doesn’t make sense that it’s intentional, because gas is never provided by contract, only EOA. Contract can only relay gas passed to it. But interesting to hear what the team says.

gzeon (judge) commented:

Agreed, but still seems to be low risk.

alexanderattar (Holograph) confirmed and commented:

This is a valid issue and this function will be refactored.

alexanderattar (Holograph) linked a PR:

Feature/holo 612 royalty smart contract improvements


The original report as published on Code4rena, by joestakey. 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 payout calculation uses the contract balance minus a hardcoded gas cost instead of the full contract balance.

Impact

A small amount of ETH is always left in the contract, and if it is too small a later payout call is likely to revert, leaving the dust effectively lost when no other withdrawal function exists.

What the attacker needed

Contract holds ETH; caller is a payout recipient

The fix

The transfers should be based on the full contract balance, removing the gasCost subtraction, and the team confirmed the function will be refactored.

How it was found

  1. Alice calls getEthPayout(), which calls _payoutEth().
  2. The code computes gasCost as 23300 times the number of recipients plus the number of recipients.
  3. The code sets balance to the contract's ETH balance and subtracts gasCost from it.
  4. Each recipient's share is calculated from the reduced balance and transferred.

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 smart contract holds ETH that belongs to several people. When someone asks for a payout, the code first subtracts a made-up 'gas cost' from the total before splitting it. That subtraction leaves a tiny amount (dust) in the contract, and if it is too small the next payout attempt fails, trapping the money.

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.

More by joestakey

View all

10 more disclosed reports, best first.

More from Holograph contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.