Skip to content

Multi-Party Hash Puzzle Opt

Combined-hash puzzle optimization.

txt
# Ten preimages are folded into one rolling digest instead of checked one by one.
Contract MultiPartyHashPuzzleOpt:

    def unlock(preimages: hex[10]):
        # Each step binds the next preimage to everything already seen.
        combinedHash = Push(0)
        SetAlt(combinedHash)

        for i in Range(9, -1, -1):
            SetMain(combinedHash)
            combinedHash = Sha256(Cat(combinedHash, preimages[i]))
            SetAlt(combinedHash)

        # Only the final digest is compared with the stored commitment.
        SetMain(combinedHash)
        EqualVerify(combinedHash, self.combinedHash)