diff --git a/chia-bls/benches/parse.rs b/chia-bls/benches/parse.rs index 90515f0c0..bf100b369 100644 --- a/chia-bls/benches/parse.rs +++ b/chia-bls/benches/parse.rs @@ -1,7 +1,7 @@ use chia_bls::secret_key::SecretKey; use chia_bls::signature::sign; -use chia_bls::Signature; use chia_bls::PublicKey; +use chia_bls::Signature; use criterion::{black_box, criterion_group, criterion_main, Criterion}; use rand::rngs::StdRng; use rand::{Rng, SeedableRng}; @@ -16,8 +16,8 @@ fn parse_benchmark(c: &mut Criterion) { let msg = b"The quick brown fox jumps over the lazy dog"; let sig = sign(&sk, msg); - let sig_bytes = sig.to_bytes(); - let pk_bytes = pk.to_bytes(); + let sig_bytes = sig.to_bytes(); + let pk_bytes = pk.to_bytes(); c.bench_function("parse Signature", |b| { b.iter(|| { @@ -46,4 +46,3 @@ fn parse_benchmark(c: &mut Criterion) { criterion_group!(parse, parse_benchmark); criterion_main!(parse); - diff --git a/chia-bls/src/gtelement.rs b/chia-bls/src/gtelement.rs index 818085f1c..03d4de936 100644 --- a/chia-bls/src/gtelement.rs +++ b/chia-bls/src/gtelement.rs @@ -1,6 +1,6 @@ use blst::*; use chia_traits::chia_error::Result; -use chia_traits::{read_bytes, Streamable}; +use chia_traits::{read_bytes, Streamable, Validation}; use sha2::{Digest, Sha256}; use std::fmt; use std::hash::{Hash, Hasher}; @@ -57,12 +57,6 @@ impl GTElement { #[pyo3(name = "SIZE")] const PY_SIZE: usize = Self::SIZE; - #[staticmethod] - #[pyo3(name = "from_bytes_unchecked")] - fn py_from_bytes_unchecked(bytes: [u8; Self::SIZE]) -> Result { - Ok(Self::from_bytes(&bytes)) - } - pub fn __repr__(&self) -> String { let bytes = self.to_bytes(); format!("", &hex::encode(bytes)) @@ -151,7 +145,7 @@ impl Streamable for GTElement { Ok(()) } - fn parse(input: &mut Cursor<&[u8]>) -> Result { + fn parse(input: &mut Cursor<&[u8]>, _checked: Validation) -> Result { Ok(GTElement::from_bytes( read_bytes(input, Self::SIZE)?.try_into().unwrap(), )) diff --git a/chia-bls/src/public_key.rs b/chia-bls/src/public_key.rs index 33a376ad1..e814eda31 100644 --- a/chia-bls/src/public_key.rs +++ b/chia-bls/src/public_key.rs @@ -1,7 +1,7 @@ use crate::secret_key::is_all_zero; use crate::{DerivableKey, Error, Result}; use blst::*; -use chia_traits::{read_bytes, Streamable}; +use chia_traits::{read_bytes, Streamable, Validation}; use clvm_traits::{FromClvm, ToClvm}; use clvmr::allocator::{Allocator, NodePtr, SExp}; use sha2::{digest::FixedOutput, Digest, Sha256}; @@ -167,12 +167,6 @@ impl PublicKey { Self::default() } - #[staticmethod] - #[pyo3(name = "from_bytes_unchecked")] - fn py_from_bytes_unchecked(bytes: [u8; Self::SIZE]) -> Result { - Self::from_bytes_unchecked(&bytes) - } - #[staticmethod] #[pyo3(name = "generator")] pub fn py_generator() -> Self { @@ -219,10 +213,13 @@ impl Streamable for PublicKey { Ok(()) } - fn parse(input: &mut Cursor<&[u8]>) -> chia_traits::Result { - Ok(Self::from_bytes( - read_bytes(input, 48)?.try_into().unwrap(), - )?) + fn parse(input: &mut Cursor<&[u8]>, checked: Validation) -> chia_traits::Result { + let input = read_bytes(input, 48)?.try_into().unwrap(); + if checked == Validation::On { + Ok(Self::from_bytes(input)?) + } else { + Ok(Self::from_bytes_unchecked(input)?) + } } } diff --git a/chia-bls/src/secret_key.rs b/chia-bls/src/secret_key.rs index ceb0d38a6..a5f16850e 100644 --- a/chia-bls/src/secret_key.rs +++ b/chia-bls/src/secret_key.rs @@ -1,6 +1,6 @@ use crate::{DerivableKey, Error, PublicKey, Result}; use blst::*; -use chia_traits::{read_bytes, Streamable}; +use chia_traits::{read_bytes, Streamable, Validation}; use hkdf::HkdfExtract; use sha2::{Digest, Sha256}; use std::fmt; @@ -168,7 +168,10 @@ impl Streamable for SecretKey { Ok(()) } - fn parse(input: &mut Cursor<&[u8]>) -> chia_traits::chia_error::Result { + fn parse( + input: &mut Cursor<&[u8]>, + _checked: Validation, + ) -> chia_traits::chia_error::Result { Ok(Self::from_bytes( read_bytes(input, 32)?.try_into().unwrap(), )?) diff --git a/chia-bls/src/signature.rs b/chia-bls/src/signature.rs index 4e3c77574..ee2991e50 100644 --- a/chia-bls/src/signature.rs +++ b/chia-bls/src/signature.rs @@ -1,6 +1,6 @@ use crate::{Error, GTElement, PublicKey, Result, SecretKey}; use blst::*; -use chia_traits::{read_bytes, Streamable}; +use chia_traits::{read_bytes, Streamable, Validation}; use clvm_traits::{FromClvm, ToClvm}; use clvmr::allocator::{Allocator, NodePtr, SExp}; use sha2::{Digest, Sha256}; @@ -145,10 +145,16 @@ impl Streamable for Signature { Ok(()) } - fn parse(input: &mut Cursor<&[u8]>) -> chia_traits::chia_error::Result { - Ok(Self::from_bytes( - read_bytes(input, 96)?.try_into().unwrap(), - )?) + fn parse( + input: &mut Cursor<&[u8]>, + checked: Validation, + ) -> chia_traits::chia_error::Result { + let input = read_bytes(input, 96)?.try_into().unwrap(); + if checked == Validation::On { + Ok(Self::from_bytes(input)?) + } else { + Ok(Self::from_bytes_unchecked(input)?) + } } } @@ -281,12 +287,6 @@ impl Signature { Self::default() } - #[staticmethod] - #[pyo3(name = "from_bytes_unchecked")] - pub fn py_from_bytes_unchecked(bytes: [u8; Self::SIZE]) -> Result { - Self::from_bytes_unchecked(&bytes) - } - #[pyo3(name = "pair")] pub fn py_pair(&self, other: &PublicKey) -> GTElement { self.pair(other) diff --git a/chia-protocol/fuzz/fuzz_targets/streamable.rs b/chia-protocol/fuzz/fuzz_targets/streamable.rs index a5a8b3af5..bdb871d05 100644 --- a/chia-protocol/fuzz/fuzz_targets/streamable.rs +++ b/chia-protocol/fuzz/fuzz_targets/streamable.rs @@ -21,6 +21,9 @@ pub fn test_streamable(obj: &T) { }; assert_eq!(obj, &obj2); + let obj3 = T::from_bytes_unchecked(&bytes).unwrap(); + assert_eq!(obj, &obj3); + let mut ctx = Sha256::new(); ctx.update(&bytes); let expect_hash: [u8; 32] = ctx.finalize().into(); diff --git a/chia-protocol/src/bytes.rs b/chia-protocol/src/bytes.rs index 01f6d57bb..c72e694ea 100644 --- a/chia-protocol/src/bytes.rs +++ b/chia-protocol/src/bytes.rs @@ -1,5 +1,5 @@ use chia_traits::chia_error; -use chia_traits::{read_bytes, Streamable}; +use chia_traits::{read_bytes, Streamable, Validation}; use clvm_traits::{FromClvm, ToClvm}; use clvmr::allocator::{NodePtr, SExp}; use clvmr::Allocator; @@ -56,8 +56,8 @@ impl Streamable for Bytes { } } - fn parse(input: &mut Cursor<&[u8]>) -> chia_error::Result { - let len = u32::parse(input)?; + fn parse(input: &mut Cursor<&[u8]>, checked: Validation) -> chia_error::Result { + let len = u32::parse(input, checked)?; Ok(Bytes(read_bytes(input, len as usize)?.to_vec())) } } @@ -196,7 +196,7 @@ impl Streamable for BytesImpl { Ok(()) } - fn parse(input: &mut Cursor<&[u8]>) -> chia_error::Result { + fn parse(input: &mut Cursor<&[u8]>, _checked: Validation) -> chia_error::Result { Ok(BytesImpl(read_bytes(input, N)?.try_into().unwrap())) } } @@ -568,7 +568,7 @@ mod tests { fn from_bytes(buf: &[u8], expected: T) { let mut input = Cursor::<&[u8]>::new(buf); - assert_eq!(T::parse(&mut input).unwrap(), expected); + assert_eq!(T::parse(&mut input, Validation::On).unwrap(), expected); } fn from_bytes_fail( @@ -576,7 +576,7 @@ mod tests { expected: chia_error::Error, ) { let mut input = Cursor::<&[u8]>::new(buf); - assert_eq!(T::parse(&mut input).unwrap_err(), expected); + assert_eq!(T::parse(&mut input, Validation::On).unwrap_err(), expected); } fn stream(v: &T) -> Vec { diff --git a/chia-protocol/src/program.rs b/chia-protocol/src/program.rs index 10bff1f1b..d636bf7d0 100644 --- a/chia-protocol/src/program.rs +++ b/chia-protocol/src/program.rs @@ -1,6 +1,6 @@ use crate::bytes::Bytes; use chia_traits::chia_error::{Error, Result}; -use chia_traits::Streamable; +use chia_traits::{Streamable, Validation}; use clvm_traits::{FromClvm, ToClvm}; use clvmr::allocator::NodePtr; use clvmr::serde::{node_from_bytes, node_to_bytes, serialized_length_from_bytes}; @@ -69,7 +69,7 @@ impl Streamable for Program { Ok(()) } - fn parse(input: &mut Cursor<&[u8]>) -> Result { + fn parse(input: &mut Cursor<&[u8]>, _checked: Validation) -> Result { let pos = input.position(); let buf: &[u8] = &input.get_ref()[pos as usize..]; let len = serialized_length_from_bytes(buf).map_err(|_e| Error::EndOfBuffer)?; diff --git a/chia-tools/src/bin/analyze-chain.rs b/chia-tools/src/bin/analyze-chain.rs index a924f0069..d3dcd98a8 100644 --- a/chia-tools/src/bin/analyze-chain.rs +++ b/chia-tools/src/bin/analyze-chain.rs @@ -86,8 +86,8 @@ fn main() { let block_buffer = zstd::stream::decode_all(&mut std::io::Cursor::>::new(block_buffer)) .expect("failed to decompress block"); - let block = FullBlock::parse(&mut std::io::Cursor::<&[u8]>::new(&block_buffer)) - .expect("failed to parse FullBlock"); + let block = + FullBlock::from_bytes_unchecked(&block_buffer).expect("failed to parse FullBlock"); let ti = match block.transactions_info { Some(ti) => ti, @@ -141,8 +141,8 @@ fn main() { zstd::stream::decode_all(&mut std::io::Cursor::>::new(ref_block)) .expect("failed to decompress block"); - let ref_block = FullBlock::parse(&mut std::io::Cursor::<&[u8]>::new(&ref_block)) - .expect("failed to parse ref-block"); + let ref_block = + FullBlock::from_bytes_unchecked(&ref_block).expect("failed to parse ref-block"); let ref_gen = match ref_block.transactions_generator { None => { panic!("block ref has no generator"); diff --git a/chia-tools/src/bin/fast-forward-spend.rs b/chia-tools/src/bin/fast-forward-spend.rs index 3484bbeed..10f010d05 100644 --- a/chia-tools/src/bin/fast-forward-spend.rs +++ b/chia-tools/src/bin/fast-forward-spend.rs @@ -1,6 +1,5 @@ use clap::Parser; use std::fs; -use std::io::Cursor; use chia::fast_forward::fast_forward_singleton; use chia_protocol::bytes::Bytes32; @@ -31,7 +30,7 @@ fn main() { let args = Args::parse(); let spend_bytes = fs::read(args.spend).expect("read file"); - let spend = CoinSpend::parse(&mut Cursor::new(&spend_bytes)).expect("parse CoinSpend"); + let spend = CoinSpend::from_bytes(&spend_bytes).expect("parse CoinSpend"); let new_parents_parent: Bytes32 = hex::decode(args.new_parents_parent) .expect("invalid hex") diff --git a/chia-tools/src/bin/run-spend.rs b/chia-tools/src/bin/run-spend.rs index a386380c0..1a677e0b4 100644 --- a/chia-tools/src/bin/run-spend.rs +++ b/chia-tools/src/bin/run-spend.rs @@ -7,7 +7,6 @@ use clvm_utils::tree_hash; use clvm_utils::CurriedProgram; use clvmr::{allocator::NodePtr, Allocator}; use hex_literal::hex; -use std::io::Cursor; /// Run a puzzle given a solution and print the resulting conditions #[derive(Parser, Debug)] @@ -235,7 +234,7 @@ fn main() { let mut a = Allocator::new(); let spend = read(args.spend).expect("spend file not found"); - let spend = CoinSpend::parse(&mut Cursor::new(spend.as_slice())).expect("parse CoinSpend"); + let spend = CoinSpend::from_bytes(&spend).expect("parse CoinSpend"); let puzzle = spend .puzzle_reveal diff --git a/chia-tools/src/bin/test-block-generators.rs b/chia-tools/src/bin/test-block-generators.rs index ff059e3be..cf509ba47 100644 --- a/chia-tools/src/bin/test-block-generators.rs +++ b/chia-tools/src/bin/test-block-generators.rs @@ -179,8 +179,8 @@ fn main() { let block_buffer = zstd::stream::decode_all(&mut std::io::Cursor::>::new(block_buffer)) .expect("failed to decompress block"); - let block = FullBlock::parse(&mut std::io::Cursor::<&[u8]>::new(&block_buffer)) - .expect("failed to parse FullBlock"); + let block = + FullBlock::from_bytes_unchecked(&block_buffer).expect("failed to parse FullBlock"); let ti = match block.transactions_info { Some(ti) => ti, @@ -218,8 +218,8 @@ fn main() { zstd::stream::decode_all(&mut std::io::Cursor::>::new(ref_block)) .expect("failed to decompress block"); - let ref_block = FullBlock::parse(&mut std::io::Cursor::<&[u8]>::new(&ref_block)) - .expect("failed to parse ref-block"); + let ref_block = + FullBlock::from_bytes_unchecked(&ref_block).expect("failed to parse ref-block"); let ref_gen = ref_block .transactions_generator .expect("block ref has no generator"); diff --git a/chia-tools/src/visit_spends.rs b/chia-tools/src/visit_spends.rs index 4174bcbeb..9f03071df 100644 --- a/chia-tools/src/visit_spends.rs +++ b/chia-tools/src/visit_spends.rs @@ -53,8 +53,8 @@ pub fn iterate_tx_blocks( let block_buffer = zstd::stream::decode_all(&mut std::io::Cursor::>::new(block_buffer)) .expect("failed to decompress block"); - let block = FullBlock::parse(&mut std::io::Cursor::<&[u8]>::new(&block_buffer)) - .expect("failed to parse FullBlock"); + let block = + FullBlock::from_bytes_unchecked(&block_buffer).expect("failed to parse FullBlock"); if block.transactions_info.is_none() { continue; @@ -83,8 +83,8 @@ pub fn iterate_tx_blocks( zstd::stream::decode_all(&mut std::io::Cursor::>::new(ref_block)) .expect("failed to decompress block"); - let ref_block = FullBlock::parse(&mut std::io::Cursor::<&[u8]>::new(&ref_block)) - .expect("failed to parse ref-block"); + let ref_block = + FullBlock::from_bytes_unchecked(&ref_block).expect("failed to parse ref-block"); let ref_gen = ref_block .transactions_generator .expect("block ref has no generator"); diff --git a/chia-traits/src/streamable.rs b/chia-traits/src/streamable.rs index c7338c447..4f07ac59f 100644 --- a/chia-traits/src/streamable.rs +++ b/chia-traits/src/streamable.rs @@ -27,10 +27,16 @@ fn test_read_bytes() { assert_eq!(read_bytes(&mut input, 1).unwrap_err(), Error::EndOfBuffer); } +#[derive(Clone, Copy, PartialEq)] +pub enum Validation { + On, + Off, +} + pub trait Streamable { fn update_digest(&self, digest: &mut Sha256); fn stream(&self, out: &mut Vec) -> Result<()>; - fn parse(input: &mut Cursor<&[u8]>) -> Result + fn parse(input: &mut Cursor<&[u8]>, checked: Validation) -> Result where Self: Sized; @@ -48,7 +54,19 @@ pub trait Streamable { Self: Sized, { let mut cursor = Cursor::new(bytes); - let ret = Self::parse(&mut cursor)?; + let ret = Self::parse(&mut cursor, Validation::On)?; + if cursor.position() != bytes.len() as u64 { + Err(Error::InputTooLarge) + } else { + Ok(ret) + } + } + fn from_bytes_unchecked(bytes: &[u8]) -> Result + where + Self: Sized, + { + let mut cursor = Cursor::new(bytes); + let ret = Self::parse(&mut cursor, Validation::Off)?; if cursor.position() != bytes.len() as u64 { Err(Error::InputTooLarge) } else { @@ -71,7 +89,7 @@ macro_rules! streamable_primitive { fn stream(&self, out: &mut Vec) -> Result<()> { Ok(out.extend_from_slice(&self.to_be_bytes())) } - fn parse(input: &mut Cursor<&[u8]>) -> Result { + fn parse(input: &mut Cursor<&[u8]>, _checked: Validation) -> Result { let sz = size_of::<$t>(); Ok(<$t>::from_be_bytes( read_bytes(input, sz)?.try_into().unwrap(), @@ -112,8 +130,8 @@ impl Streamable for Vec { } } - fn parse(input: &mut Cursor<&[u8]>) -> Result { - let len = u32::parse(input)?; + fn parse(input: &mut Cursor<&[u8]>, checked: Validation) -> Result { + let len = u32::parse(input, checked)?; let mut ret = if std::mem::size_of::() == 0 { Vec::::new() @@ -122,7 +140,7 @@ impl Streamable for Vec { Vec::::with_capacity(std::cmp::min(limit, len as usize)) }; for _ in 0..len { - ret.push(T::parse(input)?); + ret.push(T::parse(input, checked)?); } Ok(ret) } @@ -147,8 +165,8 @@ impl Streamable for String { } } - fn parse(input: &mut Cursor<&[u8]>) -> Result { - let len = u32::parse(input)?; + fn parse(input: &mut Cursor<&[u8]>, checked: Validation) -> Result { + let len = u32::parse(input, checked)?; Ok(String::from( std::str::from_utf8(read_bytes(input, len as usize)?) .map_err(|_| Error::InvalidString)?, @@ -165,7 +183,7 @@ impl Streamable for bool { out.extend_from_slice(if *self { &[1] } else { &[0] }); Ok(()) } - fn parse(input: &mut Cursor<&[u8]>) -> Result { + fn parse(input: &mut Cursor<&[u8]>, _checked: Validation) -> Result { let val = read_bytes(input, 1)?[0]; match val { 0 => Ok(false), @@ -180,7 +198,7 @@ impl Streamable for () { fn stream(&self, _out: &mut Vec) -> Result<()> { Ok(()) } - fn parse(_input: &mut Cursor<&[u8]>) -> Result { + fn parse(_input: &mut Cursor<&[u8]>, _checked: Validation) -> Result { Ok(()) } } @@ -210,11 +228,11 @@ impl Streamable for Option { } Ok(()) } - fn parse(input: &mut Cursor<&[u8]>) -> Result { + fn parse(input: &mut Cursor<&[u8]>, checked: Validation) -> Result { let val = read_bytes(input, 1)?[0]; match val { 0 => Ok(None), - 1 => Ok(Some(T::parse(input)?)), + 1 => Ok(Some(T::parse(input, checked)?)), _ => Err(Error::InvalidOptional), } } @@ -230,8 +248,8 @@ impl Streamable for (T, U) { self.1.stream(out)?; Ok(()) } - fn parse(input: &mut Cursor<&[u8]>) -> Result { - Ok((T::parse(input)?, U::parse(input)?)) + fn parse(input: &mut Cursor<&[u8]>, checked: Validation) -> Result { + Ok((T::parse(input, checked)?, U::parse(input, checked)?)) } } @@ -247,8 +265,12 @@ impl Streamable for (T, U, V) { self.2.stream(out)?; Ok(()) } - fn parse(input: &mut Cursor<&[u8]>) -> Result { - Ok((T::parse(input)?, U::parse(input)?, V::parse(input)?)) + fn parse(input: &mut Cursor<&[u8]>, checked: Validation) -> Result { + Ok(( + T::parse(input, checked)?, + U::parse(input, checked)?, + V::parse(input, checked)?, + )) } } @@ -266,12 +288,12 @@ impl Streamable for self.3.stream(out)?; Ok(()) } - fn parse(input: &mut Cursor<&[u8]>) -> Result { + fn parse(input: &mut Cursor<&[u8]>, checked: Validation) -> Result { Ok(( - T::parse(input)?, - U::parse(input)?, - V::parse(input)?, - W::parse(input)?, + T::parse(input, checked)?, + U::parse(input, checked)?, + V::parse(input, checked)?, + W::parse(input, checked)?, )) } } @@ -281,7 +303,7 @@ impl Streamable for #[cfg(test)] fn from_bytes(buf: &[u8], expected: T) { let mut input = Cursor::<&[u8]>::new(buf); - assert_eq!(T::parse(&mut input).unwrap(), expected); + assert_eq!(T::parse(&mut input, Validation::On).unwrap(), expected); } #[cfg(test)] @@ -290,7 +312,7 @@ fn from_bytes_fail( expected: Error, ) { let mut input = Cursor::<&[u8]>::new(buf); - assert_eq!(T::parse(&mut input).unwrap_err(), expected); + assert_eq!(T::parse(&mut input, Validation::On).unwrap_err(), expected); } #[test] diff --git a/chia_py_streamable_macro/src/lib.rs b/chia_py_streamable_macro/src/lib.rs index 56cc2d1ea..8de19a4d1 100644 --- a/chia_py_streamable_macro/src/lib.rs +++ b/chia_py_streamable_macro/src/lib.rs @@ -26,7 +26,7 @@ pub fn py_streamable_macro(input: proc_macro::TokenStream) -> proc_macro::TokenS impl<'a> pyo3::conversion::FromPyObject<'a> for #ident { fn extract(ob: &'a pyo3::PyAny) -> pyo3::PyResult { let v: u8 = ob.extract()?; - ::parse(&mut std::io::Cursor::<&[u8]>::new(&[v])).map_err(|e| e.into()) + ::parse(&mut std::io::Cursor::<&[u8]>::new(&[v]), #crate_name::Validation::On).map_err(|e| e.into()) } } @@ -153,17 +153,31 @@ pub fn py_streamable_macro(input: proc_macro::TokenStream) -> proc_macro::TokenS ::from_bytes(slice).map_err(|e| <#crate_name::chia_error::Error as Into>::into(e)) } + #[staticmethod] + #[pyo3(name = "from_bytes_unchecked")] + pub fn py_from_bytes_unchecked(blob: pyo3::buffer::PyBuffer) -> pyo3::PyResult { + if !blob.is_c_contiguous() { + panic!("from_bytes_unchecked() must be called with a contiguous buffer"); + } + let slice = unsafe { + std::slice::from_raw_parts(blob.buf_ptr() as *const u8, blob.len_bytes()) + }; + ::from_bytes_unchecked(slice).map_err(|e| <#crate_name::chia_error::Error as Into>::into(e)) + } + // returns the type as well as the number of bytes read from the buffer #[staticmethod] - pub fn parse_rust<'p>(blob: pyo3::buffer::PyBuffer) -> pyo3::PyResult<(Self, u32)> { + #[pyo3(signature= (blob, check_input=true))] + pub fn parse_rust<'p>(blob: pyo3::buffer::PyBuffer, check_input: bool) -> pyo3::PyResult<(Self, u32)> { if !blob.is_c_contiguous() { panic!("parse_rust() must be called with a contiguous buffer"); } let slice = unsafe { std::slice::from_raw_parts(blob.buf_ptr() as *const u8, blob.len_bytes()) }; + let checked = if check_input { #crate_name::Validation::On } else { #crate_name::Validation::Off }; let mut input = std::io::Cursor::<&[u8]>::new(slice); - ::parse(&mut input).map_err(|e| <#crate_name::chia_error::Error as Into>::into(e)).map(|v| (v, input.position() as u32)) + ::parse(&mut input, checked).map_err(|e| <#crate_name::chia_error::Error as Into>::into(e)).map(|v| (v, input.position() as u32)) } pub fn get_hash<'p>(&self, py: pyo3::Python<'p>) -> pyo3::PyResult<&'p pyo3::types::PyBytes> { @@ -226,7 +240,7 @@ pub fn py_json_dict_macro(input: proc_macro::TokenStream) -> proc_macro::TokenSt impl #crate_name::from_json_dict::FromJsonDict for #ident { fn from_json_dict(o: &pyo3::PyAny) -> pyo3::PyResult { let v = ::from_json_dict(o)?; - ::parse(&mut std::io::Cursor::<&[u8]>::new(&[v])).map_err(|e| e.into()) + ::parse(&mut std::io::Cursor::<&[u8]>::new(&[v]), #crate_name::Validation::On).map_err(|e| e.into()) } } } diff --git a/chia_streamable_macro/src/lib.rs b/chia_streamable_macro/src/lib.rs index 2e94e6dcf..0c673db0d 100644 --- a/chia_streamable_macro/src/lib.rs +++ b/chia_streamable_macro/src/lib.rs @@ -64,8 +64,8 @@ pub fn chia_streamable_macro(input: proc_macro::TokenStream) -> proc_macro::Toke fn stream(&self, out: &mut Vec) -> #crate_name::chia_error::Result<()> { ::stream(&(*self as u8), out) } - fn parse(input: &mut std::io::Cursor<&[u8]>) -> #crate_name::chia_error::Result { - let v = ::parse(input)?; + fn parse(input: &mut std::io::Cursor<&[u8]>, checked: #crate_name::Validation) -> #crate_name::chia_error::Result { + let v = ::parse(input, checked)?; match &v { #(#values => Ok(Self::#names),)* _ => Err(#crate_name::chia_error::Error::InvalidEnum), @@ -107,8 +107,8 @@ pub fn chia_streamable_macro(input: proc_macro::TokenStream) -> proc_macro::Toke #(self.#fnames.stream(out)?;)* Ok(()) } - fn parse(input: &mut std::io::Cursor<&[u8]>) -> #crate_name::chia_error::Result { - Ok(Self { #( #fnames: <#ftypes as #crate_name::Streamable>::parse(input)?, )* }) + fn parse(input: &mut std::io::Cursor<&[u8]>, checked: #crate_name::Validation) -> #crate_name::chia_error::Result { + Ok(Self { #( #fnames: <#ftypes as #crate_name::Streamable>::parse(input, checked)?, )* }) } } }; @@ -123,8 +123,8 @@ pub fn chia_streamable_macro(input: proc_macro::TokenStream) -> proc_macro::Toke #(self.#findices.stream(out)?;)* Ok(()) } - fn parse(input: &mut std::io::Cursor<&[u8]>) -> #crate_name::chia_error::Result { - Ok(Self( #( <#ftypes as #crate_name::Streamable>::parse(input)?, )* )) + fn parse(input: &mut std::io::Cursor<&[u8]>, checked: #crate_name::Validation) -> #crate_name::chia_error::Result { + Ok(Self( #( <#ftypes as #crate_name::Streamable>::parse(input, checked)?, )* )) } } }; diff --git a/fuzz/fuzz_targets/fast-forward.rs b/fuzz/fuzz_targets/fast-forward.rs index 47efac326..96bcd4731 100644 --- a/fuzz/fuzz_targets/fast-forward.rs +++ b/fuzz/fuzz_targets/fast-forward.rs @@ -6,7 +6,7 @@ use chia::gen::validation_error::ValidationErr; use chia_protocol::Bytes32; use chia_protocol::Coin; use chia_protocol::CoinSpend; -use chia_traits::streamable::Streamable; +use chia_traits::streamable::{Streamable, Validation}; use clvm_traits::ToClvm; use clvm_utils::tree_hash; use clvmr::serde::node_to_bytes; @@ -16,7 +16,7 @@ use libfuzzer_sys::fuzz_target; use std::io::Cursor; fuzz_target!(|data: &[u8]| { - let Ok(spend) = CoinSpend::parse(&mut Cursor::new(data)) else { + let Ok(spend) = CoinSpend::parse(&mut Cursor::new(data), Validation::On) else { return; }; let new_parents_parent = diff --git a/fuzz/fuzz_targets/run-puzzle.rs b/fuzz/fuzz_targets/run-puzzle.rs index d9a0c7513..173b9b17f 100644 --- a/fuzz/fuzz_targets/run-puzzle.rs +++ b/fuzz/fuzz_targets/run-puzzle.rs @@ -3,7 +3,7 @@ use chia::gen::conditions::MempoolVisitor; use chia::gen::flags::ALLOW_BACKREFS; use chia::gen::run_puzzle::run_puzzle; use chia_protocol::CoinSpend; -use chia_traits::streamable::Streamable; +use chia_traits::streamable::{Streamable, Validation}; use clvmr::Allocator; use libfuzzer_sys::fuzz_target; use std::io::Cursor; @@ -11,7 +11,7 @@ use std::io::Cursor; fuzz_target!(|data: &[u8]| { let mut a = Allocator::new(); - let Ok(spend) = CoinSpend::parse(&mut Cursor::new(data)) else { + let Ok(spend) = CoinSpend::parse(&mut Cursor::new(data), Validation::On) else { return; }; let _ = run_puzzle::( diff --git a/src/fast_forward.rs b/src/fast_forward.rs index 49d20e7ed..9175209a6 100644 --- a/src/fast_forward.rs +++ b/src/fast_forward.rs @@ -190,7 +190,6 @@ mod tests { use hex_literal::hex; use rstest::rstest; use std::fs; - use std::io::Cursor; // this test loads CoinSpends from file (Coin, puzzle, solution)-triples // and "fast-forwards" the spend onto a few different parent-parent coins @@ -208,8 +207,7 @@ mod tests { new_parents_parent: &str, ) { let spend_bytes = fs::read(format!("ff-tests/{spend_file}.spend")).expect("read file"); - let spend = - CoinSpend::parse(&mut Cursor::new(spend_bytes.as_slice())).expect("parse CoinSpend"); + let spend = CoinSpend::from_bytes(&spend_bytes).expect("parse CoinSpend"); let new_parents_parent = hex::decode(new_parents_parent).unwrap(); let mut a = Allocator::new_limited(500000000, 62500000, 62500000); @@ -273,8 +271,7 @@ mod tests { expected_err: Error, ) { let spend_bytes = fs::read("ff-tests/e3c0.spend").expect("read file"); - let mut spend = - CoinSpend::parse(&mut Cursor::new(spend_bytes.as_slice())).expect("parse CoinSpend"); + let mut spend = CoinSpend::from_bytes(&spend_bytes).expect("parse CoinSpend"); let new_parents_parent: &[u8] = &hex!("abababababababababababababababababababababababababababababababab"); diff --git a/wheel/chia_rs.pyi b/wheel/chia_rs.pyi index 8b12895d3..ba8bf25d7 100644 --- a/wheel/chia_rs.pyi +++ b/wheel/chia_rs.pyi @@ -104,7 +104,9 @@ class G1Element: @staticmethod def from_bytes(bytes) -> G1Element: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[G1Element, int]: ... + def from_bytes_unchecked(bytes) -> G1Element: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[G1Element, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -136,7 +138,9 @@ class G2Element: @staticmethod def from_bytes(bytes) -> G2Element: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[G2Element, int]: ... + def from_bytes_unchecked(bytes) -> G2Element: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[G2Element, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -164,7 +168,9 @@ class GTElement: @staticmethod def from_bytes(bytes) -> GTElement: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[GTElement, int]: ... + def from_bytes_unchecked(bytes) -> GTElement: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[GTElement, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -190,7 +196,9 @@ class PrivateKey: @staticmethod def from_bytes(bytes) -> PrivateKey: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[PrivateKey, int]: ... + def from_bytes_unchecked(bytes) -> PrivateKey: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[PrivateKey, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -251,7 +259,9 @@ class Spend: @staticmethod def from_bytes(bytes) -> Spend: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[Spend, int]: ... + def from_bytes_unchecked(bytes) -> Spend: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[Spend, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -294,7 +304,9 @@ class SpendBundleConditions: @staticmethod def from_bytes(bytes) -> SpendBundleConditions: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[SpendBundleConditions, int]: ... + def from_bytes_unchecked(bytes) -> SpendBundleConditions: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[SpendBundleConditions, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -323,7 +335,9 @@ class Message: @staticmethod def from_bytes(bytes) -> Message: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[Message, int]: ... + def from_bytes_unchecked(bytes) -> Message: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[Message, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -358,7 +372,9 @@ class Handshake: @staticmethod def from_bytes(bytes) -> Handshake: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[Handshake, int]: ... + def from_bytes_unchecked(bytes) -> Handshake: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[Handshake, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -389,7 +405,9 @@ class ClassgroupElement: @staticmethod def from_bytes(bytes) -> ClassgroupElement: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[ClassgroupElement, int]: ... + def from_bytes_unchecked(bytes) -> ClassgroupElement: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[ClassgroupElement, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -419,7 +437,9 @@ class Coin: @staticmethod def from_bytes(bytes) -> Coin: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[Coin, int]: ... + def from_bytes_unchecked(bytes) -> Coin: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[Coin, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -448,7 +468,9 @@ class CoinSpend: @staticmethod def from_bytes(bytes) -> CoinSpend: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[CoinSpend, int]: ... + def from_bytes_unchecked(bytes) -> CoinSpend: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[CoinSpend, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -477,7 +499,9 @@ class CoinState: @staticmethod def from_bytes(bytes) -> CoinState: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[CoinState, int]: ... + def from_bytes_unchecked(bytes) -> CoinState: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[CoinState, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -508,7 +532,9 @@ class EndOfSubSlotBundle: @staticmethod def from_bytes(bytes) -> EndOfSubSlotBundle: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[EndOfSubSlotBundle, int]: ... + def from_bytes_unchecked(bytes) -> EndOfSubSlotBundle: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[EndOfSubSlotBundle, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -533,7 +559,9 @@ class FeeRate: @staticmethod def from_bytes(bytes) -> FeeRate: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[FeeRate, int]: ... + def from_bytes_unchecked(bytes) -> FeeRate: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[FeeRate, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -562,7 +590,9 @@ class FeeEstimate: @staticmethod def from_bytes(bytes) -> FeeEstimate: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[FeeEstimate, int]: ... + def from_bytes_unchecked(bytes) -> FeeEstimate: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[FeeEstimate, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -589,7 +619,9 @@ class FeeEstimateGroup: @staticmethod def from_bytes(bytes) -> FeeEstimateGroup: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[FeeEstimateGroup, int]: ... + def from_bytes_unchecked(bytes) -> FeeEstimateGroup: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[FeeEstimateGroup, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -624,7 +656,9 @@ class TransactionsInfo: @staticmethod def from_bytes(bytes) -> TransactionsInfo: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[TransactionsInfo, int]: ... + def from_bytes_unchecked(bytes) -> TransactionsInfo: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[TransactionsInfo, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -659,7 +693,9 @@ class FoliageTransactionBlock: @staticmethod def from_bytes(bytes) -> FoliageTransactionBlock: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[FoliageTransactionBlock, int]: ... + def from_bytes_unchecked(bytes) -> FoliageTransactionBlock: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[FoliageTransactionBlock, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -692,7 +728,9 @@ class FoliageBlockData: @staticmethod def from_bytes(bytes) -> FoliageBlockData: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[FoliageBlockData, int]: ... + def from_bytes_unchecked(bytes) -> FoliageBlockData: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[FoliageBlockData, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -727,7 +765,9 @@ class Foliage: @staticmethod def from_bytes(bytes) -> Foliage: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[Foliage, int]: ... + def from_bytes_unchecked(bytes) -> Foliage: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[Foliage, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -782,7 +822,9 @@ class FullBlock: @staticmethod def from_bytes(bytes) -> FullBlock: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[FullBlock, int]: ... + def from_bytes_unchecked(bytes) -> FullBlock: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[FullBlock, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -836,7 +878,9 @@ class HeaderBlock: @staticmethod def from_bytes(bytes) -> HeaderBlock: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[HeaderBlock, int]: ... + def from_bytes_unchecked(bytes) -> HeaderBlock: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[HeaderBlock, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -863,7 +907,9 @@ class PoolTarget: @staticmethod def from_bytes(bytes) -> PoolTarget: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[PoolTarget, int]: ... + def from_bytes_unchecked(bytes) -> PoolTarget: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[PoolTarget, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -888,7 +934,9 @@ class Program: @staticmethod def from_bytes(bytes) -> Program: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[Program, int]: ... + def from_bytes_unchecked(bytes) -> Program: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[Program, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -923,7 +971,9 @@ class ProofOfSpace: @staticmethod def from_bytes(bytes) -> ProofOfSpace: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[ProofOfSpace, int]: ... + def from_bytes_unchecked(bytes) -> ProofOfSpace: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[ProofOfSpace, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -962,7 +1012,9 @@ class RewardChainBlockUnfinished: @staticmethod def from_bytes(bytes) -> RewardChainBlockUnfinished: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RewardChainBlockUnfinished, int]: ... + def from_bytes_unchecked(bytes) -> RewardChainBlockUnfinished: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RewardChainBlockUnfinished, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1014,7 +1066,9 @@ class RewardChainBlock: @staticmethod def from_bytes(bytes) -> RewardChainBlock: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RewardChainBlock, int]: ... + def from_bytes_unchecked(bytes) -> RewardChainBlock: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RewardChainBlock, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1045,7 +1099,9 @@ class ChallengeBlockInfo: @staticmethod def from_bytes(bytes) -> ChallengeBlockInfo: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[ChallengeBlockInfo, int]: ... + def from_bytes_unchecked(bytes) -> ChallengeBlockInfo: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[ChallengeBlockInfo, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1078,7 +1134,9 @@ class ChallengeChainSubSlot: @staticmethod def from_bytes(bytes) -> ChallengeChainSubSlot: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[ChallengeChainSubSlot, int]: ... + def from_bytes_unchecked(bytes) -> ChallengeChainSubSlot: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[ChallengeChainSubSlot, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1103,7 +1161,9 @@ class InfusedChallengeChainSubSlot: @staticmethod def from_bytes(bytes) -> InfusedChallengeChainSubSlot: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[InfusedChallengeChainSubSlot, int]: ... + def from_bytes_unchecked(bytes) -> InfusedChallengeChainSubSlot: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[InfusedChallengeChainSubSlot, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1134,7 +1194,9 @@ class RewardChainSubSlot: @staticmethod def from_bytes(bytes) -> RewardChainSubSlot: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RewardChainSubSlot, int]: ... + def from_bytes_unchecked(bytes) -> RewardChainSubSlot: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RewardChainSubSlot, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1163,7 +1225,9 @@ class SubSlotProofs: @staticmethod def from_bytes(bytes) -> SubSlotProofs: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[SubSlotProofs, int]: ... + def from_bytes_unchecked(bytes) -> SubSlotProofs: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[SubSlotProofs, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1190,7 +1254,9 @@ class SpendBundle: @staticmethod def from_bytes(bytes) -> SpendBundle: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[SpendBundle, int]: ... + def from_bytes_unchecked(bytes) -> SpendBundle: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[SpendBundle, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1223,7 +1289,9 @@ class SubEpochSummary: @staticmethod def from_bytes(bytes) -> SubEpochSummary: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[SubEpochSummary, int]: ... + def from_bytes_unchecked(bytes) -> SubEpochSummary: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[SubEpochSummary, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1268,7 +1336,9 @@ class UnfinishedBlock: @staticmethod def from_bytes(bytes) -> UnfinishedBlock: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[UnfinishedBlock, int]: ... + def from_bytes_unchecked(bytes) -> UnfinishedBlock: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[UnfinishedBlock, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1297,7 +1367,9 @@ class VDFInfo: @staticmethod def from_bytes(bytes) -> VDFInfo: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[VDFInfo, int]: ... + def from_bytes_unchecked(bytes) -> VDFInfo: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[VDFInfo, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1326,7 +1398,9 @@ class VDFProof: @staticmethod def from_bytes(bytes) -> VDFProof: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[VDFProof, int]: ... + def from_bytes_unchecked(bytes) -> VDFProof: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[VDFProof, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1353,7 +1427,9 @@ class RequestPuzzleSolution: @staticmethod def from_bytes(bytes) -> RequestPuzzleSolution: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RequestPuzzleSolution, int]: ... + def from_bytes_unchecked(bytes) -> RequestPuzzleSolution: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RequestPuzzleSolution, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1384,7 +1460,9 @@ class PuzzleSolutionResponse: @staticmethod def from_bytes(bytes) -> PuzzleSolutionResponse: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[PuzzleSolutionResponse, int]: ... + def from_bytes_unchecked(bytes) -> PuzzleSolutionResponse: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[PuzzleSolutionResponse, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1409,7 +1487,9 @@ class RespondPuzzleSolution: @staticmethod def from_bytes(bytes) -> RespondPuzzleSolution: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RespondPuzzleSolution, int]: ... + def from_bytes_unchecked(bytes) -> RespondPuzzleSolution: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RespondPuzzleSolution, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1436,7 +1516,9 @@ class RejectPuzzleSolution: @staticmethod def from_bytes(bytes) -> RejectPuzzleSolution: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RejectPuzzleSolution, int]: ... + def from_bytes_unchecked(bytes) -> RejectPuzzleSolution: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RejectPuzzleSolution, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1461,7 +1543,9 @@ class SendTransaction: @staticmethod def from_bytes(bytes) -> SendTransaction: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[SendTransaction, int]: ... + def from_bytes_unchecked(bytes) -> SendTransaction: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[SendTransaction, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1490,7 +1574,9 @@ class TransactionAck: @staticmethod def from_bytes(bytes) -> TransactionAck: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[TransactionAck, int]: ... + def from_bytes_unchecked(bytes) -> TransactionAck: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[TransactionAck, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1521,7 +1607,9 @@ class NewPeakWallet: @staticmethod def from_bytes(bytes) -> NewPeakWallet: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[NewPeakWallet, int]: ... + def from_bytes_unchecked(bytes) -> NewPeakWallet: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[NewPeakWallet, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1546,7 +1634,9 @@ class RequestBlockHeader: @staticmethod def from_bytes(bytes) -> RequestBlockHeader: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RequestBlockHeader, int]: ... + def from_bytes_unchecked(bytes) -> RequestBlockHeader: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RequestBlockHeader, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1571,7 +1661,9 @@ class RespondBlockHeader: @staticmethod def from_bytes(bytes) -> RespondBlockHeader: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RespondBlockHeader, int]: ... + def from_bytes_unchecked(bytes) -> RespondBlockHeader: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RespondBlockHeader, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1596,7 +1688,9 @@ class RejectHeaderRequest: @staticmethod def from_bytes(bytes) -> RejectHeaderRequest: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RejectHeaderRequest, int]: ... + def from_bytes_unchecked(bytes) -> RejectHeaderRequest: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RejectHeaderRequest, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1625,7 +1719,9 @@ class RequestRemovals: @staticmethod def from_bytes(bytes) -> RequestRemovals: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RequestRemovals, int]: ... + def from_bytes_unchecked(bytes) -> RequestRemovals: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RequestRemovals, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1656,7 +1752,9 @@ class RespondRemovals: @staticmethod def from_bytes(bytes) -> RespondRemovals: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RespondRemovals, int]: ... + def from_bytes_unchecked(bytes) -> RespondRemovals: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RespondRemovals, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1683,7 +1781,9 @@ class RejectRemovalsRequest: @staticmethod def from_bytes(bytes) -> RejectRemovalsRequest: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RejectRemovalsRequest, int]: ... + def from_bytes_unchecked(bytes) -> RejectRemovalsRequest: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RejectRemovalsRequest, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1712,7 +1812,9 @@ class RequestAdditions: @staticmethod def from_bytes(bytes) -> RequestAdditions: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RequestAdditions, int]: ... + def from_bytes_unchecked(bytes) -> RequestAdditions: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RequestAdditions, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1743,7 +1845,9 @@ class RespondAdditions: @staticmethod def from_bytes(bytes) -> RespondAdditions: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RespondAdditions, int]: ... + def from_bytes_unchecked(bytes) -> RespondAdditions: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RespondAdditions, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1770,7 +1874,9 @@ class RejectAdditionsRequest: @staticmethod def from_bytes(bytes) -> RejectAdditionsRequest: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RejectAdditionsRequest, int]: ... + def from_bytes_unchecked(bytes) -> RejectAdditionsRequest: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RejectAdditionsRequest, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1799,7 +1905,9 @@ class RespondBlockHeaders: @staticmethod def from_bytes(bytes) -> RespondBlockHeaders: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RespondBlockHeaders, int]: ... + def from_bytes_unchecked(bytes) -> RespondBlockHeaders: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RespondBlockHeaders, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1826,7 +1934,9 @@ class RejectBlockHeaders: @staticmethod def from_bytes(bytes) -> RejectBlockHeaders: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RejectBlockHeaders, int]: ... + def from_bytes_unchecked(bytes) -> RejectBlockHeaders: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RejectBlockHeaders, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1855,7 +1965,9 @@ class RequestBlockHeaders: @staticmethod def from_bytes(bytes) -> RequestBlockHeaders: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RequestBlockHeaders, int]: ... + def from_bytes_unchecked(bytes) -> RequestBlockHeaders: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RequestBlockHeaders, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1882,7 +1994,9 @@ class RequestHeaderBlocks: @staticmethod def from_bytes(bytes) -> RequestHeaderBlocks: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RequestHeaderBlocks, int]: ... + def from_bytes_unchecked(bytes) -> RequestHeaderBlocks: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RequestHeaderBlocks, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1909,7 +2023,9 @@ class RejectHeaderBlocks: @staticmethod def from_bytes(bytes) -> RejectHeaderBlocks: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RejectHeaderBlocks, int]: ... + def from_bytes_unchecked(bytes) -> RejectHeaderBlocks: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RejectHeaderBlocks, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1938,7 +2054,9 @@ class RespondHeaderBlocks: @staticmethod def from_bytes(bytes) -> RespondHeaderBlocks: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RespondHeaderBlocks, int]: ... + def from_bytes_unchecked(bytes) -> RespondHeaderBlocks: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RespondHeaderBlocks, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1965,7 +2083,9 @@ class RegisterForPhUpdates: @staticmethod def from_bytes(bytes) -> RegisterForPhUpdates: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RegisterForPhUpdates, int]: ... + def from_bytes_unchecked(bytes) -> RegisterForPhUpdates: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RegisterForPhUpdates, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -1994,7 +2114,9 @@ class RespondToPhUpdates: @staticmethod def from_bytes(bytes) -> RespondToPhUpdates: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RespondToPhUpdates, int]: ... + def from_bytes_unchecked(bytes) -> RespondToPhUpdates: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RespondToPhUpdates, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -2021,7 +2143,9 @@ class RegisterForCoinUpdates: @staticmethod def from_bytes(bytes) -> RegisterForCoinUpdates: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RegisterForCoinUpdates, int]: ... + def from_bytes_unchecked(bytes) -> RegisterForCoinUpdates: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RegisterForCoinUpdates, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -2050,7 +2174,9 @@ class RespondToCoinUpdates: @staticmethod def from_bytes(bytes) -> RespondToCoinUpdates: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RespondToCoinUpdates, int]: ... + def from_bytes_unchecked(bytes) -> RespondToCoinUpdates: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RespondToCoinUpdates, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -2081,7 +2207,9 @@ class CoinStateUpdate: @staticmethod def from_bytes(bytes) -> CoinStateUpdate: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[CoinStateUpdate, int]: ... + def from_bytes_unchecked(bytes) -> CoinStateUpdate: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[CoinStateUpdate, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -2106,7 +2234,9 @@ class RequestChildren: @staticmethod def from_bytes(bytes) -> RequestChildren: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RequestChildren, int]: ... + def from_bytes_unchecked(bytes) -> RequestChildren: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RequestChildren, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -2131,7 +2261,9 @@ class RespondChildren: @staticmethod def from_bytes(bytes) -> RespondChildren: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RespondChildren, int]: ... + def from_bytes_unchecked(bytes) -> RespondChildren: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RespondChildren, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -2158,7 +2290,9 @@ class RequestSesInfo: @staticmethod def from_bytes(bytes) -> RequestSesInfo: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RequestSesInfo, int]: ... + def from_bytes_unchecked(bytes) -> RequestSesInfo: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RequestSesInfo, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -2185,7 +2319,9 @@ class RespondSesInfo: @staticmethod def from_bytes(bytes) -> RespondSesInfo: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RespondSesInfo, int]: ... + def from_bytes_unchecked(bytes) -> RespondSesInfo: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RespondSesInfo, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -2210,7 +2346,9 @@ class RequestFeeEstimates: @staticmethod def from_bytes(bytes) -> RequestFeeEstimates: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RequestFeeEstimates, int]: ... + def from_bytes_unchecked(bytes) -> RequestFeeEstimates: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RequestFeeEstimates, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -2235,7 +2373,9 @@ class RespondFeeEstimates: @staticmethod def from_bytes(bytes) -> RespondFeeEstimates: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[RespondFeeEstimates, int]: ... + def from_bytes_unchecked(bytes) -> RespondFeeEstimates: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[RespondFeeEstimates, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -2286,7 +2426,9 @@ class SubSlotData: @staticmethod def from_bytes(bytes) -> SubSlotData: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[SubSlotData, int]: ... + def from_bytes_unchecked(bytes) -> SubSlotData: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[SubSlotData, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -2315,7 +2457,9 @@ class SubEpochChallengeSegment: @staticmethod def from_bytes(bytes) -> SubEpochChallengeSegment: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[SubEpochChallengeSegment, int]: ... + def from_bytes_unchecked(bytes) -> SubEpochChallengeSegment: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[SubEpochChallengeSegment, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... @@ -2340,7 +2484,9 @@ class SubEpochSegments: @staticmethod def from_bytes(bytes) -> SubEpochSegments: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[SubEpochSegments, int]: ... + def from_bytes_unchecked(bytes) -> SubEpochSegments: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[SubEpochSegments, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ... diff --git a/wheel/generate_type_stubs.py b/wheel/generate_type_stubs.py index 2c427733b..642073e8f 100644 --- a/wheel/generate_type_stubs.py +++ b/wheel/generate_type_stubs.py @@ -48,7 +48,9 @@ def __copy__(self) -> {name}: ... @staticmethod def from_bytes(bytes) -> {name}: ... @staticmethod - def parse_rust(ReadableBuffer) -> Tuple[{name}, int]: ... + def from_bytes_unchecked(bytes) -> {name}: ... + @staticmethod + def parse_rust(ReadableBuffer, bool = True) -> Tuple[{name}, int]: ... def to_bytes(self) -> bytes: ... def __bytes__(self) -> bytes: ... def stream_to_bytes(self) -> bytes: ...