From a9392fc4ff0e8029b84b423fc0c184b46883b8f6 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Fri, 27 Nov 2026 19:20:09 +0000 Subject: [PATCH 1/4] 4.3.0 spell: check collateralization, RSR, and TrustedFillerRegistry Trust audit findings for the 4.3.0 upgrade spell: - require the RToken to be fully collateralized, since the proposal unregisters deprecated assets before casting - require RSR to still be registered, since 4.2.0 allows unregistering it - require the Broker to use the DAO's TrustedFillerRegistry The proposal builder now refuses to unregister a deprecated RSR asset and fails early when the RToken is not fully collateralized. Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 2 +- contracts/spells/4_3_0.sol | 12 +++++++++++- tasks/validation/proposals/4_3_0.ts | 11 +++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fed6340a..d350caaaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ - 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. -- Add the `Upgrade4_3_0` spell to upgrade eUSD, ETH+, USD3, and bsdETH from 4.2.0. The spell rotates each RTokenAsset; no other assets are redeployed. It also takes a `newTradingDelay` and sets it on the BackingManager, so each community can choose `tradingDelay` for its new meaning. +- Add the `Upgrade4_3_0` spell to upgrade eUSD, ETH+, USD3, and bsdETH from 4.2.0. The spell rotates each RTokenAsset; no other assets are redeployed. It also takes a `newTradingDelay` and sets it on the BackingManager, so each community can choose `tradingDelay` for its new meaning. The spell requires the RToken to be SOUND and fully collateralized, RSR to be registered, and the Broker to use the DAO's TrustedFillerRegistry. ## Rounding Changes diff --git a/contracts/spells/4_3_0.sol b/contracts/spells/4_3_0.sol index 7e3fd7125..c0e6da65b 100644 --- a/contracts/spells/4_3_0.sol +++ b/contracts/spells/4_3_0.sol @@ -24,6 +24,7 @@ bytes32 constant MAIN_OWNER_ROLE = bytes32("OWNER"); * - the 4.3.0 deployer must be registered in the VersionRegistry * - all currently registered assets must be valid for 4.3.0 in the AssetPluginRegistry; * deprecated assets must be unregistered first + * - RSR must be registered, and the RToken must be SOUND and fully collateralized * - this contract must have MAIN_OWNER_ROLE of Main * * The spell rotates the RTokenAsset, keeping its maxTradeVolume. No other assets are changed. @@ -117,7 +118,9 @@ contract Upgrade4_3_0 is Versioned { require( main.versionRegistry() == registries.versionRegistry && main.assetPluginRegistry() == registries.assetPluginRegistry && - main.daoFeeRegistry() == registries.daoFeeRegistry, + main.daoFeeRegistry() == registries.daoFeeRegistry && + TestIBroker(address(main.broker())).trustedFillerRegistry() == + registries.trustedFillerRegistry, Err(4) ); @@ -137,6 +140,9 @@ contract Upgrade4_3_0 is Versioned { stRSR: main.stRSR() }); + // RSR should still be registered: 4.2.0 allows unregistering it, 4.3.0 does not + require(proxy.assetRegistry.isRegistered(main.rsr()), Err(15)); + // tradingDelay should only increase require( newTradingDelay >= TestIBackingManager(address(proxy.backingManager)).tradingDelay(), @@ -195,6 +201,10 @@ contract Upgrade4_3_0 is Versioned { proxy.assetRegistry.refresh(); require(proxy.basketHandler.status() == CollateralStatus.SOUND, Err(11)); + + // Assets unregistered before casting may have been needed to restore the backing. + // Unregistering cannot change this result without also disabling the basket. + require(proxy.basketHandler.fullyCollateralized(), Err(16)); } // Set tradingDelay for its 4.3.0 meaning diff --git a/tasks/validation/proposals/4_3_0.ts b/tasks/validation/proposals/4_3_0.ts index b4b1fb839..109fd673b 100644 --- a/tasks/validation/proposals/4_3_0.ts +++ b/tasks/validation/proposals/4_3_0.ts @@ -48,6 +48,12 @@ export const proposal_4_3_0 = async ( await main.basketHandler() ) const [primeERC20s] = await basketHandler.getPrimeBasket() + const rsr = await main.rsr() + + // Unregistered assets may be needed to restore the backing. The spell checks this too. + if (!(await basketHandler.fullyCollateralized())) { + throw new Error('RToken is not fully collateralized') + } // Unregister deprecated assets, which would fail the spell's asset validation const txs = [] @@ -55,6 +61,11 @@ export const proposal_4_3_0 = async ( for (let i = 0; i < assets.length; i++) { if (!(await assetPluginRegistry.isDeprecated(assets[i]))) continue + // 4.2.0 allows unregistering RSR; the spell requires it to stay registered + if (erc20s[i] == rsr) { + throw new Error(`deprecated RSR asset ${assets[i]} must be swapped, not unregistered`) + } + if (primeERC20s.includes(erc20s[i]) || (await basketHandler.quantity(erc20s[i])).gt(0)) { throw new Error(`deprecated asset ${assets[i]} is in the basket`) } From 2c0476410f9ef9f308315384134e3bce45e30c30 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Fri, 27 Nov 2026 19:28:47 +0000 Subject: [PATCH 2/4] 4.3.0 fork task: check the spell rejects a broken RToken Before validating each proposal, check that castSpell reverts when RSR has been unregistered (Err 15) and when the RToken is not fully collateralized (Err 16). Co-Authored-By: Claude Fable 5.2 --- tasks/validation/spells/4.3.0.ts | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tasks/validation/spells/4.3.0.ts b/tasks/validation/spells/4.3.0.ts index 5e1ee3f96..3f5cad8e5 100644 --- a/tasks/validation/spells/4.3.0.ts +++ b/tasks/validation/spells/4.3.0.ts @@ -10,6 +10,8 @@ import { resetFork } from '#/utils/chain' import { MAIN_OWNER_ROLE } from '../proposals/4_2_0' import { proposal_4_3_0 } from '../proposals/4_3_0' import { Upgrade4_3_0 } from '#/typechain' +import { Proposal } from '#/utils/subgraph' +import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' const VERSION_4_3_0_HASH = '0xdef94dbdd8411ae515cefcb56b153df454453010a1f4c881b3daa7ed18db793a' const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000' @@ -147,6 +149,73 @@ const setup_4_3_0 = async (hre: HardhatRuntimeEnvironment, deployment: RTokenDep } } +// The spell should refuse an RToken that lost RSR, or that is not fully collateralized +const checkSpellGuards = async ( + hre: HardhatRuntimeEnvironment, + deployment: RTokenDeployment, + spell: Upgrade4_3_0, + proposal: Proposal +) => { + const rToken = await hre.ethers.getContractAt('RTokenP1', deployment.rToken) + const main = await hre.ethers.getContractAt('MainP1', await rToken.main()) + const assetRegistry = await hre.ethers.getContractAt( + 'AssetRegistryP1', + await main.assetRegistry() + ) + const basketHandler = await hre.ethers.getContractAt( + 'BasketHandlerP1', + await main.basketHandler() + ) + + // Runs the proposal up to castSpell, breaks the RToken, then expects castSpell to revert + const expectErr = async ( + index: number, + breakRToken: (timelock: SignerWithAddress) => unknown + ) => { + const snapshot = await hre.network.provider.send('evm_snapshot') + + await whileImpersonating(hre, deployment.timelock, async (timelock) => { + for (let i = 0; i < proposal.targets.length - 1; i++) { + await timelock.sendTransaction({ to: proposal.targets[i], data: proposal.calldatas[i] }) + } + await breakRToken(timelock) + + const expected = spell.interface.encodeErrorResult('Err', [index]) + const actual = await hre.network.provider + .send('eth_call', [ + { + from: timelock.address, + to: spell.address, + data: proposal.calldatas[proposal.calldatas.length - 1], + }, + ]) + .then( + () => 'no revert', + (e) => e.data + ) + if (actual != expected) throw new Error(`expected Err(${index}), got ${actual}`) + }) + + await hre.network.provider.send('evm_revert', [snapshot]) + console.log(`Spell reverts with Err(${index}) as expected`) + } + + // 4.2.0 allows unregistering RSR + await expectErr(15, async (timelock) => { + await assetRegistry.connect(timelock).unregister(await assetRegistry.toAsset(await main.rsr())) + }) + + // Move a basket token out of the BackingManager + await expectErr(16, async (timelock) => { + const backingManager = await main.backingManager() + const [erc20s] = await basketHandler.getPrimeBasket() + const erc20 = await hre.ethers.getContractAt('ERC20Mock', erc20s[0]) + await whileImpersonating(hre, backingManager, async (signer) => { + await erc20.connect(signer).transfer(timelock.address, await erc20.balanceOf(backingManager)) + }) + }) +} + // Use this once to serialize a proposal task('4.3.0', 'Upgrade to 4.3.0').setAction(async (_, hre) => { const network = useEnv('FORK_NETWORK').toLowerCase() @@ -191,6 +260,8 @@ task('4.3.0', 'Upgrade to 4.3.0').setAction(async (_, hre) => { result.governor = anastasius.address result.timelock = deployment.timelock + await checkSpellGuards(hre, deployment, spell, result) + const descHash = hre.ethers.utils.keccak256(hre.ethers.utils.toUtf8Bytes(result.description)) result.proposalId = BigNumber.from( await anastasius.hashProposal(result.targets, result.values, result.calldatas, descHash) From 09303409209a70e1990b1fba92f9554e902615e5 Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Fri, 27 Nov 2026 19:44:36 +0000 Subject: [PATCH 3/4] 4.3.0 proposal tooling: skip the RToken asset, break the current basket Review feedback: - the proposal builder skipped nothing for a deprecated RTokenAsset and would queue an unregister that 4.2.0 rejects; the spell rotates it - the fork task's undercollateralization check moved the first prime basket token, which may not be in the current basket Co-Authored-By: Claude Fable 5.2 --- tasks/validation/proposals/4_3_0.ts | 3 +++ tasks/validation/spells/4.3.0.ts | 20 ++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tasks/validation/proposals/4_3_0.ts b/tasks/validation/proposals/4_3_0.ts index 109fd673b..bd91b2a8c 100644 --- a/tasks/validation/proposals/4_3_0.ts +++ b/tasks/validation/proposals/4_3_0.ts @@ -59,6 +59,9 @@ export const proposal_4_3_0 = async ( const txs = [] const [erc20s, assets] = await assetRegistry.getRegistry() for (let i = 0; i < assets.length; i++) { + // The RToken's own asset cannot be unregistered; the spell rotates it + if (erc20s[i] == rToken.address) continue + if (!(await assetPluginRegistry.isDeprecated(assets[i]))) continue // 4.2.0 allows unregistering RSR; the spell requires it to stay registered diff --git a/tasks/validation/spells/4.3.0.ts b/tasks/validation/spells/4.3.0.ts index 3f5cad8e5..452d1aca7 100644 --- a/tasks/validation/spells/4.3.0.ts +++ b/tasks/validation/spells/4.3.0.ts @@ -205,14 +205,22 @@ const checkSpellGuards = async ( await assetRegistry.connect(timelock).unregister(await assetRegistry.toAsset(await main.rsr())) }) - // Move a basket token out of the BackingManager + // Move a token of the current basket out of the BackingManager await expectErr(16, async (timelock) => { const backingManager = await main.backingManager() - const [erc20s] = await basketHandler.getPrimeBasket() - const erc20 = await hre.ethers.getContractAt('ERC20Mock', erc20s[0]) - await whileImpersonating(hre, backingManager, async (signer) => { - await erc20.connect(signer).transfer(timelock.address, await erc20.balanceOf(backingManager)) - }) + const erc20s = await assetRegistry.erc20s() + for (const addr of erc20s) { + if ((await basketHandler.quantity(addr)).eq(0)) continue + + const erc20 = await hre.ethers.getContractAt('ERC20Mock', addr) + await whileImpersonating(hre, backingManager, async (signer) => { + await erc20 + .connect(signer) + .transfer(timelock.address, await erc20.balanceOf(backingManager)) + }) + break + } + if (await basketHandler.fullyCollateralized()) throw new Error('still fully collateralized') }) } From 7084d86bb3b3b2525f1a453a22d59e8d2137af2a Mon Sep 17 00:00:00 2001 From: Taylor Brent Date: Fri, 27 Nov 2026 19:47:09 +0000 Subject: [PATCH 4/4] 4.3.0 proposal tooling: compare addresses by value, read the current basket Review feedback: - compare the RToken address case-insensitively when skipping its asset - pick the token to move from the current basket; quantity() is also nonzero for an off-basket collateral with a zero refPerTok Co-Authored-By: Claude Fable 5.2 --- tasks/validation/proposals/4_3_0.ts | 2 +- tasks/validation/spells/4.3.0.ts | 17 +++++------------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/tasks/validation/proposals/4_3_0.ts b/tasks/validation/proposals/4_3_0.ts index bd91b2a8c..e462be7cf 100644 --- a/tasks/validation/proposals/4_3_0.ts +++ b/tasks/validation/proposals/4_3_0.ts @@ -60,7 +60,7 @@ export const proposal_4_3_0 = async ( const [erc20s, assets] = await assetRegistry.getRegistry() for (let i = 0; i < assets.length; i++) { // The RToken's own asset cannot be unregistered; the spell rotates it - if (erc20s[i] == rToken.address) continue + if (erc20s[i].toLowerCase() == rTokenAddress.toLowerCase()) continue if (!(await assetPluginRegistry.isDeprecated(assets[i]))) continue diff --git a/tasks/validation/spells/4.3.0.ts b/tasks/validation/spells/4.3.0.ts index 452d1aca7..6485f5a0b 100644 --- a/tasks/validation/spells/4.3.0.ts +++ b/tasks/validation/spells/4.3.0.ts @@ -208,18 +208,11 @@ const checkSpellGuards = async ( // Move a token of the current basket out of the BackingManager await expectErr(16, async (timelock) => { const backingManager = await main.backingManager() - const erc20s = await assetRegistry.erc20s() - for (const addr of erc20s) { - if ((await basketHandler.quantity(addr)).eq(0)) continue - - const erc20 = await hre.ethers.getContractAt('ERC20Mock', addr) - await whileImpersonating(hre, backingManager, async (signer) => { - await erc20 - .connect(signer) - .transfer(timelock.address, await erc20.balanceOf(backingManager)) - }) - break - } + const [erc20s] = await basketHandler.getHistoricalBasket(await basketHandler.nonce()) + const erc20 = await hre.ethers.getContractAt('ERC20Mock', erc20s[0]) + await whileImpersonating(hre, backingManager, async (signer) => { + await erc20.connect(signer).transfer(timelock.address, await erc20.balanceOf(backingManager)) + }) if (await basketHandler.fullyCollateralized()) throw new Error('still fully collateralized') }) }