TON multisig v2

How TON multisig v2 works

multisig-contract-v2 is the official multisig of TON, written by the TON Core team, and the only contract Tonkey uses. This page follows its source: what happens between creating an order and carrying it out, and why an order can fail.

Two contracts: the multisig and its orders

The multisig is the contract that holds the assets. It stores the signers, the threshold, the proposers and the number of the next order. Its logic cannot change after it is deployed: there is no upgrade and no admin key.

Each order is a contract of its own. Its address is computed from the multisig’s address and the order’s number, so every order can be found from its multisig. The order holds what it will do, when it expires and which signers have approved it.

The source is open at ton-blockchain/multisig-contract-v2 and was audited by Zellic and Trail of Bits. The code hashes Tonkey checks every multisig against are on the security page.

The life of an order

  1. A signer or a proposer sends a new order to the multisig: its actions, an expiration date and enough GRAM to create and store the order.
  2. The multisig checks the sender and the order number, then deploys the order contract. When the creator is a signer, creating the order counts as their approval.
  3. The other signers each send an approval to the order contract from their own wallet.
  4. When the approvals reach the threshold, the order asks the multisig to execute it and sends along its whole balance.
  5. The multisig checks that the request comes from that order, that its signers and threshold still allow it and that it has not expired. Then it carries out each action: a message to send, or a change of its own settings.

Nobody has to press a last button: the approval that reaches the threshold sets off the execution.

What the contract checks, and the errors you may see

Creating an order. Only an address on the signers or proposers list can create one (exit code 1007). The order number must be the next one (1008), the expiration must be in the future (111), and the GRAM attached must cover the order (100).

Approving. Only a signer can approve (106), only once (107), and not after the order has been sent for execution (112). A signer approves with an approve message, or with a plain text comment that says approve.

Executing. The multisig accepts the request only from the order’s own address (101), only while its signers are the order’s signers and its threshold is not above the order’s approvals (102), and only before the expiration (111).

A failed execution does not reset the order: it has been sent for execution and can never run again. That is why Tonkey reads an order’s outcome from its execute transaction, never from the approvals alone.

Changing signers or the threshold

A change of settings is an order too: an action that sets the new threshold, signers and proposers. Like any order, it needs the current threshold.

Pending orders are not told about the change. They keep accepting approvals, but their execution fails with 102 if the signers changed or the threshold was raised above their own. Lowering the threshold alone leaves them valid. After a change, create again the orders you still need.

An expired order also keeps accepting approvals and then fails with 111. Tonkey does not let you approve an expired order, and marks the orders that new settings have made invalid.

What Tonkey adds

The contract does not limit what an order can do, and its authors ask every interface to show all of it. Tonkey decodes every field that moves value (send mode, attached GRAM, jetton and NFT transfers, forward amounts, response addresses), flags actions it cannot decode and simulates the order before you sign.

Tonkey compares the code of every multisig it opens with the official build, and warns about a pre-release, pre-audit or unofficial one.

Upstream, a new multisig numbers its orders from 0, so two multisigs with the same signers, threshold and proposers would land on the same address. Tonkey starts each new multisig at a random order number, so they never collide.

Because the contract is the standard one, a multisig never depends on Tonkey: any tool that supports multisig-contract-v2 can create and approve its orders.

TON multisig v2 questions

Can a multisig be upgraded to a newer contract?

No. The logic of a multisig v2 cannot change once it is deployed. To move to another contract, deploy a new multisig and send the assets to it with an order.

Can a signer approve without Tonkey?

Yes. From their own wallet, a signer can send the order’s address a message with the text comment approve and a little GRAM for fees. The contract takes it like any other approval. Read the order first: an approval cannot be taken back.

Can another multisig be a signer?

Yes. A signer can be any address: a wallet, a hardware wallet, another multisig or another contract. A multisig that is a signer approves through an order of its own.

Where are a multisig’s orders kept?

Each order is its own contract, at an address computed from the multisig’s address and the order number. The multisig itself only keeps the number of its next order.

Put your treasury under shared control

Create a multisig in a few minutes. You only need a TON wallet and the addresses of your co-signers.