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

Added verification for ostcomposer and redeempool contract #160

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
61 changes: 61 additions & 0 deletions src/NewChain/ChainVerifier.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Contracts as MosaicContracts, AbiBinProvider } from '@openst/mosaic.js';

import { contracts } from '@openst/mosaic-contracts';

import MosaicConfig, { ContractAddresses } from '../Config/MosaicConfig';

import Logger from '../Logger';
Expand Down Expand Up @@ -65,6 +67,8 @@ export default class ChainVerifier {
await this.verifyOriginAnchor();
await this.verifyAuxiliaryAnchor();
await this.verifyOSTPrime();
await this.verifyRedeemPool();
await this.verifyOSTComposer();

Logger.info('Successfully completed chain verification!!!');
}
Expand Down Expand Up @@ -394,6 +398,63 @@ export default class ChainVerifier {
Logger.info('Successfully completed OSTPrime contract verification!!!');
}

/**
* It verifies bin of ost composer contract.
* @returns
*/
private async verifyOSTComposer(): Promise<void> {
const ostComposerBin = contracts.OSTComposer.bin;
const { ostComposerAddress } = this.mosaicConfig.originChain.contractAddresses;
await this.validateBinFromMosaicContracts(
this.originWeb3,
ostComposerBin,
'ContractsBin: Mismatch of OSTComposer BIN!!!',
'OSTComposer',
ostComposerAddress,
);
Logger.info('Successfully completed OSTComposer contract verification!!!');
}

/**
* It verifies bin of redeem pool contract.
*/
private async verifyRedeemPool(): Promise<void> {
const redeemPoolBin = contracts.RedeemPool.bin;
const { redeemPoolAddress } = this.contractAddresses.auxiliary;

await this.validateBinFromMosaicContracts(
this.auxiliaryWeb3,
redeemPoolBin,
'ContractsBin: Mismatch of RedeemPool BIN!!!',
'RedeemPool',
redeemPoolAddress,
);
Logger.info('Successfully completed RedeemPool contract verification!!!');
}

/**
* Check if deployed bin is valid or not.
* Note: It is to be used for bin's of contracts which are not present in mosaic.js.
* @param web3 Web3 instance.
* @param binFromMosaicContract Bin for the contract from mosaic-contracts package.
* @param errMsg Message to be displayed when bin from chain and mosaic-contracts doesn't match.
* @param contractName Name of the contract.
* @param contractAddress Address of the contract.
*/
private async validateBinFromMosaicContracts(
web3,
binFromMosaicContract,
errMsg,
contractName,
contractAddress,
): Promise<void> {
const deployedBin = await web3.eth.getCode(contractAddress);
if (binFromMosaicContract.toLowerCase().indexOf(deployedBin.toLowerCase().slice(2)) === -1) {
Logger.error(errMsg, { contractName, contractAddress });
throw new Error(errMsg);
}
}

/**
* Check if deployed bin is valid or not
* @param web3 Web3 endpoint.
Expand Down