Skip to content

Commit

Permalink
support standard, CAT and DID spends in run-spend tool
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Feb 11, 2024
1 parent 8cb9ad6 commit b120b0f
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 13 deletions.
73 changes: 71 additions & 2 deletions chia-tools/src/bin/run-spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use clvm_utils::CurriedProgram;
use clvmr::{allocator::NodePtr, Allocator};

use chia_wallet::singleton::{SINGLETON_TOP_LAYER_PUZZLE_HASH, SingletonArgs, SingletonSolution};
use chia_wallet::standard::{STANDARD_PUZZLE_HASH, StandardArgs, StandardSolution};
use chia_wallet::cat::{CAT_PUZZLE_HASH, CatArgs, CatSolution};
use chia_wallet::did::{DID_INNER_PUZZLE_HASH, DidArgs, DidSolution};
use chia_wallet::Proof;

/// Run a puzzle given a solution and print the resulting conditions
Expand Down Expand Up @@ -127,12 +130,77 @@ fn print_puzzle_info(a: &Allocator, puzzle: NodePtr, solution: NodePtr) {
};

match tree_hash(a, uncurried.program) {
STANDARD_PUZZLE_HASH => {
println!("p2_delegated_puzzle_or_hidden_puzzle.clsp");
let Ok(uncurried) =
CurriedProgram::<NodePtr, StandardArgs>::from_clvm(a, puzzle)
else {
println!("-- failed to uncurry standard transaction");
return;
};
println!(" synthetic-key: {:?}", uncurried.args.synthetic_key);
let Ok(sol) = StandardSolution::<NodePtr, NodePtr>::from_clvm(a, solution) else {
println!("-- failed to parse solution");
return;
};
println!(" solution");
println!(" original-public-key: {:?}", sol.original_public_key);
println!("\nDelegated Puzzle\n");
print_puzzle_info(a, sol.delegated_puzzle, sol.solution);
}
CAT_PUZZLE_HASH => {
println!("cat_v2.clsp");
let Ok(uncurried) =
CurriedProgram::<NodePtr, CatArgs<NodePtr>>::from_clvm(a, puzzle)
else {
println!("-- failed to uncurry CAT transaction");
return;
};
println!(" mod-hash: {:?}", uncurried.args.mod_hash);
println!(" tail-program-hash: {:?}", uncurried.args.tail_program_hash);
let Ok(sol) = CatSolution::<NodePtr>::from_clvm(a, solution) else {
println!("-- failed to parse solution");
return;
};

println!(" solution");
println!(" lineage-proof: {:?}", sol.lineage_proof);
println!(" prev-coin-id: {:?}", sol.prev_coin_id);
println!(" this-coin-info: {:?}", sol.this_coin_info);
println!(" next-coin-proof: {:?}", sol.next_coin_proof);
println!(" prev-subtotal: {:?}", sol.prev_subtotal);
println!(" extra-delta: {:?}", sol.extra_delta);

println!("\nInner Puzzle\n");
print_puzzle_info(a, uncurried.args.inner_puzzle, sol.inner_puzzle_solution);
}
DID_INNER_PUZZLE_HASH => {
println!("did_innerpuz.clsp");
let Ok(uncurried) =
CurriedProgram::<NodePtr, DidArgs<NodePtr, NodePtr>>::from_clvm(a, puzzle)
else {
println!("-- failed to uncurry DID transaction");
return;
};
println!(" recovery_did_list_hash: {:?}", uncurried.args.recovery_did_list_hash);
println!(" num_verifications_required: {:?}", uncurried.args.num_verifications_required);
println!(" singleton_struct: {:?}", uncurried.args.singleton_struct);
println!(" metadata: {:?}", uncurried.args.metadata);
let Ok(sol) = DidSolution::<NodePtr>::from_clvm(a, solution) else {
println!("-- failed to parse solution");
return;
};

println!("\nInner Puzzle\n");
let DidSolution::InnerSpend(inner_sol) = sol;
print_puzzle_info(a, uncurried.args.inner_puzzle, inner_sol);
}
SINGLETON_TOP_LAYER_PUZZLE_HASH => {
println!("singleton_top_layer_1_1.clsp");
let Ok(uncurried) =
CurriedProgram::<NodePtr, SingletonArgs<NodePtr>>::from_clvm(a, puzzle)
else {
println!("failed to uncurry singleton");
println!("-- failed to uncurry singleton");
return;
};
println!(" singleton-struct:");
Expand All @@ -150,7 +218,7 @@ fn print_puzzle_info(a: &Allocator, puzzle: NodePtr, solution: NodePtr) {
);

let Ok(sol) = SingletonSolution::<NodePtr>::from_clvm(a, solution) else {
println!("-- failed to parse singleton solution");
println!("-- failed to parse solution");
return;
};
println!(" solution");
Expand All @@ -163,6 +231,7 @@ fn print_puzzle_info(a: &Allocator, puzzle: NodePtr, solution: NodePtr) {
println!("\nInner Puzzle:\n");
print_puzzle_info(a, uncurried.args.inner_puzzle, sol.inner_solution);
}
// TODO: NFT puzzles

// Unknown puzzle
n => {
Expand Down
10 changes: 5 additions & 5 deletions chia-wallet/src/puzzles/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn cat_puzzle_hash(asset_id: [u8; 32], inner_puzzle_hash: [u8; 32]) -> [u8;
}

/// This is the puzzle reveal of the [CAT2 standard](https://chialisp.com/cats) puzzle.
pub static CAT_PUZZLE: [u8; 1672] = hex!(
pub const CAT_PUZZLE: [u8; 1672] = hex!(
"
ff02ffff01ff02ff5effff04ff02ffff04ffff04ff05ffff04ffff0bff34ff05
80ffff04ff0bff80808080ffff04ffff02ff17ff2f80ffff04ff5fffff04ffff
Expand Down Expand Up @@ -109,14 +109,14 @@ pub static CAT_PUZZLE: [u8; 1672] = hex!(
);

/// This is the puzzle hash of the [CAT2 standard](https://chialisp.com/cats) puzzle.
pub static CAT_PUZZLE_HASH: [u8; 32] = hex!(
pub const CAT_PUZZLE_HASH: [u8; 32] = hex!(
"
37bef360ee858133b69d595a906dc45d01af50379dad515eb9518abb7c1d2a7a
"
);

/// This is the puzzle reveal of the [CAT2 multi-issuance TAIL](https://chialisp.com/cats#multi) puzzle.
pub static EVERYTHING_WITH_SIGNATURE_TAIL_PUZZLE: [u8; 41] = hex!(
pub const EVERYTHING_WITH_SIGNATURE_TAIL_PUZZLE: [u8; 41] = hex!(
"
ff02ffff01ff04ffff04ff02ffff04ff05ffff04ff5fff80808080ff8080ffff
04ffff0132ff018080
Expand All @@ -129,7 +129,7 @@ pub static EVERYTHING_WITH_SIGNATURE_TAIL_PUZZLE: [u8; 41] = hex!(
/// It is recommended not to use CAT1 for anything other than backwards compatibility (e.g. offer compression),
/// due to security issues uncovered in an audit. You can read more about the vulnerability that prompted the creation
/// of CAT2 in the [CATbleed Post Mortem](https://github.com/Chia-Network/post-mortem/blob/main/2022-08/2022-08-19-CATbleed.md).
pub static CAT_PUZZLE_V1: [u8; 1420] = hex!(
pub const CAT_PUZZLE_V1: [u8; 1420] = hex!(
"
ff02ffff01ff02ff5effff04ff02ffff04ffff04ff05ffff04ffff0bff2cff05
80ffff04ff0bff80808080ffff04ffff02ff17ff2f80ffff04ff5fffff04ffff
Expand Down Expand Up @@ -185,7 +185,7 @@ pub static CAT_PUZZLE_V1: [u8; 1420] = hex!(
/// It is recommended not to use CAT1 for anything other than backwards compatibility (e.g. offer compression),
/// due to security issues uncovered in an audit. You can read more about the vulnerability that prompted the creation
/// of CAT2 in the [CATbleed Post Mortem](https://github.com/Chia-Network/post-mortem/blob/main/2022-08/2022-08-19-CATbleed.md).
pub static CAT_PUZZLE_HASH_V1: [u8; 32] = hex!(
pub const CAT_PUZZLE_HASH_V1: [u8; 32] = hex!(
"
72dec062874cd4d3aab892a0906688a1ae412b0109982e1797a170add88bdcdc
"
Expand Down
4 changes: 2 additions & 2 deletions chia-wallet/src/puzzles/did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ where
}

/// This is the puzzle reveal of the [DID1 standard](https://chialisp.com/dids) puzzle.
pub static DID_INNER_PUZZLE: [u8; 1012] = hex!(
pub const DID_INNER_PUZZLE: [u8; 1012] = hex!(
"
ff02ffff01ff02ffff03ff81bfffff01ff02ff05ff82017f80ffff01ff02ffff
03ffff22ffff09ffff02ff7effff04ff02ffff04ff8217ffff80808080ff0b80
Expand Down Expand Up @@ -90,7 +90,7 @@ pub static DID_INNER_PUZZLE: [u8; 1012] = hex!(
);

/// This is the puzzle hash of the [DID1 standard](https://chialisp.com/dids) puzzle.
pub static DID_INNER_PUZZLE_HASH: [u8; 32] = hex!(
pub const DID_INNER_PUZZLE_HASH: [u8; 32] = hex!(
"
33143d2bef64f14036742673afd158126b94284b4530a28c354fac202b0c910e
"
Expand Down
8 changes: 4 additions & 4 deletions chia-wallet/src/puzzles/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn standard_puzzle_hash(synthetic_key: &PublicKey) -> [u8; 32] {
}

/// This is the puzzle reveal of the [standard transaction](https://chialisp.com/standard-transactions) puzzle.
pub static STANDARD_PUZZLE: [u8; 227] = hex!(
pub const STANDARD_PUZZLE: [u8; 227] = hex!(
"
ff02ffff01ff02ffff03ff0bffff01ff02ffff03ffff09ff05ffff1dff0bffff
1effff0bff0bffff02ff06ffff04ff02ffff04ff17ff8080808080808080ffff
Expand All @@ -37,17 +37,17 @@ pub static STANDARD_PUZZLE: [u8; 227] = hex!(
);

/// This is the puzzle hash of the [standard transaction](https://chialisp.com/standard-transactions) puzzle.
pub static STANDARD_PUZZLE_HASH: [u8; 32] = hex!(
pub const STANDARD_PUZZLE_HASH: [u8; 32] = hex!(
"
e9aaa49f45bad5c889b86ee3341550c155cfdd10c3a6757de618d20612fffd52
"
);

/// This is the puzzle reveal of the [default hidden puzzle](https://chialisp.com/standard-transactions#default-hidden-puzzle).
pub static DEFAULT_HIDDEN_PUZZLE: [u8; 3] = hex!("ff0980");
pub const DEFAULT_HIDDEN_PUZZLE: [u8; 3] = hex!("ff0980");

/// This is the puzzle hash of the [default hidden puzzle](https://chialisp.com/standard-transactions#default-hidden-puzzle).
pub static DEFAULT_HIDDEN_PUZZLE_HASH: [u8; 32] = hex!(
pub const DEFAULT_HIDDEN_PUZZLE_HASH: [u8; 32] = hex!(
"
711d6c4e32c92e53179b199484cf8c897542bc57f2b22582799f9d657eec4699
"
Expand Down

0 comments on commit b120b0f

Please sign in to comment.