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

Simplify lineage proof and remove chia-consensus singleton types #492

Merged
merged 6 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
37 changes: 5 additions & 32 deletions crates/chia-consensus/src/fast_forward.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,16 @@
use crate::error::{Error, Result};
use chia_protocol::Bytes32;
use chia_protocol::Coin;
use chia_wallet::singleton::SingletonArgs;
use chia_wallet::singleton::SingletonSolution;
use chia_wallet::singleton::SingletonStruct;
use chia_wallet::singleton::SINGLETON_TOP_LAYER_PUZZLE_HASH;
arvidn marked this conversation as resolved.
Show resolved Hide resolved
use clvm_traits::{FromClvm, ToClvm};
use clvm_traits::FromClvm;
use clvm_traits::ToClvm;
arvidn marked this conversation as resolved.
Show resolved Hide resolved
use clvm_utils::CurriedProgram;
use clvm_utils::{tree_hash, tree_hash_atom, tree_hash_pair};
use clvmr::allocator::{Allocator, NodePtr};

#[derive(FromClvm, ToClvm, Debug)]
#[clvm(tuple)]
pub struct SingletonStruct {
pub mod_hash: Bytes32,
pub launcher_id: Bytes32,
pub launcher_puzzle_hash: Bytes32,
}

#[derive(FromClvm, ToClvm, Debug)]
#[clvm(curry)]
pub struct SingletonArgs<I> {
pub singleton_struct: SingletonStruct,
pub inner_puzzle: I,
}

#[derive(FromClvm, ToClvm, Debug)]
#[clvm(list)]
pub struct LineageProof {
pub parent_parent_coin_id: Bytes32,
pub parent_inner_puzzle_hash: Bytes32,
pub parent_amount: u64,
}

#[derive(FromClvm, ToClvm, Debug)]
#[clvm(list)]
pub struct SingletonSolution<I> {
pub lineage_proof: LineageProof,
pub amount: u64,
pub inner_solution: I,
}

// TODO: replace this with a generic function to compute the hash of curried
// puzzles
const OP_QUOTE: u8 = 1;
Expand Down
11 changes: 6 additions & 5 deletions crates/chia-tools/src/bin/run-spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use chia_wallet::cat::{CatArgs, CatSolution, CAT_PUZZLE_HASH};
use chia_wallet::did::{DidArgs, DidSolution, DID_INNER_PUZZLE_HASH};
use chia_wallet::singleton::{SingletonArgs, SingletonSolution, SINGLETON_TOP_LAYER_PUZZLE_HASH};
use chia_wallet::standard::{StandardArgs, StandardSolution, STANDARD_PUZZLE_HASH};
use chia_wallet::Proof;
use chia_wallet::MaybeEveProof;

/// Run a puzzle given a solution and print the resulting conditions
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -233,16 +233,17 @@ fn print_puzzle_info(a: &Allocator, puzzle: NodePtr, solution: NodePtr) {
uncurried.args.singleton_struct.launcher_puzzle_hash
);

let Ok(sol) = SingletonSolution::<NodePtr>::from_clvm(a, solution) else {
let Ok(sol) = SingletonSolution::<NodePtr, MaybeEveProof>::from_clvm(a, solution)
else {
println!("-- failed to parse solution");
return;
};
println!(" solution");
match sol.proof {
Proof::Lineage(lp) => {
match sol.lineage_proof {
MaybeEveProof::Lineage(lp) => {
println!(" lineage-proof: {lp:?}");
}
Proof::Eve(ep) => {
MaybeEveProof::Eve(ep) => {
println!(" eve-proof: {ep:?}");
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/chia-wallet/fuzz/fuzz_targets/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ fuzz_target!(|data: &[u8]| {
{
use std::fmt;

use chia_wallet::{nft::NftMetadata, Proof};
use chia_wallet::{nft::NftMetadata, MaybeEveProof};
use clvm_traits::{FromClvm, ToClvm};
use clvmr::{allocator::NodePtr, Allocator};
use libfuzzer_sys::arbitrary::{Arbitrary, Unstructured};

let mut u = Unstructured::new(data);
roundtrip::<NftMetadata>(&mut u);
roundtrip::<Proof>(&mut u);
roundtrip::<MaybeEveProof>(&mut u);

fn roundtrip<'a, T>(u: &mut Unstructured<'a>)
where
Expand Down
8 changes: 4 additions & 4 deletions crates/chia-wallet/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clvm_traits::{FromClvm, ToClvm};
#[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)]
#[cfg_attr(fuzzing, derive(arbitrary::Arbitrary))]
#[clvm(untagged, tuple)]
pub enum Proof {
pub enum MaybeEveProof {
arvidn marked this conversation as resolved.
Show resolved Hide resolved
Lineage(LineageProof),
Eve(EveProof),
}
Expand All @@ -13,9 +13,9 @@ pub enum Proof {
#[cfg_attr(fuzzing, derive(arbitrary::Arbitrary))]
#[clvm(list)]
pub struct LineageProof {
pub parent_coin_info: Bytes32,
pub inner_puzzle_hash: Bytes32,
pub amount: u64,
pub parent_parent_coin_id: Bytes32,
pub parent_inner_puzzle_hash: Bytes32,
pub parent_amount: u64,
}

#[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)]
Expand Down
6 changes: 3 additions & 3 deletions crates/chia-wallet/src/puzzles/singleton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chia_protocol::Bytes32;
use clvm_traits::{FromClvm, ToClvm};
use hex_literal::hex;

use crate::Proof;
use crate::LineageProof;

#[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)]
#[clvm(curry)]
Expand All @@ -21,8 +21,8 @@ pub struct SingletonStruct {

#[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)]
#[clvm(list)]
pub struct SingletonSolution<I> {
pub proof: Proof,
pub struct SingletonSolution<I, P = LineageProof> {
arvidn marked this conversation as resolved.
Show resolved Hide resolved
pub lineage_proof: P,
pub amount: u64,
pub inner_solution: I,
}
Expand Down
Loading