Skip to content

Commit

Permalink
Merge pull request #115 from Chia-Network/update-clvmr
Browse files Browse the repository at this point in the history
Update clvmr to 0.8.0
  • Loading branch information
prozacchiwawa committed Sep 16, 2024
2 parents b483e03 + fd8bed2 commit 4a070f2
Show file tree
Hide file tree
Showing 26 changed files with 310 additions and 290 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ resources/tests/game-referee/*.sym
resources/tests/game-referee/*.clvm.hex
__pycache__
.pytest_cache
main.sym
venv/
154 changes: 67 additions & 87 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 @@ -31,7 +31,7 @@ do-notation = "0.1.3"
serde_json = "1.0"
sha2 = "0.9.5"
tempfile = "3.3.0"
clvmr = { version = "=0.3.3", features = ["pre-eval"] }
clvmr = { version = "0.8.0", features = ["pre-eval"] }
binascii = "0.1.4"
yaml-rust = "0.4"
linked-hash-map = "0.5.6"
Expand Down
10 changes: 3 additions & 7 deletions src/classic/clvm/casts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clvm_rs::NodePtr;
use num_bigint::ToBigInt;

use clvm_rs::allocator::Allocator;
use clvm_rs::reduction::EvalErr;

use crate::classic::clvm::__type_compatibility__::{
Expand All @@ -12,16 +12,12 @@ pub struct TConvertOption {
pub signed: bool,
}

pub fn int_from_bytes(
allocator: &Allocator,
b: Bytes,
option: Option<TConvertOption>,
) -> Result<u64, EvalErr> {
pub fn int_from_bytes(b: Bytes, option: Option<TConvertOption>) -> Result<u64, EvalErr> {
if b.length() == 0 {
return Ok(0);
} else if b.length() * 8 > 64 {
return Err(EvalErr(
allocator.null(),
NodePtr::NIL,
"Cannot convert Bytes to Integer larger than 64bit. Use bigint_from_bytes instead."
.to_string(),
));
Expand Down
17 changes: 9 additions & 8 deletions src/classic/clvm/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ impl<'a> Iterator for SExpToBytesIterator<'a> {
SExp::Atom => {
// The only node we have in scope is x, so this atom
// capture is trivial.
let buf = self.allocator.atom(x).to_vec();
let atom = self.allocator.atom(x);
let buf = atom.as_ref().to_vec();
let bytes = Bytes::new(Some(BytesFromType::Raw(buf.clone())));
match atom_size_blob(&bytes) {
Ok((original, b)) => {
Expand Down Expand Up @@ -184,7 +185,7 @@ impl OpStackEntry for OpReadSexp {
) -> Option<EvalErr> {
let blob = f.read(1);
if blob.length() == 0 {
return Some(EvalErr(allocator.null(), "bad encoding".to_string()));
return Some(EvalErr(NodePtr::NIL, "bad encoding".to_string()));
}

let b = blob.at(0);
Expand Down Expand Up @@ -236,7 +237,7 @@ pub fn sexp_from_stream<'a>(
}

Err(EvalErr(
allocator.null(),
NodePtr::NIL,
"No value left after conversion".to_string(),
))
}
Expand All @@ -250,7 +251,7 @@ pub fn atom_from_stream<'a>(
let mut b = b_;

if b == 0x80 {
return Ok(allocator.null());
return Ok(NodePtr::NIL);
} else if b <= MAX_SINGLE_BYTE as u8 {
return allocator.new_atom(&[b]);
}
Expand All @@ -268,17 +269,17 @@ pub fn atom_from_stream<'a>(
if bit_count > 1 {
let bin = f.read(bit_count - 1);
if bin.length() != bit_count - 1 {
return Err(EvalErr(allocator.null(), "bad encoding".to_string()));
return Err(EvalErr(NodePtr::NIL, "bad encoding".to_string()));
}
size_blob = size_blob.concat(&bin);
}
int_from_bytes(allocator, size_blob, None).and_then(|size| {
int_from_bytes(size_blob, None).and_then(|size| {
if size >= 0x400000000 {
return Err(EvalErr(allocator.null(), "blob too large".to_string()));
return Err(EvalErr(NodePtr::NIL, "blob too large".to_string()));
}
let blob = f.read(size as usize);
if blob.length() != size as usize {
return Err(EvalErr(allocator.null(), "bad encoding".to_string()));
return Err(EvalErr(NodePtr::NIL, "bad encoding".to_string()));
}
return allocator.new_atom(blob.data());
})
Expand Down
Loading

0 comments on commit 4a070f2

Please sign in to comment.