Adversary can brick AutoRoller by creating another AutoRoller on the same adapter
An AutoRoller calculates a future maturity date and tries to create a new series at that date, but the system only allows one series per adapter and maturity. An attacker can create a second AutoRoller on the same adapter that first creates the target maturity, causing the original AutoRoller to revert every time it tries to roll.
Source: https://github.com/sherlock-audit/2022-11-sense-judging/issues/20
Found by
0x52
Summary
onSponsorWindowOpened attempts to make a new series at the desired maturity. Each adapter can only have one of each maturity. If the maturity requested already exists then onSponsorWindowOpened will revert, making it impossible to roll the AutoRoller. An adversary can take advantage of this to brick an AutoRoller by creating a second AutoRoller on the same adapter that will create a target maturity before the first AutoRoller. Since the maturity now exists, the first AutoRoller will always revert when trying to Roll.
Vulnerability Detail
uint256 _maturity = utils.getFutureMaturity(targetDuration);
function getFutureMaturity(uint256 monthsForward) public view returns (uint256) {
(uint256 year, uint256 month, ) = DateTime.timestampToDate(DateTime.addMonths(block.timestamp, monthsForward));
return DateTime.timestampFromDateTime(year, month, 1 /* top of the month */, 0, 0, 0);
}
Inside AutoRoller#onSponsorWindowOpened the maturity is calculated using RollerUtils#getFutureMaturity. This returns the timestamp the requested months ahead, truncated down to the first of the month. It passes this calculated maturity as the maturity to sponsor a new series.
(ERC20 _pt, YTLike _yt) = periphery.sponsorSeries(address(adapter), _maturity, true);
https://etherscan.io/address/0xFff11417a58781D3C72083CB45EF54d79Cd02437#code#F1#L90
function sponsorSeries(
address adapter,
uint256 maturity,
bool withPool
) external returns (address pt, address yt) {
(, address stake, uint256 stakeSize) = Adapter(adapter).getStakeAndTarget();
// Transfer stakeSize from sponsor into this contract
ERC20(stake).safeTransferFrom(msg.sender, address(this), stakeSize);
// Approve divider to withdraw stake assets
ERC20(stake).approve(address(divider), stakeSize);
(pt, yt) = divider.initSeries(adapter, maturity, msg.sender);
// Space pool is always created for verified adapters whilst is optional for unverified ones.
// Automatically queueing series is only for verified adapters
if (verified[adapter]) {
poolManager.queueSeries(adapter, maturity, spaceFactory.create(adapter, maturity));
} else {
if (withPool) {
spaceFactory.create(adapter, maturity);
}
}
emit SeriesSponsored(adapter, maturity, msg.sender);
}
periphery#sponsorSeries is called with true indicating to create a space pool for the newly created series.
https://etherscan.io/address/0x5f6e8e9C888760856e22057CBc81dD9e0494aA34#code#F1#L75
function create(address adapter, uint256 maturity) external returns (address pool) {
address pt = divider.pt(adapter, maturity);
_require(pt != address(0), Errors.INVALID_SERIES);
_require(pools[adapter][maturity] == address(0), Errors.POOL_ALREADY_EXISTS);
pool = address(new Space(
vault,
adapter,
maturity,
pt,
ts,
g1,
g2,
oracleEnabled
));
pools[adapter][maturity] = pool;
}
We run into an issue inside SpaceFactory#create because it only allows a single pool per adapter/maturity. If a pool already exist then it will revert.
An adversary can abuse this revert to brick an existing AutoRoller. Assume AutoRoller A has a duration of 3 months. Its current maturity is December 1st 2022, when rolled it will attempt to create a series at March 1st 2023. An adversary could abuse this and create AutoRoller B with a maturity of 4 months. When they roll for the first time it will create a series with maturity at March 1st 2023. When AutoRoller A attempts to roll it will revert since a series already exists at March 1st 2023.
This conflict can happen accidentally if there is a monthly AutoRoller and a quarterly AutoRoller. It also hinders the viability of using an AutoRoller for an adapter that is popular because the series will likely have been created by the time the autoroller tries to roll into it.
Impact
AutoRollers will frequently be bricked
Code Snippet
Tool used
Manual Review
Recommendation
Requiring that the AutoRoller has to create the series seems overly restrictive and leads to a large number of issues. Attempting to join an a series that is already initialized could also lead to pool manipulation rates. It seems like a large refactoring is needed for the rolling section of the AutoRoller
Discussion
jparklev
This is a great observation and a valid high severity finding. We have a fix in mind that we'll share once implemented – appreciate the submission
jparklev
Fix: https://github.com/sense-finance/auto-roller/pull/20
aktech297
The fix is done by considering the trusted caller.
If the caller is trusted, contract allows for auto roller creation.
This fix will be valid till isTrusted[msg.sender] == true after first one is created.
Even the trusted caller should not be allowed to create auto roller with maturity less than the existing auto roller.
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 AutoRoller assumes it can always create a new series at the calculated maturity, but the underlying system enforces uniqueness per adapter and maturity, so a pre-existing series causes a revert.
Impact
AutoRollers could be frequently bricked, preventing them from rolling to new maturities.
What the attacker needed
Ability to deploy an AutoRoller on the same adapter; victim AutoRoller exists with a future maturity
The fix
A fix was implemented by considering a trusted caller, but the discussion notes that even trusted callers should not be allowed to create an AutoRoller with a maturity less than an existing one.
How it was found
- Deploy AutoRoller A with a 3-month duration, current maturity December 1st 2022.
- Deploy AutoRoller B on the same adapter with a 4-month duration.
- Trigger AutoRoller B to roll, creating a series at March 1st 2023.
- Attempt to roll AutoRoller A, which tries to create a series at March 1st 2023 and reverts because the series already exists.
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.
An AutoRoller is a smart contract that automatically moves funds to a new maturity date when the old one expires. The system only allows one series per adapter and maturity date, so if someone else creates that same series first, the AutoRoller's attempt to create it fails and it gets stuck.
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.