Skip to content

Commit

Permalink
[L04] Prevent initialization of the Configurator implementation contr…
Browse files Browse the repository at this point in the history
…act (#425)

This change should prevent anyone from being able to call initialize on the implementation contract of Configurator.

Addresses #378
  • Loading branch information
kevincheng96 committed Jun 23, 2022
1 parent 4e62929 commit 79f59e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions contracts/Configurator.sol
Expand Up @@ -42,6 +42,12 @@ contract Configurator is ConfiguratorStorage {
error InvalidAddress();
error Unauthorized();

/// @notice Constructs a new Configurator instance
constructor() {
// Set a high version to prevent the implementation contract from being initialized
version = type(uint256).max;
}

/// @notice Initializes the storage for Configurator
function initialize(address _governor, address _factory, Configuration calldata _config) public {
if (version != 0) revert AlreadyInitialized();
Expand Down
9 changes: 8 additions & 1 deletion test/configurator-test.ts
Expand Up @@ -44,7 +44,7 @@ describe('configurator', function () {

const configuratorAsProxy = configurator.attach(configuratorProxy.address);
const txn = await wait(configuratorAsProxy.deploy()) as any;
const [ newCometAddress ] = txn.receipt.events.find(event => event.event === 'CometDeployed').args;
const [newCometAddress] = txn.receipt.events.find(event => event.event === 'CometDeployed').args;

expect(event(txn, 0)).to.be.deep.equal({
CometDeployed: {
Expand Down Expand Up @@ -104,6 +104,13 @@ describe('configurator', function () {
await expect(configuratorAsProxy.initialize(governor.address, cometFactory.address, configuration)).to.be.revertedWith("custom error 'AlreadyInitialized()'");
});

it('reverts if initializing the implementation contract', async () => {
const { governor, configurator, cometFactory } = await makeConfigurator();

let configuration = await configurator.getConfiguration();
await expect(configurator.initialize(governor.address, cometFactory.address, configuration)).to.be.revertedWith("custom error 'AlreadyInitialized()'");
});

describe('configuration setters', function () {
it('sets governor and deploys Comet with new configuration', async () => {
const { configurator, configuratorProxy, proxyAdmin, comet, cometProxy, users: [alice] } = await makeConfigurator();
Expand Down

0 comments on commit 79f59e5

Please sign in to comment.