Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Building the Multisig Program

Pre-alpha. The devnet pre-alpha is a mock network with no MPC. Read the warning in the introduction first.

What You’ll Learn

  • How to design a multisig with fixed members and threshold approval, bound to one dWallet
  • How to store transaction data on-chain for other signers to inspect
  • How to implement both approval and rejection flows
  • How to issue a future signature voucher, owned by the proposer, for a transaction proposed as a future sign

Architecture

dWallet owner ──► CreateMultisig (members, threshold) ──► Multisig PDA ["multisig", dwallet]
                  ──► transfer ownership to CPI PDA
                │
Member 1 ──► CreateTransaction (message data stored on-chain)
                │
Member 1 ──► Approve ──┐
Member 2 ──► Approve ──┼──► threshold reached? ──► dwallet == multisig.dwallet? ──► future_sign == 0? ──► issue_signature_voucher CPI
Member 3 ──► Reject  ──┘                                                            future_sign == 1? ──► issue_future_signature_voucher CPI
                                                                                                                      │
                                                                                                             Transaction = Approved

1. Account Layouts

Multisig PDA (["multisig", dwallet]) — 363 bytes

FieldOffsetSizeType
disc01always 1
version11always 1
dwallet232pubkey — the dWallet this multisig governs
threshold342u16 LE
member_count362u16 LE
tx_index384u32 LE (auto-increment)
bump421canonical PDA bump
members4332010 × 32-byte pubkeys

Transaction PDA (["transaction", multisig, tx_index_le]) — 402 bytes

FieldOffsetSizeType
disc01always 2
version11always 1
multisig232pubkey
tx_index344u32 LE
proposer3832pubkey
message_hash7032keccak256
user_pubkey10232key allowed to call gRPC Sign
signature_scheme1342u16 LE (DWalletSignatureScheme)
approval_count1362u16 LE
rejection_count1382u16 LE
status14010=Active, 1=Approved, 2=Rejected
signature_voucher_bump1411u8 (bump of the voucher PDA ["signature_voucher", transaction])
future_sign14210 = issue a signature voucher, 1 = issue a future signature voucher
bump1431PDA bump
message_data_len1442u16 LE
message_data146256raw bytes

ApprovalRecord PDA (["approval", transaction, member]) — 68 bytes

Prevents double voting. One per member per transaction.

2. Instructions

DiscNameDescription
0CreateMultisigThe dWallet’s current owner sets members (up to 10) and threshold for that dWallet
1CreateTransactionA member proposes with message data stored on-chain
2ApproveVote yes; triggers CPI at threshold
3RejectVote no; marks rejected when impossible to approve

CreateMultisig takes the dWallet account and the dWallet program: the dWallet program account must be the ika program (ID of the CPI crate) and executable, the dWallet account must be owned by it, carry the DWallet discriminator (97), and its stored owner (offset 2) must be the signer. The multisig is created at the canonical ["multisig", dwallet] PDA, so there is exactly one per dWallet and it can only be created while the dWallet is still controlled by its user — once the owner is the CPI PDA nobody can sign for it.

3. Rejection Threshold

A transaction is rejected when enough members reject that approval becomes impossible:

rejection_threshold = member_count - threshold + 1

Example: 2-of-3 multisig → 3 - 2 + 1 = 2 rejections needed.

4. CPI Flow on Approval

When approval_count >= threshold:

#![allow(unused)]
fn main() {
// 0. Bind the CPI target — before any CPI. The CPI authority PDA is shared by
//    every dWallet this program controls, so only the multisig's own dWallet
//    may get a voucher.
if dwallet.address().as_array() != &multisig_dwallet {
    return Err(MultisigError::DWalletMismatch.into());
}

// 1. Issue the voucher. It is this program's PDA for the transaction, so the
//    program signs its creation with the PDA's seeds.
let voucher_bump_byte = [signature_voucher_bump];
let voucher_seeds = [
    Seed::from(b"signature_voucher" as &[u8]),
    Seed::from(tx_account.address().as_array().as_ref()),
    Seed::from(voucher_bump_byte.as_ref()),
];
if future_sign {
    // A future signature voucher, owned by the proposer. The proposer later
    // sets the key that completes the future sign.
    ctx.issue_future_signature_voucher(
        coordinator, signature_voucher, dwallet, payer, system_program,
        message_hash, [0u8; 32] /* no metadata */, signature_scheme,
        Some(proposer_key) /* owner */,
        Some(user_pubkey) /* signing key */,
        Some(&voucher_seeds),
    )?;
} else {
    ctx.issue_signature_voucher(
        coordinator, signature_voucher, dwallet, payer, system_program,
        message_hash, [0u8; 32] /* no metadata */, signature_scheme,
        None /* owner: this program's CPI authority */,
        Some(user_pubkey) /* signing key */,
        Some(&voucher_seeds),
    )?;
}

// 2. Mark transaction as approved
tx_data[TX_STATUS] = STATUS_APPROVED;
}

CreateTransaction takes the future_sign flag as one byte after signature_voucher_bump. Only 0 and 1 are accepted; any other value fails with InvalidInstructionData.

The Anchor variant expresses the same binding as a constraint: #[account(address = multisig.dwallet)] on dwallet. Its future_sign field is a bool.

Source Code

FrameworkPath
Pinocchioexamples/multisig/pinocchio/src/lib.rs
Nativeexamples/multisig/native/src/lib.rs
Anchorexamples/multisig/anchor/src/lib.rs