diff --git a/CHANGELOG.md b/CHANGELOG.md index ba1c3a782..75f41f29f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ - 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. +- Document the governance trust assumptions: governance is honest, and the Guardian cancels malicious proposals. +- Compile `BackingManagerP1` with 100 optimizer runs so it stays under the contract size limit. # 4.2.0 diff --git a/contracts/p0/AssetRegistry.sol b/contracts/p0/AssetRegistry.sol index 37eb43b9a..a864c74fa 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"); diff --git a/contracts/p1/AssetRegistry.sol b/contracts/p1/AssetRegistry.sol index 8398654e7..f77d73d8f 100644 --- a/contracts/p1/AssetRegistry.sol +++ b/contracts/p1/AssetRegistry.sol @@ -132,6 +132,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"); diff --git a/docs/overview.md b/docs/overview.md index 6b1d231e9..68f57e2bf 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 096d69f91..ce5c6395b 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/hardhat.config.ts b/hardhat.config.ts index f954b3b26..97b956890 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: 100 } } 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 diff --git a/test/Main.test.ts b/test/Main.test.ts index ab6b903aa..747f5fd12 100644 --- a/test/Main.test.ts +++ b/test/Main.test.ts @@ -1577,14 +1577,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 +1694,13 @@ 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' + ) }) context('With quantity reverting', function () { @@ -2685,10 +2689,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 cb958db48..2804e2c84 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)) } }