The PR aims to prevent bugs and issues created by breaking changes between an old contact and a new one.
If the contract already has clients that use him, changing the ABI of the contract (e.g., while upgrading) can lead to some critical bugs.
Even if we deploy a new version of our contract, we need to be sure that nothing will break in our frontend, backend, or other third-party consumers. If some stuff changes, it would be beneficial to have an auto-generated report that we could give to the relevant consumers.
Breaking changes according to this PR:
Removal of a previously deployed function that had 'public'/'external' visibility
Change a previously deployed function that had 'public'/'external' visibility to 'internal'/'private' visibility.
Changing a previously deployed function's signature (name, order of arguments, or arguments types), which also changes its selector
Changing previously deployed function state mutability
Changing/removing a previously event selector
Changing/removing a previously custom error selector
We solved this issue by adding a script that checks if there are breaking changes between the old ABI and the new ABI.
This script runs before each deployment and validates that there are no breaking changes between the deployed contracts and the new ones.
By default, if there are some breaking changes, the deployment would fail.
If you still want to deploy the contracts, you need to add the flag "allowBreakingAbiCompatbility".
If you have an artifact whose name is not the same as the contract name, you should add a JSON string with this data to the replace param. e.g.
hardhat deploy --replace '{"contractName": "artifactName"}'
It's also possible to export all the breaking changes to JSON files.
Also, there is a new task: 'validate-abi-compat'. In this task, you can check the ABI compatibility for a specific contract or all of them.
Possible Enhancements
Separate between breaking changes and low-priority changes
The PR aims to prevent bugs and issues created by breaking changes between an old contact and a new one. If the contract already has clients that use him, changing the ABI of the contract (e.g., while upgrading) can lead to some critical bugs. Even if we deploy a new version of our contract, we need to be sure that nothing will break in our frontend, backend, or other third-party consumers. If some stuff changes, it would be beneficial to have an auto-generated report that we could give to the relevant consumers.
Breaking changes according to this PR:
We solved this issue by adding a script that checks if there are breaking changes between the old ABI and the new ABI. This script runs before each deployment and validates that there are no breaking changes between the deployed contracts and the new ones. By default, if there are some breaking changes, the deployment would fail. If you still want to deploy the contracts, you need to add the flag "allowBreakingAbiCompatbility". If you have an artifact whose name is not the same as the contract name, you should add a JSON string with this data to the replace param. e.g.
hardhat deploy --replace '{"contractName": "artifactName"}'
It's also possible to export all the breaking changes to JSON files.Also, there is a new task: 'validate-abi-compat'. In this task, you can check the ABI compatibility for a specific contract or all of them.
Possible Enhancements
This PR was created with @fullkomnun help 🙏