Skip to content

Conversation

@LesterEvSe
Copy link
Collaborator

No description provided.

@LesterEvSe LesterEvSe self-assigned this Jan 12, 2026
@LesterEvSe LesterEvSe requested a review from KyrylR as a code owner January 12, 2026 13:50
@LesterEvSe LesterEvSe added the enhancement New feature or request label Jan 12, 2026
@LesterEvSe LesterEvSe force-pushed the feature/updated-storage branch from 433b77a to 6ea8ccc Compare January 13, 2026 09:28
use simplicityhl::{WitnessValues, str::WitnessName};

pub const MAX_VAL: usize = 10000;
pub const MAX_VAL: usize = 3;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give more explanation why it is hardcoded

@LesterEvSe LesterEvSe force-pushed the feature/updated-storage branch 3 times, most recently from 14030e2 to 4e85755 Compare January 13, 2026 11:41
@LesterEvSe LesterEvSe requested a review from KyrylR January 13, 2026 13:06
use simplicityhl::{WitnessValues, str::WitnessName};

pub const MAX_VAL: usize = 10000;
// Currently, this value is hardcoded because Simplicity cannot initialize arrays using arguments (i.e., param::LEN).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Currently, this value is hardcoded because Simplicity cannot initialize arrays using arguments (i.e., param::LEN).
// The storage is represented by the 3 u256 "slots", on every transaction all values should be provided in the witness...

I wanted it to be more like an explanation rather then technical description

Comment on lines 24 to 36
/// Adds a given `u64` value to the last 8 bytes (big-endian) of the limb at the specified index.
///
/// # Panics
///
/// This function **panics** in the following cases:
/// * **Index out of bounds:** If `index` is greater than or equal to `self.limbs.len()`.
/// * **Invalid slice length:** If the slice `self.limbs[index][24..]` is not exactly 8 bytes long.
/// * **Overflow:** If the addition `val += num` overflows `u64::MAX`.
pub fn add_num_to_last_qword(&mut self, index: usize, num: u64) {
let mut val = u64::from_be_bytes(self.limbs[index][24..].try_into().unwrap());
val += num;
self.limbs[index][24..].copy_from_slice(&val.to_be_bytes());
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Result instead of panic

Suggested change
/// Adds a given `u64` value to the last 8 bytes (big-endian) of the limb at the specified index.
///
/// # Panics
///
/// This function **panics** in the following cases:
/// * **Index out of bounds:** If `index` is greater than or equal to `self.limbs.len()`.
/// * **Invalid slice length:** If the slice `self.limbs[index][24..]` is not exactly 8 bytes long.
/// * **Overflow:** If the addition `val += num` overflows `u64::MAX`.
pub fn add_num_to_last_qword(&mut self, index: usize, num: u64) {
let mut val = u64::from_be_bytes(self.limbs[index][24..].try_into().unwrap());
val += num;
self.limbs[index][24..].copy_from_slice(&val.to_be_bytes());
}
/// Adds a given `u64` value to the last 8 bytes (big-endian) of the limb at the specified index.
///
/// # Panics
///
/// This function **panics** in the following cases:
/// * **Index out of bounds:** If `index` is greater than or equal to `self.limbs.len()`.
/// * **Invalid slice length:** If the slice `self.limbs[index][24..]` is not exactly 8 bytes long.
/// * **Overflow:** If the addition `val += num` overflows `u64::MAX`.
pub fn set_num_to_last_qword(&mut self, num: u64) {
let mut val = u64::from_be_bytes(self.limbs[index][24..].try_into().unwrap());
val += num;
self.limbs[index][24..].copy_from_slice(&val.to_be_bytes());
}

Rely on types that Rust provides more pls

@LesterEvSe LesterEvSe force-pushed the feature/updated-storage branch 2 times, most recently from b7c2fa0 to 612102f Compare January 13, 2026 15:12
@LesterEvSe LesterEvSe requested a review from KyrylR January 13, 2026 15:16
@LesterEvSe LesterEvSe changed the title feat: Update array storage ✨ Update array storage Jan 14, 2026
Comment on lines +32 to +38
/// # Errors
/// Returns an error if `index` is out of bounds.
pub fn set_num_to_last_qword(&mut self, index: usize, num: u64) -> Result<(), &'static str> {
let limb = self.limbs.get_mut(index).ok_or("Index out of bounds")?;
limb[24..].copy_from_slice(&num.to_be_bytes());
Ok(())
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give as many context as possible, there should be no "magic" numbers

.add_leaf_with_ver(1, script, version)
.expect("tap tree should be valid")
.add_hidden(1, storage_hash)
.add_hidden(1, state_hash)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should explain, what exactly .add_hidden means in that context

@LesterEvSe LesterEvSe force-pushed the feature/updated-storage branch from 612102f to 436d4b2 Compare January 16, 2026 10:06
@LesterEvSe LesterEvSe requested a review from KyrylR January 16, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants