Will changing the state mutability of any function in solidity will change the interface id as per erc165

13 views Asked by At

Whether changing the state mutability of a function in Solidity will change the interface ID as per ERC165?

1

There are 1 answers

0
gaurav On

Whether changing the state mutability of a function in Solidity will change the interface ID as per ERC165 depends on the specific function and its relationship to the interface.

Generally, changing the state mutability of a function will not affect its interface ID. This is because the interface ID is primarily determined by the function's signature, which includes its name and parameters, but not its state mutability.

However, there are some cases where changing state mutability could indirectly impact the interface ID:

  • If the function is part of an existing interface: Changing its state mutability could potentially break compatibility with implementations of that interface that rely on the original state mutability behavior. This could lead to unexpected behavior or even errors when interacting with those implementations. In such cases, it's best to create a new interface with the desired state mutability instead of modifying the existing one.
  • If the function overrides another function: Changing its state mutability might violate the overriding contract's expectations, leading to potential issues.

Here's a breakdown:

No change to interface ID:

  • Changing a function from non-state-changing to state-changing within the same contract.
  • Changing a function from non-state-changing to state-changing within a subclass, as long as the overridden function is also non-state-changing.

Potential change to interface ID:

  • Changing a function from state-changing to non-state-changing within the same contract.
  • Changing a function from state-changing to non-state-changing within a subclass, if the overridden function is state-changing.
  • Changing a function's state mutability when it's part of an existing interface.

Important takeaway:

While changing state mutability generally doesn't affect interface IDs, it's important to consider potential impacts on compatibility with existing implementations and the consistency of your contract's design. For clarity and maintainability, it's often advisable to create new interfaces instead of modifying existing ones when changing function state mutability.