Skip to content

Accumulator MultiSig

Threshold multisig with selectable participants.

This example uses alt stack operations inside if/else blocks. Compile it with --asa or --allow-subscope-altstack.

txt
# Three public-key slots are available, and `masks` selects which slots join this spend.
Contract AccumulatorMultiSig:

    def main(sigs: hex[3], pubKeys: hex[3], masks: bool[3]):

        # Keep a running total off the main stack while each selected slot is checked.
        total = Push(0)
        SetAlt(total)
        for i in Range(2, -1, -1):
            if masks[i] == 1:
                SetMain(total)
                if And(Equal(Hash160(pubKeys[i].Clone()), self.addr[i]), CheckSig(sigs[i], pubKeys[i])):
                    total = total + 1
                    SetAlt(total)
                else:
                    total = total + 0
                    SetAlt(total)
            else:
                Delete(pubKeys[i])
                Delete(sigs[i])

        # The final count must meet the configured threshold.
        SetMain(total)
        NumEqualVerify(GreaterOrEqual(total, self.threshold), 1)