[go: up one dir, main page]

Protocol: patch legacy scripts during migration.

Context

A step towards resolving: #2143 (closed).

As part of our effort to refactor the interpreter and repay its technical debt, we want to disable and eventually remove the legacy flag currently required to execute some older contracts. In order to not break them down, however, we have to patch them so that they're compatible with modern versions of the interpreter. This MR proposes to do this during protocol migration.

A full list of hashes of scripts that cannot currently be originated (because they don't typecheck without legacy flag) is can be found here. Code for each of these contracts can be foud here. Code for patched contracts can be found in src/proto_alpha/lib_protocol/test/integration/michelson/patched_contracts.

The list of scripts that don't currently typecheck was created as follows: I updated the onchain/mainnet contract collection in our smart-contracts repository. Then I iterated over all those contracts running tezos-client typecheck script for each. I collected those that failed to typecheck and ignored the rest. I deliberately ignored lambdas, as they're not using the legacy flag anyway.

Obviously, after applying the patch the semantics of each contract should remain unchanged.

Manually testing the MR

Run dune exec tezt/vesting_contract_test/main.exe to run the automated tests of the patched vesting contract.

I have replayed all historic transactions to acounts whose scripts have been changed using this script. To do this, first you need to merge !3873 (merged) into a local branch stemming from this one. --self-address option is required for the script to operate. Then compile the code, start a node and perform the migration if you haven't already. Run the node with --connections 0 to isolate yourself from the real network. Also make sure that the node listens to RPC calls.

Export an environment variable TEZOS_CLIENT=/path/to/tezos-client if tezos-client is not in your $PATH.

Then for each account from the list given by patched-accounts.txt (the ones whose scripts have been patched) run:

$ python replay-transaction.py <address> -cq --script-from-node

This will print a table containing the result of each transaction. --script-from-node option tells the script to fetch the code from the node (where it is already patched by the migration you performed earlier) instead of downloading it from the indexer (which is default behaviour). You can omit this option to compare with results obtained with the original code.

NOTE: KT1MzfYSbq18fYr4f44aQRoZBQN72BAtiz5j has been patched once already during migration to Babylon so that transactions prior to block 655360 will fail with the patched contract. This is expected, so add --filter 'lambda op: int(op["level"]) > 655360' option to the script call for that account.

NOTE: KT1XTXBsEauzcv3uPvVXW92mVqrx99UGsb9T, KT1Puc9St8wdNoGtLiD2WXaHbWU7styaxYhD, KT19c8n5mWrqpxMcR3J687yssHxotj88nGhZ, KT1DrJV8vhkdLEj76h1H9Q4irZDqAkMPo1Qf and KT1CT7S2b9hXNRxRrEcany9sak1qe4aaFAZJ are instances of the Dexter contract, which relies on a bigmap to operate. The contract storage only contains the identifier of the bigmap, so it's currently impossible run the script with the original contents of the bigmap from that time. For this reason some transactions to these contracts will also fail (or succeed where failure was expected, which is also reported as a failure in the summary printed by the script).

Checklist

  • Provide automatic testing (see the testing guide).
  • Select suitable reviewers using the Reviewers field below.
  • Select as Assignee the next person who should take action on that MR
Edited by Mehdi Bouaziz

Merge request reports

Loading