Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add puzzles, driver and lifecycle tests for revocable CATs #19000

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
; This is a "limitations_program" for use with cat.clsp.
; It allows an issuer vault to mint and a melter vault to melt this CAT.
(mod (
SINGLETON_MOD_HASH
LAUNCHER_PUZZLE_HASH
ISSUER_LAUNCHER_ID
MELTER_LAUNCHER_ID
NONCE
Truths
parent_is_cat
lineage_proof
delta
inner_conditions
( ; solution
singleton_inner_puzzle_hash
)
)

(include condition_codes.clib)
(include curry-and-treehash.clib)

(defun-inline calculate_full_puzzle_hash (SINGLETON_STRUCT inner_puzzle_hash)
(puzzle-hash-of-curried-function (f SINGLETON_STRUCT)
inner_puzzle_hash
(sha256tree SINGLETON_STRUCT)
)
)

(defun-inline authorize_via_singleton (SINGLETON_STRUCT singleton_inner_puzzle_hash delta)
(list
(list RECEIVE_MESSAGE 23 delta (calculate_full_puzzle_hash SINGLETON_STRUCT singleton_inner_puzzle_hash))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave a comment about what bits these are and what that means

)
)

(defun-inline singleton_struct_for_delta (ISSUER_LAUNCHER_ID MELTER_LAUNCHER_ID delta)
(if (> 0 delta)
(c SINGLETON_MOD_HASH (c MELTER_LAUNCHER_ID LAUNCHER_PUZZLE_HASH)) ; delta is negative, so we melt
(c SINGLETON_MOD_HASH (c ISSUER_LAUNCHER_ID LAUNCHER_PUZZLE_HASH)) ; delta is positive or 0, so we mint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure you should swap this with a parent_is_cat check. I think (though I have not fully thought it through), that a melting authority could play games here where it issues a CAT and then immediately melts some of it. That initial issuance doesn't count as a positive delta and therefore you would be able to have a negative delta even though more total CAT exists on the blockchain. I don't think you need to acommodate positive deltas, that kind of minting is kind of silly.

)
)

(authorize_via_singleton (singleton_struct_for_delta ISSUER_LAUNCHER_ID MELTER_LAUNCHER_ID delta) singleton_inner_puzzle_hash delta)
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(mod (
SINGLETON_MOD_HASH
SINGLETON_STRUCT_HASH ; The hash of (SINGLETON_MOD_HASH . (LAUNCHER_ID . SINGLETON_LAUNCHER_HASH))
NONCE
singleton_inner_puzzle_hash
delegated_puzzle
delegated_solution
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ff02ffff01ff04ffff04ff08ffff04ffff0117ffff04ffff02ff0effff04ff02ffff04ff2fff80808080ffff04ffff0bff2affff0bff0cffff0bff0cff32ff0580ffff0bff0cffff0bff3affff0bff0cffff0bff0cff32ff0b80ffff0bff0cffff0bff3affff0bff0cffff0bff0cff32ff1780ffff0bff0cff32ff22808080ff22808080ff22808080ff8080808080ffff02ff2fff5f8080ffff04ffff01ffff4302ffffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c5ff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff0effff04ff02ffff04ff09ff80808080ffff02ff0effff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff018080
ff02ffff01ff04ffff04ff08ffff04ffff0117ffff04ffff02ff0effff04ff02ffff04ff5fff80808080ffff04ffff0bff2affff0bff0cffff0bff0cff32ff0580ffff0bff0cffff0bff3affff0bff0cffff0bff0cff32ff0b80ffff0bff0cffff0bff3affff0bff0cffff0bff0cff32ff2f80ffff0bff0cff32ff22808080ff22808080ff22808080ff8080808080ffff02ff5fff81bf8080ffff04ffff01ffff4302ffffffa04bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459aa09dcf97a184f32623d11a73124ceb99a5709b083721e878a16d78f596718ba7b2ffa102a12871fee210fb8619291eaea194581cbd2531e4b23759d225f6806923f63222a102a8d5dd63fba471ebcb1f3e8f7c1e1879b7152a6e7298a91ce119a63400ade7c5ff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff0effff04ff02ffff04ff09ff80808080ffff02ff0effff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff018080
8 changes: 6 additions & 2 deletions chia/wallet/revocable_cats/revocable_cats_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@


# Basic drivers
def construct_p2_delegated_by_singleton(issuer_launcher_id: bytes32) -> Program:
def construct_p2_delegated_by_singleton(
issuer_launcher_id: bytes32, nonce=0
) -> Program:
singleton_struct: Program = Program.to(
(
SINGLETON_TOP_LAYER_MOD_HASH,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's important in these drivers to have optional ways to override these values. Sometimes, in tests, I like to use a "mock" singleton puzzle, and these drivers wouldn't work for that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes for similar functions below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, although as you said, I don't think that driver will be merged into chia-blockchain anytime soon.
Would add that in case we do want to use it here.

(issuer_launcher_id, SINGLETON_LAUNCHER_PUZZLE_HASH),
)
)
return P2_DELEGATED_BY_SINGLETON.curry(
SINGLETON_TOP_LAYER_MOD_HASH, singleton_struct.get_tree_hash()
SINGLETON_TOP_LAYER_MOD_HASH,
singleton_struct.get_tree_hash(),
Program.to(nonce),
)


Expand Down
Loading