A smart contract which allows upgrading the smart contract of a dApp UTXO via gathering signatures.
The code on this repository has not been audited. We don't recommend it using in production without a full security audit. Use it at your own risk!.
This contract enables updating the treasury UTXO to a new smart contract if enough signatures are collected.
Protocol steps:
-
Prerequisites:
- The contract to be migrated must include the migration code and be parametrized with the treasury token.
- The treasury must be parametrized with the authorized public signatures and the required minimum numer of them.
-
Build the new migration datum with:
- the current contract validator hash
- the validator hash of the contract to migrate to
- the new datum hash
- the value to move to the new contract (should be the value in the current contract)
-
Gather signatures
- Approved signers must sign the migration datum hash (from step 1)
-
Migrate the contract
- To allow migration, the origin contract requires the treasury token to be spent and pay to the treasury on the same transaction
- The treasury will allow spending the treasury token if the origin script, the target script, the new datum at the target script, and the value at the target script matches the signed datum hash.
To build the project execute cabal build
at the project root.
To build:
$ nix-shell
...
$ cabal build
...
To run use-case test execute the following commands at the project root.
$ cabal test
$ cabal test
Build profile: -w ghc-8.10.4.20210212 -O1
In order, the following will be built (use -v for more details):
- contract-upgrade-0.1.0.0 (test:contract-upgrade-test) (first run)
Preprocessing test suite 'contract-upgrade-test' for contract-upgrade-0.1.0.0..
Building test suite 'contract-upgrade-test' for contract-upgrade-0.1.0.0..
Running 1 test suites...
Test suite contract-upgrade-test: RUNNING...
use cases
Simple endpoint tests
Expose endpoints: OK
Normal contract use
Collect prize: OK (0.08s)
Try prize with invalid response: OK (0.04s)
Migrate contract: OK (0.11s)
All 4 tests passed (0.24s)
Test suite contract-upgrade-test: PASS
1 of 1 test suites (1 of 1 test cases) passed.