Skip to content

Commit

Permalink
fixed usize serialization in ByteWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
irakliyk committed Jun 24, 2024
1 parent 0caa34b commit 619525f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
16 changes: 8 additions & 8 deletions air/src/air/assertions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ const NO_STRIDE: usize = 0;
/// 1. **Single** assertion - which requires that a value in a single cell of an execution trace
/// is equal to the specified value.
/// 2. **Periodic** assertion - which requires that values in multiple cells of a single column
/// are equal to the specified value. The cells must be evenly spaced at intervals with lengths
/// equal to powers of two. For example, we can specify that values in a column must be equal
/// to 0 at steps 0, 8, 16, 24, 32 etc. Steps can also start at some offset - e.g., 1, 9, 17,
/// 25, 33 is also a valid sequence of steps.
/// are equal to the specified value. The cells must be evenly spaced at intervals with lengths
/// equal to powers of two. For example, we can specify that values in a column must be equal
/// to 0 at steps 0, 8, 16, 24, 32 etc. Steps can also start at some offset - e.g., 1, 9, 17,
/// 25, 33 is also a valid sequence of steps.
/// 3. **Sequence** assertion - which requires that multiple cells in a single column are equal
/// to the values from the provided list. The cells must be evenly spaced at intervals with
/// lengths equal to powers of two. For example, we can specify that values in a column must
/// be equal to a sequence 1, 2, 3, 4 at steps 0, 8, 16, 24. That is, value at step 0 should be
/// equal to 1, value at step 8 should be equal to 2 etc.
/// to the values from the provided list. The cells must be evenly spaced at intervals with
/// lengths equal to powers of two. For example, we can specify that values in a column must
/// be equal to a sequence 1, 2, 3, 4 at steps 0, 8, 16, 24. That is, value at step 0 should be
/// equal to 1, value at step 8 should be equal to 2 etc.
///
/// Note that single and periodic assertions are succinct. That is, a verifier can evaluate them
/// very efficiently. However, sequence assertions have liner complexity in the number of
Expand Down
2 changes: 1 addition & 1 deletion air/src/air/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl<B: StarkField> AirContext<B> {
///
/// This is the maximum of:
/// 1. The maximum evaluation degree over all transition constraints minus the degree of the
/// transition constraint divisor divided by trace length.
/// transition constraint divisor divided by trace length.
/// 2. `1`, because the constraint composition polynomial requires at least one column.
///
/// Since the degree of a constraint `C(x)` can be computed as `[constraint.base +
Expand Down
4 changes: 3 additions & 1 deletion utils/core/src/serde/byte_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ pub trait ByteWriter: Sized {
/// # Panics
/// Panics if the value could not be written into `self`.
fn write_usize(&mut self, value: usize) {
// convert the value into a u64 so that we always get 8 bytes from to_le_bytes() call
let value = value as u64;
let length = encoded_len(value);

// 9-byte special case
Expand Down Expand Up @@ -140,7 +142,7 @@ impl ByteWriter for alloc::vec::Vec<u8> {
// ================================================================================================

/// Returns the length of the value in vint64 encoding.
fn encoded_len(value: usize) -> usize {
fn encoded_len(value: u64) -> usize {
let zeros = value.leading_zeros() as usize;
let len = zeros.saturating_sub(1) / 7;
9 - core::cmp::min(len, 8)
Expand Down
4 changes: 2 additions & 2 deletions utils/core/src/serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl<T: Serializable, const C: usize> Serializable for [T; C] {
}

impl<T: Serializable> Serializable for [T] {
fn write_into<W: ?Sized + ByteWriter>(&self, target: &mut W) {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
target.write_usize(self.len());
for element in self.iter() {
element.write_into(target);
Expand Down Expand Up @@ -226,7 +226,7 @@ impl<T: Serializable> Serializable for BTreeSet<T> {
}

impl Serializable for str {
fn write_into<W: ?Sized + ByteWriter>(&self, target: &mut W) {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
target.write_usize(self.len());
target.write_many(self.as_bytes());
}
Expand Down

0 comments on commit 619525f

Please sign in to comment.