Submitted by SBSecurity, also found by ether_sky
In the SurplusGuildMinter::stake() function, there is currently no check to verify if the provided terms CREDIT token is the same as the CREDIT token in the called SurplusGuildMinter. This oversight could result in inaccuracies in gaugeWeight and rewards for guild holders, especially with the upcoming inclusion of various markets such as gUSDC and likely gWETH.
A potential issue exists where a user can stake in the SurplusGuildMinter(gUSDC) using a gWETH term. This action results in the user obtaining Guild tokens based on staked gUSDC but inadvertently increases the gaugeWeight for gWETH. As a consequence, other Guild token holders in the gWETH market may receive reduced rewards.
With a guild:credit mintRatio of 2, a staker should receive 2 Guild tokens for 1 gWETH. However, if the staker uses the wrong SurplusGuildMinter and stakes 1 gUSDC, again 2 Guild tokens will be minted, creating a situation where the malicious staker can increase the gWETH gaugeWeight with cheaper CreditToken.
As illustrated in the scenario below, with just $100, the malicious staker can reduce guild holder rewards more than twice. Afterward, they can unstake the initial $100, causing a loss of rewards for other stakers.
Note: The malicious staker wont receive rewards for this stake, and there wont be any penalties (slashing) if the term incurs no losses until they decide to unstake.
Preconditions:
Steps:
Create a new file in test/unit/loan called StakeIntoWrongTerm.t.sol:
There are tests for both cases  one without the attack and another with the attack scenario.
Run them with:
To prevent manipulation, add a check in the stake() function to ensure that the passed term is from the same market as the SurplusGuildMinter.
Invalid Validation
eswak (Ethereum Credit Guild) confirmed and commented:
