Skip to content

Commit

Permalink
Merge branch 'refactor/range-naming'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Aug 12, 2024
2 parents dfdf981 + e819503 commit a67bf6a
Show file tree
Hide file tree
Showing 29 changed files with 747 additions and 559 deletions.
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/boc_decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fuzz_target!(|data: &[u8]| {
_ = slice.get_u64(0);
_ = slice.get_u128(0);
_ = slice.get_u256(0);
if slice.try_advance(3, 0) {
if slice.skip_first(3, 0).is_ok() {
_ = slice.get_u8(0);
_ = slice.get_u16(0);
_ = slice.get_u32(0);
Expand Down
9 changes: 4 additions & 5 deletions src/abi/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use sha2::Digest;
use crate::abi::value::ser::AbiSerializer;
use crate::abi::AbiHeader;
use crate::cell::{
Cell, CellBuilder, CellFamily, CellSlice, CellSliceRange, CellSliceSize, DynCell, HashBytes,
Store,
Cell, CellBuilder, CellFamily, CellSlice, CellSliceRange, DynCell, HashBytes, Size, Store,
};
use crate::dict::RawDict;
use crate::models::{
Expand Down Expand Up @@ -494,7 +493,7 @@ impl Function {
} else {
// Skip signature
if slice.load_bit()? {
slice.advance(512, 0)?;
slice.skip_first(512, 0)?;
}
// Skip headers
ok!(AbiHeader::skip_all(&self.headers, slice));
Expand Down Expand Up @@ -732,7 +731,7 @@ impl<'f, 'a> ExternalInput<'f, 'a> {
if reserve_signature {
serializer.add_offset(if abi_version.major == 1 {
// Reserve reference for signature
CellSliceSize { bits: 0, refs: 1 }
Size { bits: 0, refs: 1 }
} else {
let bits = if abi_version >= AbiVersion::V2_3 {
// Reserve only for address as it also ensures the the signature will fit
Expand All @@ -741,7 +740,7 @@ impl<'f, 'a> ExternalInput<'f, 'a> {
// Reserve for `Some` non-empty signature
1 + 512
};
CellSliceSize { bits, refs: 0 }
Size { bits, refs: 0 }
});
}

Expand Down
18 changes: 9 additions & 9 deletions src/abi/value/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,17 @@ impl AbiHeader {
match ty {
AbiHeaderType::Time => {
ok!(preload_bits(64, slice));
slice.advance(64, 0)?;
slice.skip_first(64, 0)?;
}
AbiHeaderType::Expire => {
ok!(preload_bits(32, slice));
slice.advance(32, 0)?;
slice.skip_first(32, 0)?;
}
AbiHeaderType::PublicKey => {
ok!(preload_bits(1, slice));
if slice.load_bit()? {
ok!(preload_bits(256, slice));
slice.advance(256, 0)?;
slice.skip_first(256, 0)?;
}
}
}
Expand Down Expand Up @@ -315,7 +315,7 @@ fn preload_bits(bits: u16, slice: &mut CellSlice) -> Result<()> {
return Ok(());
}

let remaining_bits = slice.remaining_bits();
let remaining_bits = slice.size_bits();
if remaining_bits == 0 {
let first_ref = slice.load_reference_as_slice()?;

Expand Down Expand Up @@ -415,9 +415,9 @@ fn load_varuint_raw(size: NonZeroU8, slice: &mut CellSlice) -> Result<Vec<u8>> {
}

fn load_cell(version: AbiVersion, last: bool, slice: &mut CellSlice) -> Result<Cell> {
if slice.remaining_refs() == 1
if slice.size_refs() == 1
&& (version.major == 1 && slice.cell().reference_count() as usize == MAX_REF_COUNT
|| version.major > 1 && !last && slice.remaining_bits() == 0)
|| version.major > 1 && !last && slice.size_bits() == 0)
{
*slice = slice.load_reference_as_slice()?;
}
Expand Down Expand Up @@ -796,7 +796,7 @@ mod tests {
// 4 refs with empty cells
let cell = Boc::decode_base64("te6ccgEBAgEACAAEAAEBAQEAAA==")?;
let slice = &mut cell.as_slice()?;
slice.try_advance(0, 3);
slice.skip_first(0, 3)?;

assert_basic_err!(
AbiValue::load(&AbiType::Cell, AbiVersion::V1_0, slice),
Expand All @@ -806,7 +806,7 @@ mod tests {
// 3 refs with empty cells + last ref with a cell with 1 ref
let cell = Boc::decode_base64("te6ccgEBAwEACwAEAAICAgEBAAIAAA==")?;
let slice = &mut cell.as_slice()?;
slice.try_advance(0, 3);
slice.skip_first(0, 3)?;

assert_eq!(
AbiValue::load(&AbiType::Cell, AbiVersion::V1_0, slice)?,
Expand All @@ -825,7 +825,7 @@ mod tests {
// 4 refs with empty cells
let cell = Boc::decode_base64("te6ccgEBAgEACAAEAAEBAQEAAA==")?;
let slice = &mut cell.as_slice()?;
slice.try_advance(0, 3);
slice.skip_first(0, 3)?;

assert_eq!(
AbiValue::load(&AbiType::Cell, v, slice)?,
Expand Down
Loading

0 comments on commit a67bf6a

Please sign in to comment.