Skip to content

feat(cosmwasm): load-time validation for instantiated contract addresses#1309

Open
AttissNgo wants to merge 1 commit into
mainfrom
feat/load-time-validation-for-instantiated-cosmwasm-contracts
Open

feat(cosmwasm): load-time validation for instantiated contract addresses#1309
AttissNgo wants to merge 1 commit into
mainfrom
feat/load-time-validation-for-instantiated-cosmwasm-contracts

Conversation

@AttissNgo

@AttissNgo AttissNgo commented Dec 19, 2025

Copy link
Copy Markdown
Contributor
  • add InstantiatedContractConfig interface with required address field
  • add load-time validation for Amplifier Protocol contracts
  • add new getter methods
  • replace awkward validateRequired pattern

why

Improve type safety and provide fail-fast validation with clear error messages when required contracts are missing addresses


Note

Adds load-time validation for required contract addresses, introduces typed getters for instantiated contracts, and refactors CosmWasm commands/migrations/queries to use them with chain-type-aware resolution.

  • Config:
    • Add InstantiatedContractConfig, AMPLIFIER_PROTOCOL_CONTRACTS, and validateAmplifierProtocolContracts() to enforce required addresses at load.
    • Introduce safe getters: getContractAddress, getInstantiatedContractConfig, getInstantiatedContractByChain; use in getChainCodecAddress().
  • CosmWasm:
    • Refactor to replace validateRequired(...address) with new getters across contract.ts, coordinator.ts, migrate/chain-codec.ts, migrate/sdk50.ts, migrate/update-rewards-pool-epoch-duration.ts, query.ts, and utils.js (e.g., itsHubChainParams).
    • Use chain-type-specific contract names when resolving VotingVerifier/MultisigProver during operations and migrations.

Written by Cursor Bugbot for commit 7a895db. This will update automatically on new commits. Configure here.

- add InstantiatedContractConfig interface with required address field
- add load-time validation for Amplifier Protocol contracts
- add new getter methods
- replace awkward validateRequired pattern
@AttissNgo AttissNgo requested a review from a team as a code owner December 19, 2025 22:50
Comment thread common/config.ts
this.chains = fullConfig.chains;

this.validateConfig();
this.validateAmplifierProtocolContracts();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should be part of the validateConfig. Note that currently we print warnings instead of errors, since axelarate devnet setup workflow does not produce a full valid config. The validation methods gathers all the errors and then produce a report instead

Comment thread common/config.ts
printWarn('');
}

private validateAmplifierProtocolContracts(): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, this method should be used as a part of validateConfig. It should return errors that are relevant to its validation checks

Comment thread common/config.ts
}

public getContractAddress(name: string): string {
const config = this.getContractConfig(name);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const config = this.getContractConfig(name);
const config = this.getInstantiatedContractConfig(name);

To be really certain about the address presence

Comment thread cosmwasm/utils.js
const itsMsgTranslator =
chainParams?.msgTranslator ||
config.validateRequired(config.getContractConfig('ItsAbiTranslator').address, 'ItsAbiTranslator.address');
const itsMsgTranslator = chainParams?.msgTranslator || config.getInstantiatedContractConfig('ItsAbiTranslator').address;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const itsMsgTranslator = chainParams?.msgTranslator || config.getInstantiatedContractConfig('ItsAbiTranslator').address;
const itsMsgTranslator = chainParams?.msgTranslator || config.getContractAddress('ItsAbiTranslator');

Comment thread cosmwasm/contract.ts
}

const contractAddress = config.validateRequired(config.getContractConfig(contractName).address, `${contractName}.address`);
const contractAddress = config.getInstantiatedContractConfig(contractName).address;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const contractAddress = config.getInstantiatedContractConfig(contractName).address;
const contractAddress = config.getContractAddress(contractName);

Comment thread common/config.ts
const chainCodec = this.getChainCodecContractForChainType(chainType);
const chainCodecConfig = this.getContractConfig(chainCodec);
return this.validateRequired(chainCodecConfig.address, `${chainCodec}.address`);
return this.getInstantiatedContractConfig(chainCodec).address;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return this.getInstantiatedContractConfig(chainCodec).address;
return this.getContractAddress(chainCodec);

Comment thread cosmwasm/migrate/sdk50.ts
Comment on lines +82 to +83
const contractName = config.getVotingVerifierContractForChainType(chainConfig.chainType);
const address = config.getInstantiatedContractByChain(contractName, chainName).address;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This change complicates that part, maybe leave the way it was

Comment thread common/config.ts
Comment on lines +456 to +458
if (!config.address) {
throw new Error(`Contract '${name}' has not been instantiated`);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the existing validation method, also used in this file

Comment thread common/config.ts
Comment on lines +464 to +466
if (!config.address) {
throw new Error(`Contract '${name}' for chain '${chainName}' has not been instantiated`);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the existing validation method, also used in this file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants