0

I am trying to update the code of a smart contract using the chain-extension functionality instead of using the ink_env::set_code_hash method. The contract pallet successfully emits the ContractCodeUpdated event with the expected values. Still, after the execution of the contract, the state changes are not persisted and the contract continues to use its original code hash (though changes made in the contract's own storage persists).

The sample code can be found here (https://github.com/realnimish/contract-upgrade-test).

Reproduction steps

  1. Create a chain extension that takes an input - (Contract Address, New Code Hash) and calls the Contracts::set_code extrinsic and returns the result. impl-chain-ext
  2. Create an ink! contract (C1) which interacts with the chain-extension and deploy it. impl-C1
  3. Create another ink! contract (C2) which can call C1 to update its code and deploy it. impl-C2
  4. Create an ink! contract (C3) to which C2 should update to and upload it. impl-C3
  5. Call the C2 contract method which calls C1 and updates itself to C3 code. impl-unit-test

Expected Outcome: Contract C2 now has the code_hash of C3
Actual Outcome: Contract C2's code_hash doesn't change after the execution even though Contract pallet emits that the contract code has been updated and the smart contract call doesn't fail.

1 Answer 1

1

Two things would be helpful for giving a specific answer:

  • Can you update your reproducer code to ink! 4.0? We have a migration guide here. There were some fixes along the way and I just want to ensure that the errors still appears.
  • Can you reduce the reproduction steps to what is strictly necessary? E.g. I don't understand how the unit test from step 5 is relevant. Instead of the names C1 & co, please use the contract names. What would be best is an ordered list of contract messages that you executed and the parameters you used.

As I understand you, calling SetCode::replace_code directly works. The code for the chain extension also looks fine.

I suspect it's an issue with your cross-contract calling code. It's hard to tell specifically where, but if you edit the question with what I wrote above we can pinpoint it further.

1
  • Thanks for the response! I'll ping you here when the updated version is ready Mar 28, 2023 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.