Transfer ownership in Mailbox initializer (#1477)

pull/1480/head
Asa Oines 2 years ago committed by GitHub
parent 4a8c47c73c
commit fdc6de49da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      solidity/contracts/Mailbox.sol
  2. 2
      solidity/test/isms/multisigIsm.test.ts
  3. 21
      solidity/test/mailbox.test.ts
  4. 2
      solidity/test/router.test.ts
  5. 6
      typescript/infra/config/environments/test/core.ts
  6. 1
      typescript/infra/config/environments/testnet3/core.ts
  7. 3
      typescript/sdk/src/core/TestCoreDeployer.ts
  8. 33
      typescript/sdk/src/deploy/HyperlaneDeployer.ts
  9. 5
      typescript/sdk/src/deploy/core/HyperlaneCoreDeployer.ts
  10. 2
      typescript/sdk/src/deploy/core/types.ts

@ -112,11 +112,15 @@ contract Mailbox is
localDomain = _localDomain; localDomain = _localDomain;
} }
// ============ Initializer ============ // ============ Initializers ============
function initialize(address _defaultIsm) external initializer { function initialize(address _owner, address _defaultIsm)
external
initializer
{
__PausableReentrancyGuard_init(); __PausableReentrancyGuard_init();
__Ownable_init(); __Ownable_init();
transferOwnership(_owner);
_setDefaultIsm(_defaultIsm); _setDefaultIsm(_defaultIsm);
} }

@ -366,7 +366,7 @@ describe('MultisigIsm', async () => {
const destinationMailbox = await mailboxFactory.deploy( const destinationMailbox = await mailboxFactory.deploy(
DESTINATION_DOMAIN, DESTINATION_DOMAIN,
); );
await destinationMailbox.initialize(multisigIsm.address); await destinationMailbox.initialize(signer.address, multisigIsm.address);
await destinationMailbox.process(metadata, message); await destinationMailbox.process(metadata, message);
}); });

