Skip to content

Commit

Permalink
fix: Add additional factory validation for loan migration (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfarhaan authored Nov 20, 2023
1 parent 9effdcd commit 20e4528
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion contracts/MapleLoanV502Migrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { MapleLoanStorage } from "./MapleLoanStorage.sol";

/// @title MapleLoanV502Migrator is to update the factory address for each deployed loan.
contract MapleLoanV502Migrator is ProxiedInternals, MapleLoanStorage {

fallback() external {
( address newFactory_ ) = abi.decode(msg.data, (address));

require(_factory() != newFactory_, "MLV502M:INVALID_NO_OP");

address globals = IMapleProxyFactoryLike(_factory()).mapleGlobals();

require(IGlobalsLike(globals).isInstanceOf("FT_LOAN_FACTORY", newFactory_), "MLV502M:INVALID_FACTORY");
Expand Down
10 changes: 10 additions & 0 deletions tests/MapleLoanV502Migrator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ contract MapleLoanV502MigratorTests is TestUtils {
loan502 = MapleLoan(oldFactory.createInstance(arguments, "SALT2"));
}

function test_migration_sameFactory_noOp() external {
newFactory = new MapleLoanFactory(address(globals), address(oldFactory));

bytes memory arguments = abi.encode(address(oldFactory));

vm.expectRevert("MPF:UI:FAILED");
vm.prank(securityAdmin);
loan501.upgrade(502, arguments);
}

function test_migration_invalidFactory() external {
newFactory = new MapleLoanFactory(address(globals), address(oldFactory));

Expand Down

0 comments on commit 20e4528

Please sign in to comment.