From 039b882dfa8a89fa31481e20045021ed08bab5dc Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Wed, 2 Sep 2026 20:05:56 +0000 Subject: [PATCH 1/4] Enforce RSR staking obligations --- CHANGELOG.md | 2 + contracts/p0/AssetRegistry.sol | 15 ++++ contracts/p0/BackingManager.sol | 14 ++++ contracts/p0/mixins/Trading.sol | 4 ++ contracts/p1/AssetRegistry.sol | 17 +++++ contracts/p1/BackingManager.sol | 14 ++++ contracts/p1/mixins/Trading.sol | 4 ++ test/Main.test.ts | 107 +++++++++++++++++++++++++--- test/RToken.test.ts | 9 ++- test/Revenues.test.ts | 2 + test/scenario/ComplexBasket.test.ts | 2 + test/scenario/LargeDecimals.test.ts | 2 + 12 files changed, 182 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba1c3a7823..4451173b07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Delay automatic rebalancing after a collateral default while allowing issuance against the backup basket. - Allow governance-triggered basket changes to rebalance without waiting for `tradingDelay`. +- Prevent unregistering RSR and require RSR assets to preserve BackingManager tradeability. +- Limit BackingManager `minTradeVolume` increases to one tenth of both the conservative RSR stake value and the RSR asset's `maxTradeVolume`. # 4.2.0 diff --git a/contracts/p0/AssetRegistry.sol b/contracts/p0/AssetRegistry.sol index 37eb43b9a7..6ceee85c09 100644 --- a/contracts/p0/AssetRegistry.sol +++ b/contracts/p0/AssetRegistry.sol @@ -86,6 +86,7 @@ contract AssetRegistryP0 is ComponentP0, IAssetRegistry { /// @custom:governance function unregister(IAsset asset) external governance { require(address(asset.erc20()) != address(main.rToken()), "cannot unregister RToken"); + require(address(asset.erc20()) != address(main.rsr()), "cannot unregister RSR"); require(_erc20s.contains(address(asset.erc20())), "no asset to unregister"); require(assets[asset.erc20()] == asset, "asset not found"); @@ -175,6 +176,20 @@ contract AssetRegistryP0 is ComponentP0, IAssetRegistry { // Refresh to ensure it does not revert, and to save a recent lastPrice asset.refresh(); + if (address(asset.erc20()) == address(main.rsr())) { + (uint192 low, uint192 high) = asset.price(); + require(low > 0 && high < FIX_MAX, "RSR asset unpriced"); + + uint192 requiredVolume = main.backingManager().minTradeVolume() * 10; + require(asset.maxTradeVolume() >= requiredVolume, "RSR maxTradeVolume too low"); + if (!_isInitializing()) { + require( + asset.bal(address(main.stRSR())).safeMul(low, FLOOR) >= requiredVolume, + "RSR stake too small" + ); + } + } + if (_erc20s.contains(address(asset.erc20())) && assets[asset.erc20()] != asset) { _erc20s.remove(address(asset.erc20())); emit AssetUnregistered(asset.erc20(), assets[asset.erc20()]); diff --git a/contracts/p0/BackingManager.sol b/contracts/p0/BackingManager.sol index 7a3bdce601..1c5a087ed0 100644 --- a/contracts/p0/BackingManager.sol +++ b/contracts/p0/BackingManager.sol @@ -276,4 +276,18 @@ contract BackingManagerP0 is TradingP0, IBackingManager { emit BackingBufferSet(backingBuffer, val); backingBuffer = val; } + + function _validateMinTradeVolume(uint192 val) internal view override { + if (_isInitializing()) return; + + IAsset rsrAsset = main.assetRegistry().toAsset(main.rsr()); + uint192 requiredVolume = val * 10; + require(rsrAsset.maxTradeVolume() >= requiredVolume, "RSR maxTradeVolume too low"); + + (uint192 low, ) = rsrAsset.price(); + require( + rsrAsset.bal(address(main.stRSR())).safeMul(low, FLOOR) >= requiredVolume, + "RSR stake too small" + ); + } } diff --git a/contracts/p0/mixins/Trading.sol b/contracts/p0/mixins/Trading.sol index e96aa3dec5..55c7799d6f 100644 --- a/contracts/p0/mixins/Trading.sol +++ b/contracts/p0/mixins/Trading.sol @@ -120,7 +120,11 @@ abstract contract TradingP0 is RewardableP0, ITrading { /// @custom:governance function setMinTradeVolume(uint192 val) public governance { require(val <= MAX_TRADE_VOLUME, "invalid minTradeVolume"); + if (val > minTradeVolume) _validateMinTradeVolume(val); emit MinTradeVolumeSet(minTradeVolume, val); minTradeVolume = val; } + + // solhint-disable-next-line no-empty-blocks + function _validateMinTradeVolume(uint192) internal view virtual {} } diff --git a/contracts/p1/AssetRegistry.sol b/contracts/p1/AssetRegistry.sol index 8398654e7b..e961df9126 100644 --- a/contracts/p1/AssetRegistry.sol +++ b/contracts/p1/AssetRegistry.sol @@ -6,11 +6,13 @@ import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "../plugins/assets/RTokenAsset.sol"; import "../interfaces/IAssetRegistry.sol"; import "../interfaces/IMain.sol"; +import "../libraries/Fixed.sol"; import "./mixins/Component.sol"; /// The AssetRegistry provides the mapping from ERC20 to Asset, allowing the rest of Main /// to think in terms of ERC20 tokens and target/ref units. contract AssetRegistryP1 is ComponentP1, IAssetRegistry { + using FixLib for uint192; using EnumerableSet for EnumerableSet.AddressSet; uint256 public constant GAS_FOR_BH_QTY = 100_000; // enough to call bh.quantity @@ -132,6 +134,7 @@ contract AssetRegistryP1 is ComponentP1, IAssetRegistry { IERC20Metadata erc20 = asset.erc20(); require(address(erc20) != address(main.rToken()), "cannot unregister RToken"); + require(address(erc20) != address(main.rsr()), "cannot unregister RSR"); require(_erc20s.contains(address(erc20)), "no asset to unregister"); require(assets[erc20] == asset, "asset not found"); @@ -278,6 +281,20 @@ contract AssetRegistryP1 is ComponentP1, IAssetRegistry { // Refresh to ensure it does not revert, and to save a recent lastPrice asset.refresh(); + if (address(erc20) == address(main.rsr())) { + (uint192 low, uint192 high) = asset.price(); + require(low > 0 && high < FIX_MAX, "RSR asset unpriced"); + + uint192 requiredVolume = backingManager.minTradeVolume() * 10; + require(asset.maxTradeVolume() >= requiredVolume, "RSR maxTradeVolume too low"); + if (!_isInitializing()) { + require( + asset.bal(address(main.stRSR())).safeMul(low, FLOOR) >= requiredVolume, + "RSR stake too small" + ); + } + } + if (!main.frozen()) { backingManager.grantRTokenAllowance(erc20); } diff --git a/contracts/p1/BackingManager.sol b/contracts/p1/BackingManager.sol index d9e8b679b8..f0962c2c17 100644 --- a/contracts/p1/BackingManager.sol +++ b/contracts/p1/BackingManager.sol @@ -347,6 +347,20 @@ contract BackingManagerP1 is TradingP1, IBackingManager { backingBuffer = val; } + function _validateMinTradeVolume(uint192 val) internal view override { + if (_isInitializing()) return; + + IAsset rsrAsset = assetRegistry.toAsset(rsr); + uint192 requiredVolume = val * 10; + require(rsrAsset.maxTradeVolume() >= requiredVolume, "RSR maxTradeVolume too low"); + + (uint192 low, ) = rsrAsset.price(); + require( + rsrAsset.bal(address(stRSR)).safeMul(low, FLOOR) >= requiredVolume, + "RSR stake too small" + ); + } + /// Call after upgrade to >= 3.0.0 function cacheComponents() public { assetRegistry = main.assetRegistry(); diff --git a/contracts/p1/mixins/Trading.sol b/contracts/p1/mixins/Trading.sol index 6eb40edc83..1734953198 100644 --- a/contracts/p1/mixins/Trading.sol +++ b/contracts/p1/mixins/Trading.sol @@ -174,10 +174,14 @@ abstract contract TradingP1 is Multicall, ComponentP1, ReentrancyGuardUpgradeabl function setMinTradeVolume(uint192 val) public { requireGovernanceOnly(); require(val <= MAX_TRADE_VOLUME, "invalid minTradeVolume"); + if (val > minTradeVolume) _validateMinTradeVolume(val); emit MinTradeVolumeSet(minTradeVolume, val); minTradeVolume = val; } + // solhint-disable-next-line no-empty-blocks + function _validateMinTradeVolume(uint192) internal view virtual {} + /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. diff --git a/test/Main.test.ts b/test/Main.test.ts index ab6b903aa7..bc8e642297 100644 --- a/test/Main.test.ts +++ b/test/Main.test.ts @@ -36,6 +36,7 @@ import { expectPrice, expectUnpriced, setOraclePrice } from './utils/oracles' import { bn, fp } from '../common/numbers' import { Asset, + AssetMock, ATokenFiatCollateral, BackingManagerP1, BasketHandlerP1, @@ -1072,7 +1073,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { }) it('Should allow to update minTradeVolume if OWNER and perform validations', async () => { - const newValue: BigNumber = fp('0.02') + const newValue: BigNumber = fp('0.005') // Check existing value expect(await backingManager.minTradeVolume()).to.equal(config.minTradeVolume) @@ -1097,6 +1098,33 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { ).to.be.revertedWith('invalid minTradeVolume') }) + it('Should bound minTradeVolume increases by RSR tradeability', async () => { + const stakeAmt = fp('2000000') + await rsr.mint(addr1.address, stakeAmt) + await rsr.connect(addr1).approve(stRSR.address, stakeAmt) + await stRSR.connect(addr1).stake(stakeAmt) + + const maxAllowed = (await rsrAsset.maxTradeVolume()).div(10) + await backingManager.connect(owner).setMinTradeVolume(maxAllowed) + await expect( + backingManager.connect(owner).setMinTradeVolume(maxAllowed.add(1)) + ).to.be.revertedWith('RSR maxTradeVolume too low') + + // RevenueTrader settings are independent + await expect(rsrTrader.connect(owner).setMinTradeVolume(maxAllowed.add(1))).to.not.be.reverted + + // Reductions remain available when the stake no longer satisfies the bound + await rsr.burn(stRSR.address, stakeAmt.sub(fp('1'))) + await backingManager.connect(owner).setMinTradeVolume(config.minTradeVolume) + + const [low] = await rsrAsset.price() + const poolAllowed = low.div(10) // one RSR remains in StRSR + await backingManager.connect(owner).setMinTradeVolume(poolAllowed) + await expect( + backingManager.connect(owner).setMinTradeVolume(poolAllowed.add(1)) + ).to.be.revertedWith('RSR stake too small') + }) + it('Should allow to update backingBuffer if OWNER and perform validations', async () => { const newValue: BigNumber = fp('0.02') @@ -1577,14 +1605,15 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { await expect(assetRegistry.toAsset(other.address)).to.be.revertedWith('erc20 unregistered') // Reverts if no registered asset - After unregister - await expect(assetRegistry.connect(owner).unregister(rsrAsset.address)) + await expect(assetRegistry.connect(owner).unregister(aaveAsset.address)) .to.emit(assetRegistry, 'AssetUnregistered') - .withArgs(rsr.address, rsrAsset.address) - await expect(assetRegistry.toAsset(rsr.address)).to.be.revertedWith('erc20 unregistered') + .withArgs(aaveToken.address, aaveAsset.address) + await expect(assetRegistry.toAsset(aaveToken.address)).to.be.revertedWith( + 'erc20 unregistered' + ) // Returns correctly the asset expect(await assetRegistry.toAsset(rToken.address)).to.equal(rTokenAsset.address) - expect(await assetRegistry.toAsset(aaveToken.address)).to.equal(aaveAsset.address) expect(await assetRegistry.toAsset(compToken.address)).to.equal(compAsset.address) expect(await assetRegistry.toAsset(token0.address)).to.equal(collateral0.address) expect(await assetRegistry.toAsset(token1.address)).to.equal(collateral1.address) @@ -1693,10 +1722,72 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { ).to.be.revertedWith('cannot swap RToken') }) - it('Should not allow to unregister RToken', async () => { + it('Should not allow to unregister RToken or RSR', async () => { await expect(assetRegistry.connect(owner).unregister(rTokenAsset.address)).to.be.revertedWith( 'cannot unregister RToken' ) + await expect(assetRegistry.connect(owner).unregister(rsrAsset.address)).to.be.revertedWith( + 'cannot unregister RSR' + ) + }) + + it('Should preserve RSR tradeability when swapping its asset', async () => { + const AssetFactory: ContractFactory = await ethers.getContractFactory('Asset') + const requiredVolume = config.minTradeVolume.mul(10) + + const AssetMockFactory: ContractFactory = await ethers.getContractFactory('AssetMock') + const unpricedAsset: AssetMock = ( + await AssetMockFactory.deploy( + PRICE_TIMEOUT, + await rsrAsset.chainlinkFeed(), + ORACLE_ERROR, + rsr.address, + requiredVolume, + ORACLE_TIMEOUT + ) + ) + await expect( + assetRegistry.connect(owner).swapRegistered(unpricedAsset.address) + ).to.be.revertedWith('RSR asset unpriced') + + const lowMaxAsset: Asset = ( + await AssetFactory.deploy( + PRICE_TIMEOUT, + await rsrAsset.chainlinkFeed(), + ORACLE_ERROR, + rsr.address, + requiredVolume.sub(1), + ORACLE_TIMEOUT + ) + ) + + await expect( + assetRegistry.connect(owner).swapRegistered(lowMaxAsset.address) + ).to.be.revertedWith('RSR maxTradeVolume too low') + expect(await assetRegistry.toAsset(rsr.address)).to.equal(rsrAsset.address) + + const validAsset: Asset = ( + await AssetFactory.deploy( + PRICE_TIMEOUT, + await rsrAsset.chainlinkFeed(), + ORACLE_ERROR, + rsr.address, + requiredVolume, + ORACLE_TIMEOUT + ) + ) + await expect( + assetRegistry.connect(owner).swapRegistered(validAsset.address) + ).to.be.revertedWith('RSR stake too small') + expect(await assetRegistry.toAsset(rsr.address)).to.equal(rsrAsset.address) + + await rsr.mint(addr1.address, fp('1')) + await rsr.connect(addr1).approve(stRSR.address, fp('1')) + await stRSR.connect(addr1).stake(fp('1')) + await expect(assetRegistry.connect(owner).swapRegistered(validAsset.address)) + .to.emit(assetRegistry, 'AssetRegistered') + .withArgs(rsr.address, validAsset.address) + expect(await assetRegistry.toAsset(rsr.address)).to.equal(validAsset.address) }) context('With quantity reverting', function () { @@ -2685,10 +2776,10 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { expect(await indexBH.status()).to.equal(CollateralStatus.SOUND) expect(await indexBH.fullyCollateralized()).to.equal(false) - // Unregister everything except token0 + // Unregister everything except token0 and the protocol assets const erc20s = await assetRegistry.erc20s() for (const erc20 of erc20s) { - if (erc20 != token0.address && erc20 != rToken.address) { + if (erc20 != token0.address && erc20 != rToken.address && erc20 != rsr.address) { await assetRegistry.connect(owner).unregister(await assetRegistry.toAsset(erc20)) } } diff --git a/test/RToken.test.ts b/test/RToken.test.ts index cb958db48c..2804e2c841 100644 --- a/test/RToken.test.ts +++ b/test/RToken.test.ts @@ -1991,10 +1991,15 @@ describe(`RTokenP${IMPLEMENTATION} contract`, () => { }) it('Should not revert when redeeming mostly unregistered collateral #fast', async function () { - // Unregister everything except token0 + // Unregister everything except token0 and the protocol assets const erc20s = await assetRegistry.erc20s() + const rsr = await main.rsr() for (const erc20 of erc20s) { - if (erc20 != token0.address && erc20 != rToken.address) { + if ( + erc20 != token0.address && + erc20 != rToken.address && + erc20.toLowerCase() != rsr.toLowerCase() + ) { await assetRegistry.connect(owner).unregister(await assetRegistry.toAsset(erc20)) } } diff --git a/test/Revenues.test.ts b/test/Revenues.test.ts index b2cc9651e5..4f7e570d2a 100644 --- a/test/Revenues.test.ts +++ b/test/Revenues.test.ts @@ -1395,7 +1395,9 @@ describe(`Revenues - P${IMPLEMENTATION}`, () => { // Perform asset swap await assetRegistry.connect(owner).swapRegistered(newSellAsset.address) + await rsr.mint(stRSR.address, fp('1')) await assetRegistry.connect(owner).swapRegistered(newRSRAsset.address) + await rsr.burn(stRSR.address, fp('1')) await basketHandler.refreshBasket() // Set rewards manually diff --git a/test/scenario/ComplexBasket.test.ts b/test/scenario/ComplexBasket.test.ts index 450cdb9460..c1d2f25fe0 100644 --- a/test/scenario/ComplexBasket.test.ts +++ b/test/scenario/ComplexBasket.test.ts @@ -175,7 +175,9 @@ describe(`Complex Basket - P${IMPLEMENTATION}`, () => { ORACLE_TIMEOUT ) ) + await rsr.mint(stRSR.address, fp('1')) await assetRegistry.connect(owner).swapRegistered(newRSRAsset.address) + await rsr.burn(stRSR.address, fp('1')) rsrAsset = newRSRAsset /***** Setup Basket ***********/ diff --git a/test/scenario/LargeDecimals.test.ts b/test/scenario/LargeDecimals.test.ts index c3900bfeb7..0273ca9ae1 100644 --- a/test/scenario/LargeDecimals.test.ts +++ b/test/scenario/LargeDecimals.test.ts @@ -150,7 +150,9 @@ describe(`Large Decimals Basket - P${IMPLEMENTATION}`, () => { ORACLE_TIMEOUT ) ) + await rsr.mint(stRSR.address, fp('1')) await assetRegistry.connect(owner).swapRegistered(newRSRAsset.address) + await rsr.burn(stRSR.address, fp('1')) rsrAsset = newRSRAsset // Setup reward asset From ae88131287eeb7f25318ba41fde80a6486a0d676 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Fri, 6 Nov 2026 17:31:17 +0000 Subject: [PATCH 2/4] Reduce RSR obligations to an unregister ban Governance is trusted, with the Guardian cancelling malicious proposals, so parameter checks against malicious governance add no security. Drop the RSR asset-swap checks and the minTradeVolume bound, keep the RSR unregister ban, and document the governance trust assumptions. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 +- contracts/p0/AssetRegistry.sol | 14 ----- contracts/p0/BackingManager.sol | 14 ----- contracts/p0/mixins/Trading.sol | 4 -- contracts/p1/AssetRegistry.sol | 16 ------ contracts/p1/BackingManager.sol | 14 ----- contracts/p1/mixins/Trading.sol | 4 -- docs/overview.md | 2 +- docs/system-design.md | 14 +++++ test/Main.test.ts | 89 +---------------------------- test/Revenues.test.ts | 2 - test/scenario/ComplexBasket.test.ts | 2 - test/scenario/LargeDecimals.test.ts | 2 - 13 files changed, 18 insertions(+), 163 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4451173b07..66a77e6180 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,8 @@ - Delay automatic rebalancing after a collateral default while allowing issuance against the backup basket. - Allow governance-triggered basket changes to rebalance without waiting for `tradingDelay`. -- Prevent unregistering RSR and require RSR assets to preserve BackingManager tradeability. -- Limit BackingManager `minTradeVolume` increases to one tenth of both the conservative RSR stake value and the RSR asset's `maxTradeVolume`. +- Prevent unregistering RSR. +- Document the governance trust assumptions: governance is honest, and the Guardian cancels malicious proposals. # 4.2.0 diff --git a/contracts/p0/AssetRegistry.sol b/contracts/p0/AssetRegistry.sol index 6ceee85c09..a864c74fa0 100644 --- a/contracts/p0/AssetRegistry.sol +++ b/contracts/p0/AssetRegistry.sol @@ -176,20 +176,6 @@ contract AssetRegistryP0 is ComponentP0, IAssetRegistry { // Refresh to ensure it does not revert, and to save a recent lastPrice asset.refresh(); - if (address(asset.erc20()) == address(main.rsr())) { - (uint192 low, uint192 high) = asset.price(); - require(low > 0 && high < FIX_MAX, "RSR asset unpriced"); - - uint192 requiredVolume = main.backingManager().minTradeVolume() * 10; - require(asset.maxTradeVolume() >= requiredVolume, "RSR maxTradeVolume too low"); - if (!_isInitializing()) { - require( - asset.bal(address(main.stRSR())).safeMul(low, FLOOR) >= requiredVolume, - "RSR stake too small" - ); - } - } - if (_erc20s.contains(address(asset.erc20())) && assets[asset.erc20()] != asset) { _erc20s.remove(address(asset.erc20())); emit AssetUnregistered(asset.erc20(), assets[asset.erc20()]); diff --git a/contracts/p0/BackingManager.sol b/contracts/p0/BackingManager.sol index 1c5a087ed0..7a3bdce601 100644 --- a/contracts/p0/BackingManager.sol +++ b/contracts/p0/BackingManager.sol @@ -276,18 +276,4 @@ contract BackingManagerP0 is TradingP0, IBackingManager { emit BackingBufferSet(backingBuffer, val); backingBuffer = val; } - - function _validateMinTradeVolume(uint192 val) internal view override { - if (_isInitializing()) return; - - IAsset rsrAsset = main.assetRegistry().toAsset(main.rsr()); - uint192 requiredVolume = val * 10; - require(rsrAsset.maxTradeVolume() >= requiredVolume, "RSR maxTradeVolume too low"); - - (uint192 low, ) = rsrAsset.price(); - require( - rsrAsset.bal(address(main.stRSR())).safeMul(low, FLOOR) >= requiredVolume, - "RSR stake too small" - ); - } } diff --git a/contracts/p0/mixins/Trading.sol b/contracts/p0/mixins/Trading.sol index 55c7799d6f..e96aa3dec5 100644 --- a/contracts/p0/mixins/Trading.sol +++ b/contracts/p0/mixins/Trading.sol @@ -120,11 +120,7 @@ abstract contract TradingP0 is RewardableP0, ITrading { /// @custom:governance function setMinTradeVolume(uint192 val) public governance { require(val <= MAX_TRADE_VOLUME, "invalid minTradeVolume"); - if (val > minTradeVolume) _validateMinTradeVolume(val); emit MinTradeVolumeSet(minTradeVolume, val); minTradeVolume = val; } - - // solhint-disable-next-line no-empty-blocks - function _validateMinTradeVolume(uint192) internal view virtual {} } diff --git a/contracts/p1/AssetRegistry.sol b/contracts/p1/AssetRegistry.sol index e961df9126..f77d73d8fd 100644 --- a/contracts/p1/AssetRegistry.sol +++ b/contracts/p1/AssetRegistry.sol @@ -6,13 +6,11 @@ import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; import "../plugins/assets/RTokenAsset.sol"; import "../interfaces/IAssetRegistry.sol"; import "../interfaces/IMain.sol"; -import "../libraries/Fixed.sol"; import "./mixins/Component.sol"; /// The AssetRegistry provides the mapping from ERC20 to Asset, allowing the rest of Main /// to think in terms of ERC20 tokens and target/ref units. contract AssetRegistryP1 is ComponentP1, IAssetRegistry { - using FixLib for uint192; using EnumerableSet for EnumerableSet.AddressSet; uint256 public constant GAS_FOR_BH_QTY = 100_000; // enough to call bh.quantity @@ -281,20 +279,6 @@ contract AssetRegistryP1 is ComponentP1, IAssetRegistry { // Refresh to ensure it does not revert, and to save a recent lastPrice asset.refresh(); - if (address(erc20) == address(main.rsr())) { - (uint192 low, uint192 high) = asset.price(); - require(low > 0 && high < FIX_MAX, "RSR asset unpriced"); - - uint192 requiredVolume = backingManager.minTradeVolume() * 10; - require(asset.maxTradeVolume() >= requiredVolume, "RSR maxTradeVolume too low"); - if (!_isInitializing()) { - require( - asset.bal(address(main.stRSR())).safeMul(low, FLOOR) >= requiredVolume, - "RSR stake too small" - ); - } - } - if (!main.frozen()) { backingManager.grantRTokenAllowance(erc20); } diff --git a/contracts/p1/BackingManager.sol b/contracts/p1/BackingManager.sol index f0962c2c17..d9e8b679b8 100644 --- a/contracts/p1/BackingManager.sol +++ b/contracts/p1/BackingManager.sol @@ -347,20 +347,6 @@ contract BackingManagerP1 is TradingP1, IBackingManager { backingBuffer = val; } - function _validateMinTradeVolume(uint192 val) internal view override { - if (_isInitializing()) return; - - IAsset rsrAsset = assetRegistry.toAsset(rsr); - uint192 requiredVolume = val * 10; - require(rsrAsset.maxTradeVolume() >= requiredVolume, "RSR maxTradeVolume too low"); - - (uint192 low, ) = rsrAsset.price(); - require( - rsrAsset.bal(address(stRSR)).safeMul(low, FLOOR) >= requiredVolume, - "RSR stake too small" - ); - } - /// Call after upgrade to >= 3.0.0 function cacheComponents() public { assetRegistry = main.assetRegistry(); diff --git a/contracts/p1/mixins/Trading.sol b/contracts/p1/mixins/Trading.sol index 1734953198..6eb40edc83 100644 --- a/contracts/p1/mixins/Trading.sol +++ b/contracts/p1/mixins/Trading.sol @@ -174,14 +174,10 @@ abstract contract TradingP1 is Multicall, ComponentP1, ReentrancyGuardUpgradeabl function setMinTradeVolume(uint192 val) public { requireGovernanceOnly(); require(val <= MAX_TRADE_VOLUME, "invalid minTradeVolume"); - if (val > minTradeVolume) _validateMinTradeVolume(val); emit MinTradeVolumeSet(minTradeVolume, val); minTradeVolume = val; } - // solhint-disable-next-line no-empty-blocks - function _validateMinTradeVolume(uint192) internal view virtual {} - /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. diff --git a/docs/overview.md b/docs/overview.md index 6b1d231e97..68f57e2bf0 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -94,4 +94,4 @@ Standard timelock. Usually 3 days. ### Guardian -The Guardian is simply our name for an address that has the cancellation power in the timelock. +The Guardian is simply our name for an address that has the cancellation power in the timelock. The protocol relies on the Guardian to cancel malicious governance proposals; see [Governance Trust Assumptions](system-design.md#governance-trust-assumptions). diff --git a/docs/system-design.md b/docs/system-design.md index 096d69f91f..ce5c6395b5 100644 --- a/docs/system-design.md +++ b/docs/system-design.md @@ -19,6 +19,20 @@ The remained solidity files in our repository are either: - Mixins for the implementations of the other contracts in the system - Mocks or stubs for testing +## Governance Trust Assumptions + +The protocol assumes that RToken governance is honest, and that the [Guardian](overview.md#guardian) cancels any proposal that attacks RToken holders or RSR stakers before the timelock executes it. Checks on governance parameters guard against specific mistakes; they are not a security boundary against malicious governance. + +This assumption is load-bearing. The OWNER can already prevent or avoid RSR seizure through ordinary configuration, for example by: + +- raising `minTradeVolume`, or registering an RSR asset whose price decays, so that RSR is never sold and RToken holders take a haircut instead +- registering assets or collateral that misreport prices, balances, or status (limited to approved plugins when an `AssetPluginRegistry` is set) +- disabling auctions, pausing trading, freezing, or setting a long `tradingDelay` +- lowering prime basket target amounts with `forceSetPrimeBasket`, for reweightable RTokens +- granting the OWNER role to an address outside the timelock + +The protocol prevents unregistering RSR, but this does not remove the need for honest governance and an attentive Guardian. + ## Notes on Token Flow ### Tokens Held by Different Contracts diff --git a/test/Main.test.ts b/test/Main.test.ts index bc8e642297..747f5fd12a 100644 --- a/test/Main.test.ts +++ b/test/Main.test.ts @@ -36,7 +36,6 @@ import { expectPrice, expectUnpriced, setOraclePrice } from './utils/oracles' import { bn, fp } from '../common/numbers' import { Asset, - AssetMock, ATokenFiatCollateral, BackingManagerP1, BasketHandlerP1, @@ -1073,7 +1072,7 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { }) it('Should allow to update minTradeVolume if OWNER and perform validations', async () => { - const newValue: BigNumber = fp('0.005') + const newValue: BigNumber = fp('0.02') // Check existing value expect(await backingManager.minTradeVolume()).to.equal(config.minTradeVolume) @@ -1098,33 +1097,6 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { ).to.be.revertedWith('invalid minTradeVolume') }) - it('Should bound minTradeVolume increases by RSR tradeability', async () => { - const stakeAmt = fp('2000000') - await rsr.mint(addr1.address, stakeAmt) - await rsr.connect(addr1).approve(stRSR.address, stakeAmt) - await stRSR.connect(addr1).stake(stakeAmt) - - const maxAllowed = (await rsrAsset.maxTradeVolume()).div(10) - await backingManager.connect(owner).setMinTradeVolume(maxAllowed) - await expect( - backingManager.connect(owner).setMinTradeVolume(maxAllowed.add(1)) - ).to.be.revertedWith('RSR maxTradeVolume too low') - - // RevenueTrader settings are independent - await expect(rsrTrader.connect(owner).setMinTradeVolume(maxAllowed.add(1))).to.not.be.reverted - - // Reductions remain available when the stake no longer satisfies the bound - await rsr.burn(stRSR.address, stakeAmt.sub(fp('1'))) - await backingManager.connect(owner).setMinTradeVolume(config.minTradeVolume) - - const [low] = await rsrAsset.price() - const poolAllowed = low.div(10) // one RSR remains in StRSR - await backingManager.connect(owner).setMinTradeVolume(poolAllowed) - await expect( - backingManager.connect(owner).setMinTradeVolume(poolAllowed.add(1)) - ).to.be.revertedWith('RSR stake too small') - }) - it('Should allow to update backingBuffer if OWNER and perform validations', async () => { const newValue: BigNumber = fp('0.02') @@ -1731,65 +1703,6 @@ describe(`MainP${IMPLEMENTATION} contract`, () => { ) }) - it('Should preserve RSR tradeability when swapping its asset', async () => { - const AssetFactory: ContractFactory = await ethers.getContractFactory('Asset') - const requiredVolume = config.minTradeVolume.mul(10) - - const AssetMockFactory: ContractFactory = await ethers.getContractFactory('AssetMock') - const unpricedAsset: AssetMock = ( - await AssetMockFactory.deploy( - PRICE_TIMEOUT, - await rsrAsset.chainlinkFeed(), - ORACLE_ERROR, - rsr.address, - requiredVolume, - ORACLE_TIMEOUT - ) - ) - await expect( - assetRegistry.connect(owner).swapRegistered(unpricedAsset.address) - ).to.be.revertedWith('RSR asset unpriced') - - const lowMaxAsset: Asset = ( - await AssetFactory.deploy( - PRICE_TIMEOUT, - await rsrAsset.chainlinkFeed(), - ORACLE_ERROR, - rsr.address, - requiredVolume.sub(1), - ORACLE_TIMEOUT - ) - ) - - await expect( - assetRegistry.connect(owner).swapRegistered(lowMaxAsset.address) - ).to.be.revertedWith('RSR maxTradeVolume too low') - expect(await assetRegistry.toAsset(rsr.address)).to.equal(rsrAsset.address) - - const validAsset: Asset = ( - await AssetFactory.deploy( - PRICE_TIMEOUT, - await rsrAsset.chainlinkFeed(), - ORACLE_ERROR, - rsr.address, - requiredVolume, - ORACLE_TIMEOUT - ) - ) - await expect( - assetRegistry.connect(owner).swapRegistered(validAsset.address) - ).to.be.revertedWith('RSR stake too small') - expect(await assetRegistry.toAsset(rsr.address)).to.equal(rsrAsset.address) - - await rsr.mint(addr1.address, fp('1')) - await rsr.connect(addr1).approve(stRSR.address, fp('1')) - await stRSR.connect(addr1).stake(fp('1')) - await expect(assetRegistry.connect(owner).swapRegistered(validAsset.address)) - .to.emit(assetRegistry, 'AssetRegistered') - .withArgs(rsr.address, validAsset.address) - expect(await assetRegistry.toAsset(rsr.address)).to.equal(validAsset.address) - }) - context('With quantity reverting', function () { let InvalidRefPerTokFiatCollFactory: ContractFactory let revertCollateral: InvalidRefPerTokCollateralMock diff --git a/test/Revenues.test.ts b/test/Revenues.test.ts index 4f7e570d2a..b2cc9651e5 100644 --- a/test/Revenues.test.ts +++ b/test/Revenues.test.ts @@ -1395,9 +1395,7 @@ describe(`Revenues - P${IMPLEMENTATION}`, () => { // Perform asset swap await assetRegistry.connect(owner).swapRegistered(newSellAsset.address) - await rsr.mint(stRSR.address, fp('1')) await assetRegistry.connect(owner).swapRegistered(newRSRAsset.address) - await rsr.burn(stRSR.address, fp('1')) await basketHandler.refreshBasket() // Set rewards manually diff --git a/test/scenario/ComplexBasket.test.ts b/test/scenario/ComplexBasket.test.ts index c1d2f25fe0..450cdb9460 100644 --- a/test/scenario/ComplexBasket.test.ts +++ b/test/scenario/ComplexBasket.test.ts @@ -175,9 +175,7 @@ describe(`Complex Basket - P${IMPLEMENTATION}`, () => { ORACLE_TIMEOUT ) ) - await rsr.mint(stRSR.address, fp('1')) await assetRegistry.connect(owner).swapRegistered(newRSRAsset.address) - await rsr.burn(stRSR.address, fp('1')) rsrAsset = newRSRAsset /***** Setup Basket ***********/ diff --git a/test/scenario/LargeDecimals.test.ts b/test/scenario/LargeDecimals.test.ts index 0273ca9ae1..c3900bfeb7 100644 --- a/test/scenario/LargeDecimals.test.ts +++ b/test/scenario/LargeDecimals.test.ts @@ -150,9 +150,7 @@ describe(`Large Decimals Basket - P${IMPLEMENTATION}`, () => { ORACLE_TIMEOUT ) ) - await rsr.mint(stRSR.address, fp('1')) await assetRegistry.connect(owner).swapRegistered(newRSRAsset.address) - await rsr.burn(stRSR.address, fp('1')) rsrAsset = newRSRAsset // Setup reward asset From a6cdb1260e349c10a4cf1b7498e5d2ff2c7c930a Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Fri, 6 Nov 2026 17:48:46 +0000 Subject: [PATCH 3/4] Compile BackingManagerP1 with 1 optimizer run BackingManagerP1 exceeds the EIP-170 contract size limit at 200 runs. Override its optimizer runs to 1, following the ConvexStakingWrapper precedent, which brings it to 24,541 bytes. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + hardhat.config.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66a77e6180..d265a93854 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Allow governance-triggered basket changes to rebalance without waiting for `tradingDelay`. - Prevent unregistering RSR. - Document the governance trust assumptions: governance is honest, and the Guardian cancels malicious proposals. +- Compile `BackingManagerP1` with 1 optimizer run so it stays under the contract size limit. # 4.2.0 diff --git a/hardhat.config.ts b/hardhat.config.ts index f954b3b26a..a037c71542 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -31,6 +31,7 @@ const TIMEOUT = useEnv('SLOW') ? 6_000_000 : 600_000 const src_dir = `./contracts/${useEnv('PROTO')}` const settings = useEnv('NO_OPT') ? {} : { optimizer: { enabled: true, runs: 200 } } +const minSizeSettings = useEnv('NO_OPT') ? {} : { optimizer: { enabled: true, runs: 1 } } const config: HardhatUserConfig = { defaultNetwork: 'hardhat', @@ -153,6 +154,13 @@ const config: HardhatUserConfig = { }, ], overrides: { + 'contracts/p1/BackingManager.sol': { + version: '0.8.28', + settings: { + ...minSizeSettings, + evmVersion: 'paris', + }, // contract over-size + }, 'contracts/plugins/assets/convex/vendor/ConvexStakingWrapper.sol': { version: '0.6.12', settings: { optimizer: { enabled: true, runs: 1 } }, // contract over-size From ad9ecf745b3f756b830433143b3b7c9ce77d67ec Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Fri, 6 Nov 2026 17:57:15 +0000 Subject: [PATCH 4/4] Use 100 optimizer runs for BackingManagerP1 100 runs is enough to fit under the contract size limit (24,573 bytes) while costing less gas than 1 run. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- hardhat.config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d265a93854..75f41f29f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Allow governance-triggered basket changes to rebalance without waiting for `tradingDelay`. - Prevent unregistering RSR. - Document the governance trust assumptions: governance is honest, and the Guardian cancels malicious proposals. -- Compile `BackingManagerP1` with 1 optimizer run so it stays under the contract size limit. +- Compile `BackingManagerP1` with 100 optimizer runs so it stays under the contract size limit. # 4.2.0 diff --git a/hardhat.config.ts b/hardhat.config.ts index a037c71542..97b9568906 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -31,7 +31,7 @@ const TIMEOUT = useEnv('SLOW') ? 6_000_000 : 600_000 const src_dir = `./contracts/${useEnv('PROTO')}` const settings = useEnv('NO_OPT') ? {} : { optimizer: { enabled: true, runs: 200 } } -const minSizeSettings = useEnv('NO_OPT') ? {} : { optimizer: { enabled: true, runs: 1 } } +const minSizeSettings = useEnv('NO_OPT') ? {} : { optimizer: { enabled: true, runs: 100 } } const config: HardhatUserConfig = { defaultNetwork: 'hardhat',