@ -35,13 +35,24 @@ describe('Mailbox', async () => {
module = await moduleFactory.deploy(); module = await moduleFactory.deploy();
const mailboxFactory = new TestMailbox__factory(signer); const mailboxFactory = new TestMailbox__factory(signer);
mailbox = await mailboxFactory.deploy(originDomain); mailbox = await mailboxFactory.deploy(originDomain);
await mailbox.initialize(module.address); await mailbox.initialize(signer.address, module.address);
}); });
it('Cannot be initialized twice', async () => { describe('#initialize', () => {
await expect(mailbox.initialize(module.address)).to.be.revertedWith( it('Sets the owner', async () => {
'Initializable: contract is already initialized', const mailboxFactory = new TestMailbox__factory(signer);
); mailbox = await mailboxFactory.deploy(originDomain);
const expectedOwner = nonOwner.address;
await mailbox.initialize(expectedOwner, module.address);
const owner = await mailbox.owner();
expect(owner).equals(expectedOwner);
});
it('Cannot be initialized twice', async () => {
await expect(
mailbox.initialize(signer.address, module.address),
).to.be.revertedWith('Initializable: contract is already initialized');
});
}); });
describe('#dispatch', () => { describe('#dispatch', () => {

@ -79,7 +79,7 @@ describe('Router', async () => {
await router.initialize(mailbox.address); await router.initialize(mailbox.address);
const ism = await new TestIsm__factory(signer).deploy(); const ism = await new TestIsm__factory(signer).deploy();
await ism.setAccept(true); await ism.setAccept(true);
await mailbox.initialize(ism.address); await mailbox.initialize(signer.address, ism.address);
}); });
it('accepts message from enrolled mailbox and router', async () => { it('accepts message from enrolled mailbox and router', async () => {

@ -3,20 +3,24 @@ import { ChainMap, CoreConfig } from '@hyperlane-xyz/sdk';
import { TestChains } from './chains'; import { TestChains } from './chains';
export const core: ChainMap<TestChains, CoreConfig> = { export const core: ChainMap<TestChains, CoreConfig> = {
// Hardhat accounts 1-4 // Owner is hardhat account 0
// Validators are hardhat accounts 1-3
test1: { test1: {
owner: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
multisigIsm: { multisigIsm: {
validators: ['0x70997970c51812dc3a010c7d01b50e0d17dc79c8'], validators: ['0x70997970c51812dc3a010c7d01b50e0d17dc79c8'],
threshold: 1, threshold: 1,
}, },
}, },
test2: { test2: {
owner: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
multisigIsm: { multisigIsm: {
validators: ['0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc'], validators: ['0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc'],
threshold: 1, threshold: 1,
}, },
}, },
test3: { test3: {
owner: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
multisigIsm: { multisigIsm: {
validators: ['0x90f79bf6eb2c4f870365e785982e1f101e93b906'], validators: ['0x90f79bf6eb2c4f870365e785982e1f101e93b906'],
threshold: 1, threshold: 1,

@ -7,6 +7,7 @@ export const core: ChainMap<TestnetChains, CoreConfig> = objMap(
validators, validators,
(_, validatorSet) => { (_, validatorSet) => {
return { return {
owner: '0xfaD1C94469700833717Fa8a3017278BC1cA8031C',
multisigIsm: { multisigIsm: {
validators: validatorSet.validators.map((v) => v.address), validators: validatorSet.validators.map((v) => v.address),
threshold: validatorSet.threshold, threshold: validatorSet.threshold,

@ -16,8 +16,9 @@ import { coreFactories } from './contracts';
const nonZeroAddress = ethers.constants.AddressZero.replace('00', '01'); const nonZeroAddress = ethers.constants.AddressZero.replace('00', '01');
// dummy config as TestInbox and TestOutbox do not use deployed ValidatorManager // dummy config as TestInbox and TestOutbox do not use deployed ISM
const testMultisigIsmConfig: CoreConfig = { const testMultisigIsmConfig: CoreConfig = {
owner: nonZeroAddress,
multisigIsm: { multisigIsm: {
validators: [nonZeroAddress], validators: [nonZeroAddress],
threshold: 1, threshold: 1,

@ -173,19 +173,25 @@ export abstract class HyperlaneDeployer<
salt, salt,
); );
const deployTx = deployOpts.initCalldata if ((await chainConnection.provider.getCode(contractAddr)) === '0x') {
? await create2Factory.deployAndInit( const deployTx = deployOpts.initCalldata
bytecode, ? await create2Factory.deployAndInit(
salt, bytecode,
deployOpts.initCalldata, salt,
chainConnection.overrides, deployOpts.initCalldata,
) chainConnection.overrides,
: await create2Factory.deploy( )
bytecode, : await create2Factory.deploy(
salt, bytecode,
chainConnection.overrides, salt,
); chainConnection.overrides,
await chainConnection.handleTx(deployTx); );
await chainConnection.handleTx(deployTx);
} else {
this.logger(
`Found contract deployed at CREATE2 address, skipping contract deploy`,
);
}
this.verificationInputs[chain].push({ this.verificationInputs[chain].push({
name: contractName, name: contractName,
@ -295,6 +301,7 @@ export abstract class HyperlaneDeployer<
proxy.address, proxy.address,
implementation.address, implementation.address,
initData, initData,
chainConnection.overrides,
); );
} else { } else {
const constructorArgs: Parameters< const constructorArgs: Parameters<

@ -68,13 +68,14 @@ export class HyperlaneCoreDeployer<
deployOpts?: DeployOptions, deployOpts?: DeployOptions,
): Promise<ProxiedContract<Mailbox, TransparentProxyAddresses>> { ): Promise<ProxiedContract<Mailbox, TransparentProxyAddresses>> {
const domain = chainMetadata[chain].id; const domain = chainMetadata[chain].id;
const owner = this.configMap[chain].owner;
const mailbox = await this.deployProxiedContract( const mailbox = await this.deployProxiedContract(
chain, chain,
'mailbox', 'mailbox',
[domain], [domain],
proxyAdmin, proxyAdmin,
[defaultIsmAddress], [owner, defaultIsmAddress],
deployOpts, deployOpts,
); );
return mailbox; return mailbox;
@ -204,8 +205,8 @@ export class HyperlaneCoreDeployer<
owner: types.Address, owner: types.Address,
chainConnection: ChainConnection, chainConnection: ChainConnection,
): Promise<ethers.ContractReceipt[]> { ): Promise<ethers.ContractReceipt[]> {
// Mailbox ownership is transferred upon initialization.
const ownables: Ownable[] = [ const ownables: Ownable[] = [
coreContracts.mailbox.contract,
coreContracts.multisigIsm, coreContracts.multisigIsm,
coreContracts.proxyAdmin, coreContracts.proxyAdmin,
]; ];

@ -11,7 +11,7 @@ export type MultisigIsmConfig = {
export type CoreConfig = { export type CoreConfig = {
multisigIsm: MultisigIsmConfig; multisigIsm: MultisigIsmConfig;
owner?: types.Address; owner: types.Address;
remove?: boolean; remove?: boolean;
}; };

Loading…
Cancel
Save