Do network files <network>.json in upgradeable contracts skip an "impl" if the code is the same of a previous version?

I just deployed my first upgradeable contract. To make sure it was actually upgradeable, I simply modified how a value was stored in one of the functions. For example, instead of x = input, I simply changed it to x = input*2. It worked out perfectly. When I looked into the .json (ropsten.json in my case), it showed 2 different "contracts" in the "impl" property of the json object. This is perfect as well.

However, I changed back my function to its original state since I had already made sure the upgrade feature works, and I deployed again my modified contract (which is the actual original version). So, I was expecting to see 3 different "contracts" in the "impl" property of the json object since I have deployed 3 times my contract, but there is only 2 of them. So, my question is, does the openzeppelin library know that my final code is the same as a previous version, and that is why there is no third "contract" created in the "impl" property in the json object? Or this is an unexpected situation and there is something wrong with my code/implementation?

I just need to really understand what happens under the hood, otherwise I feel I'm not getting it right. Thanks a lot.

:1234: Code to reproduce


:computer: Environment

Never mind. I guess the key of the child property in "impl" is the hash of the code. I checked the transactions in etherscan and they show I am interacting in the last txs with the contract I deployed first, which means the proxy didn't redeploy the last contract since it was the same as the first one, and simply started pointing to the first contract and updated some variables. So, I guess the way openzeppelin knows I am trying to deploy a contract that already exists in the blockchain is by the hash in the json file.

Yes, it's exactly as you described.

1 Like