Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect against frontrunning #9

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/DefaultInflationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ contract DefaultInflationManager is Initializable, Ownable2StepUpgradeable, IDef
// log2(2%pa continuously compounded inflation per year) in 18 decimals, see _inflatedSupplyAfter
uint256 public constant INTEREST_PER_YEAR_LOG2 = 0.028569152196770894e18;
uint256 public constant START_SUPPLY = 10_000_000_000e18;
address private immutable DEPLOYER;

IPolygon public token;
IPolygonMigration public migration;
Expand All @@ -29,6 +30,7 @@ contract DefaultInflationManager is Initializable, Ownable2StepUpgradeable, IDef
uint256 public startTimestamp;

constructor() {
DEPLOYER = msg.sender;
// so that the implementation contract cannot be initialized
_disableInitializers();
}
Expand All @@ -40,6 +42,8 @@ contract DefaultInflationManager is Initializable, Ownable2StepUpgradeable, IDef
address treasury_,
address owner_
) external initializer {
// prevent front-running since we can't initialize on proxy deployment
if (DEPLOYER != msg.sender) revert();
if (
token_ == address(0) ||
migration_ == address(0) ||
Expand Down
10 changes: 8 additions & 2 deletions test/DefaultInflationManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,25 @@ contract DefaultInflationManagerTest is Test {
assertEq(polygon.totalSupply(), 10_000_000_000e18);
}

function test_InvalidDeployment(uint256 seed) external {
function test_InvalidDeployment(uint160 seed) external {
address[5] memory params = [
makeAddr("polygon"),
makeAddr("migration"),
makeAddr("stakeManager"),
makeAddr("treasury"),
makeAddr("governance")
];
params[seed % params.length] = address(0); // any one is zero addr

address proxy = address(
new TransparentUpgradeableProxy(address(new DefaultInflationManager()), msg.sender, "")
);

vm.prank(address(seed));
vm.expectRevert();
DefaultInflationManager(proxy).initialize(params[0], params[1], params[2], params[3], params[4]);

params[seed % params.length] = address(0); // any one is zero addr

vm.expectRevert(InvalidAddress.selector);
DefaultInflationManager(proxy).initialize(params[0], params[1], params[2], params[3], params[4]);
}
Expand Down