diff --git a/chia-wallet/fuzz/fuzz_targets/roundtrip.rs b/chia-wallet/fuzz/fuzz_targets/roundtrip.rs index d76e0a574..94b52280c 100644 --- a/chia-wallet/fuzz/fuzz_targets/roundtrip.rs +++ b/chia-wallet/fuzz/fuzz_targets/roundtrip.rs @@ -1,13 +1,16 @@ #![no_main] -use std::fmt; use chia_wallet::{nft::NftMetadata, Proof}; +use libfuzzer_sys::{arbitrary::Unstructured, fuzz_target}; + +#[cfg(fuzzing)] use clvm_traits::{FromPtr, ToPtr}; +#[cfg(fuzzing)] use clvmr::Allocator; -use libfuzzer_sys::{ - arbitrary::{Arbitrary, Unstructured}, - fuzz_target, -}; +#[cfg(fuzzing)] +use libfuzzer_sys::arbitrary::Arbitrary; +#[cfg(fuzzing)] +use std::fmt; fuzz_target!(|data: &[u8]| { let mut u = Unstructured::new(data); @@ -15,6 +18,7 @@ fuzz_target!(|data: &[u8]| { roundtrip::(&mut u); }); +#[cfg(fuzzing)] fn roundtrip<'a, T>(u: &mut Unstructured<'a>) where T: Arbitrary<'a> + ToPtr + FromPtr + PartialEq + fmt::Debug, @@ -25,3 +29,6 @@ where let obj2 = T::from_ptr(&a, ptr).unwrap(); assert_eq!(obj, obj2); } + +#[cfg(not(fuzzing))] +fn roundtrip(_u: &mut Unstructured) {} diff --git a/chia-wallet/src/proof.rs b/chia-wallet/src/proof.rs index 562d7abbd..7aa7a5296 100644 --- a/chia-wallet/src/proof.rs +++ b/chia-wallet/src/proof.rs @@ -1,4 +1,5 @@ use arbitrary::{Arbitrary, Unstructured}; +use chia_protocol::Bytes32; use clvm_traits::{from_clvm, to_clvm, FromClvm, ToClvm}; #[derive(Debug, Clone, PartialEq, Eq)] @@ -35,13 +36,13 @@ impl<'a> Arbitrary<'a> for Proof { let is_eve = u.ratio(3, 10)?; if is_eve { Ok(Self::Eve(EveProof { - parent_coin_info: u.arbitrary()?, + parent_coin_info: u.arbitrary::<[u8; 32]>()?.into(), amount: u.arbitrary()?, })) } else { Ok(Self::Lineage(LineageProof { - parent_coin_info: u.arbitrary()?, - inner_puzzle_hash: u.arbitrary()?, + parent_coin_info: u.arbitrary::<[u8; 32]>()?.into(), + inner_puzzle_hash: u.arbitrary::<[u8; 32]>()?.into(), amount: u.arbitrary()?, })) } @@ -51,14 +52,14 @@ impl<'a> Arbitrary<'a> for Proof { #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] #[clvm(list)] pub struct LineageProof { - pub parent_coin_info: [u8; 32], - pub inner_puzzle_hash: [u8; 32], + pub parent_coin_info: Bytes32, + pub inner_puzzle_hash: Bytes32, pub amount: u64, } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] #[clvm(list)] pub struct EveProof { - pub parent_coin_info: [u8; 32], + pub parent_coin_info: Bytes32, pub amount: u64, } diff --git a/chia-wallet/src/puzzles/cat.rs b/chia-wallet/src/puzzles/cat.rs index 44fab5ba7..43da15d6a 100644 --- a/chia-wallet/src/puzzles/cat.rs +++ b/chia-wallet/src/puzzles/cat.rs @@ -1,5 +1,5 @@ use chia_bls::PublicKey; -use chia_protocol::Coin; +use chia_protocol::{Bytes32, Coin}; use clvm_traits::{FromClvm, ToClvm}; use hex_literal::hex; @@ -8,8 +8,8 @@ use crate::LineageProof; #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] #[clvm(curry)] pub struct CatArgs { - pub mod_hash: [u8; 32], - pub tail_program_hash: [u8; 32], + pub mod_hash: Bytes32, + pub tail_program_hash: Bytes32, pub inner_puzzle: I, } @@ -24,7 +24,7 @@ pub struct EverythingWithSignatureTailArgs { pub struct CatSolution { pub inner_puzzle_solution: I, pub lineage_proof: Option, - pub prev_coin_id: [u8; 32], + pub prev_coin_id: Bytes32, pub this_coin_info: Coin, pub next_coin_proof: CoinProof, pub prev_subtotal: i64, @@ -34,8 +34,8 @@ pub struct CatSolution { #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] #[clvm(list)] pub struct CoinProof { - pub parent_coin_info: [u8; 32], - pub inner_puzzle_hash: [u8; 32], + pub parent_coin_info: Bytes32, + pub inner_puzzle_hash: Bytes32, pub amount: u64, } diff --git a/chia-wallet/src/puzzles/did.rs b/chia-wallet/src/puzzles/did.rs index 228ebb0f6..efd5f8a66 100644 --- a/chia-wallet/src/puzzles/did.rs +++ b/chia-wallet/src/puzzles/did.rs @@ -1,3 +1,4 @@ +use chia_protocol::Bytes32; use clvm_traits::{clvm_tuple, from_clvm, match_tuple, to_clvm, FromClvm, FromClvmError, ToClvm}; use hex_literal::hex; @@ -7,7 +8,7 @@ use crate::singleton::SingletonStruct; #[clvm(curry)] pub struct DidArgs { pub inner_puzzle: I, - pub recovery_did_list_hash: [u8; 32], + pub recovery_did_list_hash: Bytes32, pub num_verifications_required: u64, pub singleton_struct: SingletonStruct, pub metadata: M, diff --git a/chia-wallet/src/puzzles/nft.rs b/chia-wallet/src/puzzles/nft.rs index d0a867083..907e09c8f 100644 --- a/chia-wallet/src/puzzles/nft.rs +++ b/chia-wallet/src/puzzles/nft.rs @@ -1,4 +1,4 @@ -use arbitrary::Arbitrary; +use chia_protocol::Bytes32; use clvm_traits::{from_clvm, to_clvm, FromClvm, Raw, ToClvm}; use hex_literal::hex; @@ -7,7 +7,7 @@ use crate::singleton::SingletonStruct; #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] #[clvm(curry)] pub struct NftIntermediateLauncherArgs { - pub launcher_puzzle_hash: [u8; 32], + pub launcher_puzzle_hash: Bytes32, pub mint_number: usize, pub mint_total: usize, } @@ -15,9 +15,9 @@ pub struct NftIntermediateLauncherArgs { #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] #[clvm(curry)] pub struct NftStateLayerArgs { - pub mod_hash: [u8; 32], + pub mod_hash: Bytes32, pub metadata: M, - pub metadata_updater_puzzle_hash: [u8; 32], + pub metadata_updater_puzzle_hash: Bytes32, pub inner_puzzle: I, } @@ -30,8 +30,8 @@ pub struct NftStateLayerSolution { #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] #[clvm(curry)] pub struct NftOwnershipLayerArgs { - pub mod_hash: [u8; 32], - pub current_owner: Option<[u8; 32]>, + pub mod_hash: Bytes32, + pub current_owner: Option, pub transfer_program: P, pub inner_puzzle: I, } @@ -46,20 +46,21 @@ pub struct NftOwnershipLayerSolution { #[clvm(curry)] pub struct NftRoyaltyTransferPuzzleArgs { pub singleton_struct: SingletonStruct, - pub royalty_puzzle_hash: [u8; 32], + pub royalty_puzzle_hash: Bytes32, pub trade_price_percentage: u16, } -#[derive(Debug, Clone, PartialEq, Eq, Arbitrary)] +#[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(fuzzing, derive(arbitrary::Arbitrary))] pub struct NftMetadata { pub edition_number: u64, pub edition_total: u64, pub data_uris: Vec, - pub data_hash: Option<[u8; 32]>, + pub data_hash: Option, pub metadata_uris: Vec, - pub metadata_hash: Option<[u8; 32]>, + pub metadata_hash: Option, pub license_uris: Vec, - pub license_hash: Option<[u8; 32]>, + pub license_hash: Option, } impl Default for NftMetadata { diff --git a/chia-wallet/src/puzzles/singleton.rs b/chia-wallet/src/puzzles/singleton.rs index c1b0c2409..263230e8d 100644 --- a/chia-wallet/src/puzzles/singleton.rs +++ b/chia-wallet/src/puzzles/singleton.rs @@ -1,3 +1,4 @@ +use chia_protocol::Bytes32; use clvm_traits::{FromClvm, ToClvm}; use hex_literal::hex; @@ -13,9 +14,9 @@ pub struct SingletonArgs { #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] #[clvm(tuple)] pub struct SingletonStruct { - pub mod_hash: [u8; 32], - pub launcher_id: [u8; 32], - pub launcher_puzzle_hash: [u8; 32], + pub mod_hash: Bytes32, + pub launcher_id: Bytes32, + pub launcher_puzzle_hash: Bytes32, } #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] @@ -29,17 +30,17 @@ pub struct SingletonSolution { #[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] #[clvm(list)] pub struct LauncherSolution { - pub singleton_puzzle_hash: [u8; 32], + pub singleton_puzzle_hash: Bytes32, pub amount: u64, pub key_value_list: T, } impl SingletonStruct { - pub fn new(launcher_id: [u8; 32]) -> Self { + pub fn new(launcher_id: Bytes32) -> Self { Self { - mod_hash: SINGLETON_TOP_LAYER_PUZZLE_HASH, + mod_hash: SINGLETON_TOP_LAYER_PUZZLE_HASH.into(), launcher_id, - launcher_puzzle_hash: SINGLETON_LAUNCHER_PUZZLE_HASH, + launcher_puzzle_hash: SINGLETON_LAUNCHER_PUZZLE_HASH.into(), } } }