Skip to content

Commit

Permalink
fix(evm): domain separator calculation (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs47 authored Jun 3, 2024
1 parent bdec307 commit 8c297d3
Show file tree
Hide file tree
Showing 3 changed files with 1,111 additions and 974 deletions.
20 changes: 14 additions & 6 deletions cosmwasm/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const makeGatewayInstantiateMsg = ({ Router: { address: routerAddress }, VotingV

const makeMultisigProverInstantiateMsg = (config, chainName) => {
const {
axelar: { contracts, chainId: axelarChainId, axelarId },
axelar: { contracts, chainId: axelarChainId },
chains: { [chainName]: chainConfig },
} = config;

Expand Down Expand Up @@ -201,7 +201,19 @@ const makeMultisigProverInstantiateMsg = (config, chainName) => {
},
} = contractConfig;

const separator = domainSeparator || calculateDomainSeparator(axelarId, routerAddress, axelarChainId);
if (!isString(chainId)) {
throw new Error(`Missing or invalid axelar ID for chain ${chainName}`);
}

if (!validateAddress(routerAddress)) {
throw new Error('Missing or invalid Router.address in axelar info');
}

if (!isString(axelarChainId)) {
throw new Error(`Missing or invalid chain ID`);
}

const separator = domainSeparator || calculateDomainSeparator(chainId, routerAddress, axelarChainId);

if (!validateAddress(adminAddress)) {
throw new Error(`Missing or invalid MultisigProver[${chainId}].adminAddress in axelar info`);
Expand All @@ -215,10 +227,6 @@ const makeMultisigProverInstantiateMsg = (config, chainName) => {
throw new Error(`Missing or invalid Gateway[${chainId}].address in axelar info`);
}

if (!validateAddress(routerAddress)) {
throw new Error('Missing or invalid Router.address in axelar info');
}

if (!validateAddress(coordinatorAddress)) {
throw new Error('Missing or invalid Coordinator.address in axelar info');
}
Expand Down
20 changes: 17 additions & 3 deletions evm/deploy-amplifier-gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ const {
isValidAddress,
isKeccak256Hash,
getContractConfig,
isString,
} = require('./utils');
const { calculateDomainSeparator } = require('../cosmwasm/utils');
const { calculateDomainSeparator, isValidCosmosAddress } = require('../cosmwasm/utils');
const { addExtendedOptions } = require('./cli-utils');
const { storeSignedTx, signTransaction, getWallet } = require('./sign-utils.js');

Expand Down Expand Up @@ -77,13 +78,26 @@ async function getDomainSeparator(config, chain, options) {
}

const {
axelar: { contracts, chainId, axelarId },
axelar: { contracts, chainId },
} = config;
const {
Router: { address: routerAddress },
} = contracts;

if (!isString(chain.axelarId)) {
throw new Error(`missing or invalid axelar ID for chain ${chain.name}`);
}

if (!isString(routerAddress) || !isValidCosmosAddress(routerAddress)) {
throw new Error(`missing or invalid router address`);
}

if (!isString(chainId)) {
throw new Error(`missing or invalid chain ID`);
}

const domainSeparator = hexlify((await getContractConfig(config, chain.axelarId)).domain_separator);
const expectedDomainSeparator = calculateDomainSeparator(axelarId, routerAddress, chainId);
const expectedDomainSeparator = calculateDomainSeparator(chain.axelarId, routerAddress, chainId);

if (domainSeparator !== expectedDomainSeparator) {
throw new Error(`unexpected domain separator (want ${expectedDomainSeparator}, got ${domainSeparator})`);
Expand Down
Loading

0 comments on commit 8c297d3

Please sign in to comment.