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

Fix multisig contracts ownership #950

Merged
merged 3 commits into from
Sep 19, 2022
Merged
Changes from 2 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
70 changes: 43 additions & 27 deletions nightfall-deployer/src/contract-setup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,70 @@ address of the contract that holds global state (State.sol)
import config from 'config';
import logger from 'common-files/utils/logger.mjs';
import Web3 from 'common-files/utils/web3.mjs';
import { waitForContract, getContractAddress } from 'common-files/utils/contract.mjs';
import { waitForContract } from 'common-files/utils/contract.mjs';

async function setupCircuits() {
async function setupContracts() {
const stateInstance = await waitForContract('State');
logger.debug(`address of State contract is ${stateInstance.options.address}`);

const simpleMultiSigAddress = (await waitForContract('SimpleMultiSig')).options.address;
const shieldContractInstance = await waitForContract('Shield');
const stateContractInstance = await waitForContract('State');
const proposerContractInstance = await waitForContract('Proposers');
const challengesContractInstance = await waitForContract('Challenges');

logger.debug(
`transfering ownership of contracts to simpleMultiSigAddress ${simpleMultiSigAddress}`,
);

// when deploying on infura
// do serial registration to predict nonce
// or, if we have the owner's private key, sign with that, rather than use an unlocked account
if (config.ETH_PRIVATE_KEY) {
await Web3.submitRawTransaction(
(await waitForContract('Proposers')).methods
.setStateContract(stateInstance.options.address)
.encodeABI(),
await getContractAddress('Proposers'),
proposerContractInstance.methods.setStateContract(stateInstance.options.address).encodeABI(),
proposerContractInstance.options.address,
);
await Web3.submitRawTransaction(
shieldContractInstance.methods.setStateContract(stateInstance.options.address).encodeABI(),
shieldContractInstance.options.address,
);
await Web3.submitRawTransaction(
(await waitForContract('Shield')).methods
challengesContractInstance.methods
.setStateContract(stateInstance.options.address)
.encodeABI(),
await getContractAddress('Shield'),
challengesContractInstance.options.address,
);

// our last action as the deployer is to hand off our onlyOwner powers to the
// multisig contract
await Web3.submitRawTransaction(
shieldContractInstance.methods.transferOwnership(simpleMultiSigAddress).encodeABI(),
shieldContractInstance.options.address,
);
await Web3.submitRawTransaction(
stateContractInstance.methods.transferOwnership(simpleMultiSigAddress).encodeABI(),
stateContractInstance.options.address,
);
await Web3.submitRawTransaction(
proposerContractInstance.methods.transferOwnership(simpleMultiSigAddress).encodeABI(),
proposerContractInstance.options.address,
);
return Web3.submitRawTransaction(
(await waitForContract('Challenges')).methods
.setStateContract(stateInstance.options.address)
.encodeABI(),
await getContractAddress('Challenges'),
challengesContractInstance.methods.transferOwnership(simpleMultiSigAddress).encodeABI(),
challengesContractInstance.options.address,
);
}

// the following code runs the registrations in parallel
await Promise.all([
(await waitForContract('Proposers')).methods
.setStateContract(stateInstance.options.address)
.send(),
(await waitForContract('Shield')).methods
.setStateContract(stateInstance.options.address)
.send(),
(await waitForContract('Challenges')).methods
.setStateContract(stateInstance.options.address)
.send(),
proposerContractInstance.methods.setStateContract(stateInstance.options.address).send(),
shieldContractInstance.methods.setStateContract(stateInstance.options.address).send(),
challengesContractInstance.methods.setStateContract(stateInstance.options.address).send(),
]);

// our last action as the deployer is to hand off our onlyOwner powers to the
// multisig contract
const simpleMultiSigAddress = (await waitForContract('SimpleMultiSig')).options.address;
const shieldContractInstance = await waitForContract('Shield');
const stateContractInstance = await waitForContract('State');
const proposerContractInstance = await waitForContract('Proposers');
const challengesContractInstance = await waitForContract('Challenges');
return Promise.all([
shieldContractInstance.methods.transferOwnership(simpleMultiSigAddress).send(),
stateContractInstance.methods.transferOwnership(simpleMultiSigAddress).send(),
Expand All @@ -62,4 +78,4 @@ async function setupCircuits() {
]);
}

export default setupCircuits;
export default setupContracts;