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

Initial move to chia-puzzles #829

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
25 changes: 5 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ chia-protocol = { path = "./crates/chia-protocol", version = "0.17.0" }
chia-secp = { path = "./crates/chia-secp", version = "0.17.0" }
chia-ssl = { path = "./crates/chia-ssl", version = "0.17.0" }
chia-traits = { path = "./crates/chia-traits", version = "0.17.0" }
chia-puzzles = { path = "./crates/chia-puzzles", version = "0.17.0" }
chia-sha2 = { path = "./crates/chia-sha2", version = "0.17.0" }
clvm-traits = { path = "./crates/clvm-traits", version = "0.17.0" }
clvm-utils = { path = "./crates/clvm-utils", version = "0.17.0" }
Expand All @@ -122,6 +121,7 @@ chia-protocol-fuzz = { path = "./crates/chia-protocol/fuzz", version = "0.16.0"
chia-puzzles-fuzz = { path = "./crates/chia-puzzles/fuzz", version = "0.16.0" }
clvm-traits-fuzz = { path = "./crates/clvm-traits/fuzz", version = "0.16.0" }
clvm-utils-fuzz = { path = "./crates/clvm-utils/fuzz", version = "0.16.0" }
chia-puzzles = "0.19.1"
blst = { version = "0.3.12", features = ["portable"] }
clvmr = "0.10.0"
syn = "2.0.90"
Expand Down
2 changes: 2 additions & 0 deletions crates/chia-bls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ hex = { workspace = true }
thiserror = { workspace = true }
pyo3 = { workspace = true, features = ["multiple-pymethods"], optional = true }
arbitrary = { workspace = true, optional = true }
hex-literal = { workspace = true }
num-bigint = { workspace = true }
linked-hash-map = "0.5.6"

[dev-dependencies]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
use chia_bls::{PublicKey, SecretKey};
use chia_sha2::Sha256;
use hex_literal::hex;
use num_bigint::BigInt;

use crate::standard::DEFAULT_HIDDEN_PUZZLE_HASH;
use crate::{PublicKey, SecretKey};

/// This is the puzzle reveal of the [default hidden puzzle](https://chialisp.com/standard-transactions#default-hidden-puzzle).
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 const DEFAULT_HIDDEN_PUZZLE_HASH: [u8; 32] = hex!(
"
711d6c4e32c92e53179b199484cf8c897542bc57f2b22582799f9d657eec4699
"
);

const GROUP_ORDER_BYTES: [u8; 32] =
hex!("73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001");
Expand All @@ -20,7 +29,7 @@ pub trait DeriveSynthetic {
where
Self: Sized,
{
self.derive_synthetic_hidden(&DEFAULT_HIDDEN_PUZZLE_HASH.to_bytes())
self.derive_synthetic_hidden(&DEFAULT_HIDDEN_PUZZLE_HASH)
}
}

Expand Down Expand Up @@ -60,9 +69,9 @@ fn synthetic_offset(public_key: &PublicKey, hidden_puzzle_hash: &[u8; 32]) -> Se
mod tests {
use super::*;

use chia_bls::{master_to_wallet_unhardened_intermediate, DerivableKey};
use hex::ToHex;
use hex_literal::hex;

use crate::{master_to_wallet_unhardened_intermediate, DerivableKey};

#[test]
fn test_synthetic_public_keys() {
Expand Down
2 changes: 2 additions & 0 deletions crates/chia-bls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

mod bls_cache;
mod derive_keys;
mod derive_synthetic;
mod error;
mod gtelement;
mod public_key;
Expand All @@ -13,6 +14,7 @@ mod parse_hex;

pub use bls_cache::BlsCache;
pub use derive_keys::*;
pub use derive_synthetic::*;
pub use error::{Error, Result};
pub use gtelement::GTElement;
pub use public_key::{hash_to_g1, hash_to_g1_with_dst, PublicKey};
Expand Down
99 changes: 91 additions & 8 deletions crates/chia-consensus/src/fast_forward.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,101 @@
use crate::error::{Error, Result};
use chia_protocol::Bytes32;
use chia_protocol::Coin;
use chia_puzzles::singleton::{
SingletonArgs, SingletonSolution, SingletonStruct, SINGLETON_TOP_LAYER_PUZZLE_HASH,
};
use chia_puzzles::Proof;
use chia_puzzles::SINGLETON_LAUNCHER_HASH;
use chia_puzzles::SINGLETON_TOP_LAYER_V1_1_HASH;
use clvm_traits::{FromClvm, ToClvm};
use clvm_utils::CurriedProgram;
use clvm_utils::ToTreeHash;
use clvm_utils::TreeHash;
use clvm_utils::{tree_hash, tree_hash_atom, tree_hash_pair};
use clvmr::allocator::{Allocator, NodePtr};

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

impl<I> SingletonArgs<I> {
pub fn new(launcher_id: Bytes32, inner_puzzle: I) -> Self {
Self {
singleton_struct: SingletonStruct::new(launcher_id),
inner_puzzle,
}
}
}

impl SingletonArgs<TreeHash> {
pub fn curry_tree_hash(launcher_id: Bytes32, inner_puzzle: TreeHash) -> TreeHash {
CurriedProgram {
program: TreeHash::new(SINGLETON_TOP_LAYER_V1_1_HASH),
args: SingletonArgs {
singleton_struct: SingletonStruct::new(launcher_id),
inner_puzzle,
},
}
.tree_hash()
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ToClvm, FromClvm)]
#[clvm(list)]
pub struct SingletonStruct {
pub mod_hash: Bytes32,
pub launcher_id: Bytes32,
#[clvm(rest)]
pub launcher_puzzle_hash: Bytes32,
}

impl SingletonStruct {
pub fn new(launcher_id: Bytes32) -> Self {
Self {
mod_hash: SINGLETON_TOP_LAYER_V1_1_HASH.into(),
launcher_id,
launcher_puzzle_hash: SINGLETON_LAUNCHER_HASH.into(),
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ToClvm, FromClvm)]
#[clvm(solution)]
pub struct SingletonSolution<I> {
pub lineage_proof: Proof,
pub amount: u64,
pub inner_solution: I,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ToClvm, FromClvm)]
#[clvm(solution)]
pub struct LauncherSolution<T> {
pub singleton_puzzle_hash: Bytes32,
pub amount: u64,
pub key_value_list: T,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ToClvm, FromClvm)]
#[clvm(transparent)]
pub enum Proof {
Lineage(LineageProof),
Eve(EveProof),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ToClvm, FromClvm)]
#[clvm(list)]
pub struct LineageProof {
pub parent_parent_coin_info: Bytes32,
pub parent_inner_puzzle_hash: Bytes32,
pub parent_amount: u64,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ToClvm, FromClvm)]
#[clvm(list)]
pub struct EveProof {
pub parent_parent_coin_info: Bytes32,
pub parent_amount: u64,
}

