Securing spend with announcements - overview

From mojo_puzzler
Jump to navigation Jump to search

Return to: Insightful_Comments

1.

Dan Perry on Keybase 20211220 10:59pm EST

The parameters you pass into the puzzle ("defconstant" and "TARGET_AMOUNT" in your example) are the puzzle's solution. If you curry one of these parameters, you are hard-coding it into the solution, and therefore into the puzzle as well.

You won't always know what all of these values will be at the time of the coin's creation, so currying them isn't always an option. Any part of the solution that has not been curried has to be supplied when the coin is spent. (In order to spend a coin, you must provide the original puzzle, a valid solution, and usually a signature)

While a farmer cannot change the puzzle (because doing so would change the puzzlehash), a farmer can attempt to change any of the non-curried values in the solution. You should make sure that if those values do get changed, the spend will fail. The way you do this is with announcements, which are covered in the chialisp docs: https://chialisp.com/docs/coins_spends_and_wallets

This video shows you how to use announcements to secure your coins: https://www.youtube.com/watch?v=_SBGfMZhRd8

2.

gneale notes 20211221

Technique for securing multiple coin spends with announcements commonly uses creating puzzlehash announcement while assert a coin announcement.

See: https://github.com/geoffwalmsley/CreatorNFT/blob/912ce88d75f89357141260aad2dd1626038f7d60/clsp/creator_nft.clsp#L64

	       (list CREATE_PUZZLE_ANNOUNCEMENT payment_info) ;; Announce the p2 coin id
(list ASSERT_COIN_ANNOUNCEMENT (sha256 payment_info (sha256tree new_state))) ;; Assert the p2_coin spend

See also: https://github.com/xch-gallery/nft-companion/blob/3ec7748f3cd6834ea97fd46fde6d119f30ab566b/ownable_singleton/clsp/ownable_singleton.clsp#L27

         (list CREATE_PUZZLE_ANNOUNCEMENT payment_id) ; Inform the payment coin of this spend
         (list ASSERT_COIN_ANNOUNCEMENT (sha256 payment_id new_owner_pubkey)) ; Assert that the payment coin is being spent and validate the owner