Skip to content

Commit

Permalink
Merge pull request #405 from Chia-Network/bump-clvm-0.6.0
Browse files Browse the repository at this point in the history
Bump clvm 0.6.0
  • Loading branch information
arvidn committed Feb 15, 2024
2 parents 5b1b20a + b9a92c3 commit deec42d
Show file tree
Hide file tree
Showing 29 changed files with 172 additions and 153 deletions.
4 changes: 2 additions & 2 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 @@ -35,7 +35,7 @@ repository = "https://github.com/Chia-Network/chia_rs/"
py-bindings = ["dep:pyo3"]

[dependencies]
clvmr = "0.5.0"
clvmr = "0.6.0"
hex = "0.4.3"
pyo3 = { version = ">=0.19.0", optional = true }
clvm-utils = { version = "0.5.1", path = "clvm-utils" }
Expand Down
2 changes: 1 addition & 1 deletion chia-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sha2 = "0.10.8"
hex = "0.4.3"
chia_streamable_macro = { version = "0.3.0", path = "../chia_streamable_macro" }
chia_py_streamable_macro = { version = "0.5.1", path = "../chia_py_streamable_macro", optional = true }
clvmr = "0.5.0"
clvmr = "0.6.0"
chia-traits = { version = "0.5.1", path = "../chia-traits" }
clvm-traits = { version = "0.5.1", path = "../clvm-traits", features = ["derive"] }
clvm-utils = { version = "0.5.1", path = "../clvm-utils" }
Expand Down
2 changes: 1 addition & 1 deletion chia-protocol/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
clvmr = "0.5.0"
clvmr = "0.6.0"
chia-traits = { path = "../../chia-traits" }
clvm-traits = { path = "../../clvm-traits" }
arbitrary = { version = "=1.3.0" }
Expand Down
4 changes: 2 additions & 2 deletions chia-protocol/fuzz/fuzz_targets/spend-bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ fuzz_target!(|data: &[u8]| {
let op = first(&a, c).expect("first");
let c = rest(&a, c).expect("rest");
let buf = a.atom(op);
if buf.len() != 1 {
if buf.as_ref().len() != 1 {
continue;
}
if buf[0] == 51 {
if buf.as_ref()[0] == 51 {
let (puzzle_hash, (amount, _)) =
<(Bytes32, (u64, NodePtr))>::from_clvm(&a, c).expect("parse spend");
expected.insert(Coin {
Expand Down
8 changes: 4 additions & 4 deletions chia-protocol/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<N> ToClvm<N> for Bytes {
impl<N> FromClvm<N> for Bytes {
fn from_clvm(decoder: &impl ClvmDecoder<Node = N>, node: N) -> Result<Self, FromClvmError> {
let bytes = decoder.decode_atom(&node)?;
Ok(Self(bytes.to_vec()))
Ok(Self(bytes.as_ref().to_vec()))
}
}

Expand Down Expand Up @@ -247,13 +247,13 @@ impl<N, const LEN: usize> ToClvm<N> for BytesImpl<LEN> {
impl<N, const LEN: usize> FromClvm<N> for BytesImpl<LEN> {
fn from_clvm(decoder: &impl ClvmDecoder<Node = N>, node: N) -> Result<Self, FromClvmError> {
let bytes = decoder.decode_atom(&node)?;
if bytes.len() != LEN {
if bytes.as_ref().len() != LEN {
return Err(FromClvmError::WrongAtomLength {
expected: LEN,
found: bytes.len(),
found: bytes.as_ref().len(),
});
}
Ok(Self::try_from(bytes).unwrap())
Ok(Self::try_from(bytes.as_ref()).unwrap())
}
}

Expand Down
2 changes: 1 addition & 1 deletion chia-protocol/src/lazy_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl LazyNode {
#[getter(atom)]
pub fn atom(&self, py: Python) -> Option<PyObject> {
match &self.allocator.sexp(self.node) {
SExp::Atom => Some(PyBytes::new(py, self.allocator.atom(self.node)).into()),
SExp::Atom => Some(PyBytes::new(py, self.allocator.atom(self.node).as_ref()).into()),
_ => None,
}
}
Expand Down
1 change: 1 addition & 0 deletions chia-protocol/src/spend_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl SpendBundle {
return Err(EvalErr(op, "invalid condition".to_string()));
}
};
let buf = buf.as_ref();
if buf.len() != 1 {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion chia-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ clvm-utils = { version = "0.5.1", path = "../clvm-utils" }
clvm-traits = { version = "0.5.2", path = "../clvm-traits" }
chia-wallet = { version = "0.5.1", path = "../chia-wallet" }
chia-bls = { version = "0.5.1", path = "../chia-bls" }
clvmr = { version = "0.5.0", features = ["counters"] }
clvmr = { version = "0.6.0", features = ["counters"] }
chia = { version = "0.5.2", path = ".." }
rusqlite = { version = "0.30.0", features = ["bundled"] }
clap = { version = "4.3.9", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion chia-tools/src/visit_spends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub fn visit_spends<
let [parent_id, puzzle, amount, solution, _spend_level_extra] =
extract_n::<5>(a, spend, ErrorCode::InvalidCondition)?;
let amount: u64 = a.number(amount).try_into().expect("invalid amount");
let parent_id = Bytes32::try_from(a.atom(parent_id)).unwrap();
let parent_id = Bytes32::try_from(a.atom(parent_id).as_ref()).unwrap();
callback(a, parent_id, amount, puzzle, solution);
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion chia-wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ homepage = "https://github.com/Chia-Network/chia_rs/chia-wallet/"
repository = "https://github.com/Chia-Network/chia_rs/chia-wallet/"

[dependencies]
clvmr = "0.5.0"
clvmr = "0.6.0"
sha2 = "0.10.8"
num-bigint = "0.4.3"
hex-literal = "0.4.1"
Expand Down
2 changes: 1 addition & 1 deletion chia-wallet/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
clvmr = "0.5.0"
clvmr = "0.6.0"
pyo3 = { version = ">=0.19.0", features = ["auto-initialize"]}
chia-wallet = { path = ".." }
clvm-traits = { version = "0.5.2", path = "../../clvm-traits" }
Expand Down
2 changes: 1 addition & 1 deletion clvm-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ py-bindings = ["dep:pyo3"]

[dependencies]
pyo3 = { version = ">=0.19.0", optional = true }
clvmr = "0.5.0"
clvmr = "0.6.0"
clvm-derive = { version = "0.5.2", path = "../clvm-derive", optional = true }
chia-bls = { version = "0.5.1", path = "../chia-bls", optional = true }
num-bigint = "0.4.3"
Expand Down
6 changes: 3 additions & 3 deletions clvm-traits/src/clvm_decoder.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use clvmr::{allocator::SExp, Allocator, NodePtr};
use clvmr::{allocator::SExp, Allocator, Atom, NodePtr};

use crate::{FromClvm, FromClvmError};

pub trait ClvmDecoder {
type Node: Clone;

fn decode_atom(&self, node: &Self::Node) -> Result<&[u8], FromClvmError>;
fn decode_atom(&self, node: &Self::Node) -> Result<Atom, FromClvmError>;
fn decode_pair(&self, node: &Self::Node) -> Result<(Self::Node, Self::Node), FromClvmError>;

/// This is a helper function that just calls `clone` on the node.
Expand All @@ -19,7 +19,7 @@ pub trait ClvmDecoder {
impl ClvmDecoder for Allocator {
type Node = NodePtr;

fn decode_atom(&self, node: &Self::Node) -> Result<&[u8], FromClvmError> {
fn decode_atom(&self, node: &Self::Node) -> Result<Atom, FromClvmError> {
if let SExp::Atom = self.sexp(*node) {
Ok(self.atom(*node))
} else {
Expand Down
39 changes: 20 additions & 19 deletions clvm-traits/src/from_clvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ macro_rules! clvm_primitive {
const LEN: usize = std::mem::size_of::<$primitive>();

let bytes = decoder.decode_atom(&node)?;
let number = BigInt::from_signed_bytes_be(bytes);
let number = BigInt::from_signed_bytes_be(bytes.as_ref());
let (sign, mut vec) = number.to_bytes_be();

if vec.len() < std::mem::size_of::<$primitive>() {
Expand All @@ -28,7 +28,7 @@ macro_rules! clvm_primitive {
let value = <$primitive>::from_be_bytes(vec.as_slice().try_into().or(Err(
FromClvmError::WrongAtomLength {
expected: LEN,
found: bytes.len(),
found: bytes.as_ref().len(),
},
))?);

Expand Down Expand Up @@ -71,12 +71,12 @@ where
impl<N> FromClvm<N> for () {
fn from_clvm(decoder: &impl ClvmDecoder<Node = N>, node: N) -> Result<Self, FromClvmError> {
let bytes = decoder.decode_atom(&node)?;
if bytes.is_empty() {
if bytes.as_ref().is_empty() {
Ok(())
} else {
Err(FromClvmError::WrongAtomLength {
expected: 0,
found: bytes.len(),
found: bytes.as_ref().len(),
})
}
}
Expand All @@ -98,12 +98,12 @@ where
}
} else {
let bytes = decoder.decode_atom(&node)?;
if bytes.is_empty() {
if bytes.as_ref().is_empty() {
return items.try_into().or(Err(FromClvmError::ExpectedPair));
} else {
return Err(FromClvmError::WrongAtomLength {
expected: 0,
found: bytes.len(),
found: bytes.as_ref().len(),
});
}
}
Expand All @@ -123,12 +123,12 @@ where
node = rest;
} else {
let bytes = decoder.decode_atom(&node)?;
if bytes.is_empty() {
if bytes.as_ref().is_empty() {
return Ok(items);
} else {
return Err(FromClvmError::WrongAtomLength {
expected: 0,
found: bytes.len(),
found: bytes.as_ref().len(),
});
}
}
Expand All @@ -141,18 +141,19 @@ where
T: FromClvm<N>,
{
fn from_clvm(decoder: &impl ClvmDecoder<Node = N>, node: N) -> Result<Self, FromClvmError> {
if let Ok(&[]) = decoder.decode_atom(&node) {
Ok(None)
} else {
Ok(Some(T::from_clvm(decoder, node)?))
if let Ok(atom) = decoder.decode_atom(&node) {
if atom.as_ref().is_empty() {
return Ok(None);
}
}
Ok(Some(T::from_clvm(decoder, node)?))
}
}

impl<N> FromClvm<N> for String {
fn from_clvm(decoder: &impl ClvmDecoder<Node = N>, node: N) -> Result<Self, FromClvmError> {
let bytes = decoder.decode_atom(&node)?;
Ok(Self::from_utf8(bytes.to_vec())?)
Ok(Self::from_utf8(bytes.as_ref().to_vec())?)
}
}

Expand All @@ -162,10 +163,10 @@ impl<N> FromClvm<N> for chia_bls::PublicKey {
let bytes = decoder.decode_atom(&node)?;
let error = Err(FromClvmError::WrongAtomLength {
expected: 48,
found: bytes.len(),
found: bytes.as_ref().len(),
});
let bytes = bytes.try_into().or(error)?;
Self::from_bytes(bytes).map_err(|error| FromClvmError::Custom(error.to_string()))
let bytes: [u8; 48] = bytes.as_ref().try_into().or(error)?;
Self::from_bytes(&bytes).map_err(|error| FromClvmError::Custom(error.to_string()))
}
}

Expand All @@ -175,10 +176,10 @@ impl<N> FromClvm<N> for chia_bls::Signature {
let bytes = decoder.decode_atom(&node)?;
let error = Err(FromClvmError::WrongAtomLength {
expected: 96,
found: bytes.len(),
found: bytes.as_ref().len(),
});
let bytes = bytes.try_into().or(error)?;
Self::from_bytes(bytes).map_err(|error| FromClvmError::Custom(error.to_string()))
let bytes: [u8; 96] = bytes.as_ref().try_into().or(error)?;
Self::from_bytes(&bytes).map_err(|error| FromClvmError::Custom(error.to_string()))
}
}

Expand Down
2 changes: 1 addition & 1 deletion clvm-traits/src/match_byte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<N, const BYTE: u8> ToClvm<N> for MatchByte<BYTE> {

impl<N, const BYTE: u8> FromClvm<N> for MatchByte<BYTE> {
fn from_clvm(decoder: &impl ClvmDecoder<Node = N>, node: N) -> Result<Self, FromClvmError> {
match decoder.decode_atom(&node)? {
match decoder.decode_atom(&node)?.as_ref() {
[] if BYTE == 0 => Ok(Self),
[byte] if *byte == BYTE && BYTE > 0 => Ok(Self),
_ => Err(FromClvmError::Custom(format!(
Expand Down
2 changes: 1 addition & 1 deletion clvm-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ homepage = "https://github.com/Chia-Network/chia_rs/"
repository = "https://github.com/Chia-Network/chia_rs/clvm-utils"

[dependencies]
clvmr = "0.5.0"
clvmr = "0.6.0"
clvm-traits = { version = "0.5.1", path = "../clvm-traits" }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion clvm-utils/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
clvmr = "=0.5.0"
clvmr = "=0.6.0"
chia-fuzz = { path = "../../fuzz" }
clvm-utils = { path = ".." }
clvm-traits = { path = "../../clvm-traits" }
Expand Down
2 changes: 1 addition & 1 deletion clvm-utils/src/tree_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn tree_hash(a: &Allocator, node: NodePtr) -> [u8; 32] {
match op {
TreeOp::SExp(node) => match a.sexp(node) {
SExp::Atom => {
hashes.push(tree_hash_atom(a.atom(node)));
hashes.push(tree_hash_atom(a.atom(node).as_ref()));
}
SExp::Pair(left, right) => {
ops.push(TreeOp::Cons);
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
clvmr = "0.5.0"
clvmr = "0.6.0"
clvm-utils = { path = "../clvm-utils" }
clvm-traits = { path = "../clvm-traits" }
chia-protocol = { path = "../chia-protocol" }
Expand Down
4 changes: 2 additions & 2 deletions src/gen/condition_sanitizers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn sanitize_hash(
) -> Result<NodePtr, ValidationErr> {
let buf = atom(a, n, code)?;

if buf.len() != size {
if buf.as_ref().len() != size {
Err(ValidationErr(n, code))
} else {
Ok(n)
Expand All @@ -33,7 +33,7 @@ pub fn sanitize_announce_msg(
) -> Result<NodePtr, ValidationErr> {
let buf = atom(a, n, code)?;

if buf.len() > 1024 {
if buf.as_ref().len() > 1024 {
Err(ValidationErr(n, code))
} else {
Ok(n)
Expand Down
Loading

0 comments on commit deec42d

Please sign in to comment.