// TODO: replace this with a generic function to compute the hash of curried
// puzzles
const OP_QUOTE: u8 = 1;
Expand Down Expand Up @@ -86,16 +171,14 @@ pub fn fast_forward_singleton(

// this is the tree hash of the singleton top layer puzzle
// the tree hash of singleton_top_layer_v1_1.clsp
if singleton.args.singleton_struct.mod_hash.as_ref()
!= SINGLETON_TOP_LAYER_PUZZLE_HASH.to_bytes()
{
if singleton.args.singleton_struct.mod_hash.as_ref() != SINGLETON_TOP_LAYER_V1_1_HASH {
return Err(Error::NotSingletonModHash);
}

// also make sure the actual mod-hash of this puzzle matches the
// singleton_top_layer_v1_1.clsp
let mod_hash = tree_hash(a, singleton.program);
if mod_hash != SINGLETON_TOP_LAYER_PUZZLE_HASH {
if mod_hash != SINGLETON_TOP_LAYER_V1_1_HASH.into() {
return Err(Error::NotSingletonModHash);
}

Expand Down
33 changes: 0 additions & 33 deletions crates/chia-puzzles/Cargo.toml

This file was deleted.

3 changes: 0 additions & 3 deletions crates/chia-puzzles/fuzz/.gitignore

This file was deleted.

25 changes: 0 additions & 25 deletions crates/chia-puzzles/fuzz/Cargo.toml

This file was deleted.

26 changes: 0 additions & 26 deletions crates/chia-puzzles/fuzz/fuzz_targets/roundtrip.rs

This file was deleted.

7 changes: 0 additions & 7 deletions crates/chia-puzzles/src/lib.rs

This file was deleted.

36 changes: 0 additions & 36 deletions crates/chia-puzzles/src/proof.rs

This file was deleted.

Loading
Loading