-
Notifications
You must be signed in to change notification settings - Fork 4
✨ Update array storage #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
✨ Update array storage #46
Conversation
433b77a to
6ea8ccc
Compare
| use simplicityhl::{WitnessValues, str::WitnessName}; | ||
|
|
||
| pub const MAX_VAL: usize = 10000; | ||
| pub const MAX_VAL: usize = 3; |
There was a problem hiding this comment.
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
14030e2 to
4e85755
Compare
| 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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // 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
| /// 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()); | ||
| } |
There was a problem hiding this comment.
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
| /// 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
b7c2fa0 to
612102f
Compare
| /// # 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(()) | ||
| } |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
612102f to
436d4b2
Compare
No description provided.