Skip to content

ton-blockchain/multisig-contract

 
 

Repository files navigation

TON Multisig

Standard TON Multisig wallet smart contract and correpsponding Fift interaction scripts.

Brief description of multisig wallet

(n, k)-multisig wallet is a multisignature wallet with n private keys holders, which accepts requests to send messages if the request (aka order, query) collects at least k signatures of the holders. An order can have up to three unique messages to send in a single transaction. In contrast to some other blockchains, a holder doesn't need to have own wallet. It is possible to control the multisig using only the keys, while the fee is paid from multisig's own funds. Also multisig supports onchain voting for orders. Namely, if an order sent to multisig has at least one correct signature but less than k, then it is saved to contract data to allow collecting missing signatures later. Also any order may have a time limit, after which it is expired.

Risks using multisig wallet

⚠️ Please note that it is not recommended to have more than ~100 non-expired orders simultaneously, because it can lead to out of gas credit exception. An order is considered non-expired from the moment it transefered to the contract to the expiration time (such orders' ids are saved in the contract data to enforce reply-protection).

Compilation

Compile the contract with func -SPA stdlib.fc multisig-code.fc -o multisig-code.fif.

Scripts

Suppose you have set FIFTPATH variabale to fift library directory. Then you can run the scripts with command fift -s <script-name> <args>. When no args are specified, a script displays short help message with info of its usage.

  1. You can generate one or several keys with new-key.fif script manually, or generate a batch or keys with generate-keypairs.fif.
  2. Having a text file with list of serialized public keys (in "user-friendly" format) you can create an init message for a new mulstisig wallet with new-mulstisig.fif script.
  3. After the contract is activated, you may want to create one or several internal messages to send with create-msg.fif script.
  4. Having message(s) to send you can group it to a new order with create-order.fif script.
  5. You can add a signature to the order with add-signature.fif script, provided you have corresponding private key. Note that the index of the key is the number of line in public keys text file at which it is presented (numbering from 0).
  6. Having two orders with the same messages to send, but (potentially) different signatures lists, you can unite the lists with union-signatures.fif script.
  7. When you want to send the order to the contract, you should create the external message with create-external-message.fif script. Note that it requires a private key to ensure authenticity ot the signatures list. Your signature will also be counted as a vote for the order.
  8. Send the message and enjoy your order being processed.

Also you can clear signatures list with clear-signatures.fif and show indexes of parties signed the order with show-signed-by.fif. show-msg.fif and show-order.fif can be used for displaying messages and orders in human-readable format.

Dev History

  1. Originally written by the Telegram team and located in TON monorepo at https://github.com/ton-blockchain/ton/blob/master/crypto/smartcont/multisig-code.fc.

  2. The commit 3aa7f3f6091690c472903021ecbae348875ad6cd of the master branch of this repo is identical to the last multisig change in the TON monorepo (master branch, commit 9f351fc29f7a0e8937897a873f62fc35418fdcb1 (24.03.2020)).

  3. @akifoq wrote Fift scripts

  4. @akifoq fixed a minor bug in a get_messages_unsigned, get_messages_unsigned_by_id get-method (doesn't affect onchain behaviour).

  5. @akifoq added additional check for proposed query to prevent infinite repeating of correctly signed by majority of holders, but otherwise incorrect (due to a bug in offchain interface, for instance) order, which could lead to loosing unlimited amount of funds to blockchain fees.

About

Standard multisignature wallet smart contract

Resources

Stars

Watchers

Forks

Releases

No releases published