Non-existing revenue contract can be passed to claimRevenue to send all tokens to treasury
The claimRevenue function did not verify that the provided revenue contract was registered. An attacker could pass a non-existent contract address, causing all claimed tokens to be sent to the treasury instead of the escrow, depriving the lender of revenue.
Lambda Follow with berndartmueller, adriro and 1 other
Originally disclosed on Code4rena
Submitted by Lambda, also found by berndartmueller, adriro, and aphak5010
Neither SpigotLib.claimRevenue nor SpigotLib._claimRevenue check that the provided revenueContract was registered before. If this is not the case, SpigotLib._claimRevenue assumes that this is a revenue contract with push payments (because self.settings[revenueContract].claimFunction is 0) and just returns the difference since the last call to claimRevenue:
if(self.settings[revenueContract].claimFunction == bytes4(0)) {
// push payments
// claimed = total balance - already accounted for balance
claimed = existingBalance - self.escrowed[token]; //@audit Rebasing tokens
// underflow revert ensures we have more tokens than we started with and actually claimed revenue
}
SpigotLib.claimRevenue will then read self.settings[revenueContract].ownerSplit, which is 0 for non-registered revenue contracts:
uint256 escrowedAmount = claimed * self.settings[revenueContract].ownerSplit / 100;
Therefore, the whole claimed amount is sent to the treasury.
This becomes very problematic for revenue tokens that use push payments. An attacker (in practice the borrower) can just regularly call claimRevenue with this token and a non-existing revenue contract. All of the tokens that were sent to the spigot since the last call will be sent to the treasury and none to the escrow, i.e. a borrower can ensure that no revenue will be available for the lender, no matter what the configured split is.
Proof Of Concept
As mentioned above, the attack pattern works for arbitrary tokens where one (or more) revenue contracts use push payments, i.e. where the balance of the Spigot increases from time to time. Then, the attacker just calls claimRevenue with a non-existing address. This is illustrated in the following diff:
--- a/contracts/tests/Spigot.t.sol
+++ b/contracts/tests/Spigot.t.sol
@@ -174,7 +174,7 @@ contract SpigotTest is Test {
assertEq(token.balanceOf(address(spigot)), totalRevenue);
bytes memory claimData;
- spigot.claimRevenue(revenueContract, address(token), claimData);
+ spigot.claimRevenue(address(0), address(token), claimData);
Thanks to this small modification, all of the tokens are sent to the treasury and none are sent to the escrow.
Recommended Mitigation Steps
Check that a revenue contract was registered before, revert if it does not.
kibagateaux (Debt DAO) confirmed
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 contract failed to validate that the revenue contract address was registered, so it treated an unregistered address as a push-payment contract with a zero owner split, sending all funds to the treasury.
Impact
A borrower could ensure that no revenue is available for the lender, regardless of the configured split, by regularly calling claimRevenue with a non-existent contract.
What the attacker needed
A revenue token using push payments; ability to call claimRevenue (e.g., as borrower)
The fix
The contract should check that the revenue contract was registered before processing the claim, and revert if it was not.
How it was found
- Deploy or identify a Spigot contract with a revenue token that uses push payments.
- Call claimRevenue with a non-existent revenue contract address and the token address.
- Observe that all tokens sent to the Spigot since the last claim are transferred to the treasury, not the escrow.
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 a smart contract, a function that distributes revenue assumed any address given was a valid revenue source. Because it didn't check, someone could give a fake address and the contract would still send all the money to the treasury, leaving none for the lender.
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.