-
Notifications
You must be signed in to change notification settings - Fork 288
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
refactor: random fixes and readability improvements #11129
base: 01-07-chore_fixing_aztec-nr_warnings
Are you sure you want to change the base?
Changes from all commits
4463a88
8f11ff7
f7e47ed
967688a
f71be38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ mod test; | |
|
||
// This data structure is used by SharedMutable to store the minimum delay with which a ScheduledValueChange object can | ||
// schedule a change. | ||
// This delay is initally equal to INITIAL_DELAY, and can be safely mutated to any other value over time. This mutation | ||
// This delay is initially equal to INITIAL_DELAY, and can be safely mutated to any other value over time. This mutation | ||
// is performed via `schedule_change` in order to satisfy ScheduleValueChange constraints: if e.g. we allowed for the | ||
// delay to be decreased immediately then it'd be possible for the state variable to schedule a value change with a | ||
// reduced delay, invalidating prior private reads. | ||
|
@@ -58,7 +58,7 @@ impl<let INITIAL_DELAY: u32> ScheduledDelayChange<INITIAL_DELAY> { | |
// When changing the delay value we must ensure that it is not possible to produce a value change with a delay | ||
// shorter than the current one. | ||
let blocks_until_change = if new > current { | ||
// Increasing the delay value can therefore be done immediately: this does not invalidate prior contraints | ||
// Increasing the delay value can therefore be done immediately: this does not invalidate prior constraints | ||
// about how quickly a value might be changed (indeed it strengthens them). | ||
0 | ||
} else { | ||
|
@@ -127,34 +127,28 @@ impl<let INITIAL_DELAY: u32> ScheduledDelayChange<INITIAL_DELAY> { | |
|
||
impl<let INITIAL_DELAY: u32> Serialize<1> for ScheduledDelayChange<INITIAL_DELAY> { | ||
fn serialize(self) -> [Field; 1] { | ||
// We pack all three u32 values into a single U128, which is made up of two u64 limbs. | ||
// Low limb: [ pre_inner: u32 | post_inner: u32 ] | ||
// High limb: [ empty | pre_is_some: u8 | post_is_some: u8 | block_of_change: u32 ] | ||
let lo = ((self.pre.unwrap_unchecked() as u64) * (1 << 32)) | ||
+ (self.post.unwrap_unchecked() as u64); | ||
|
||
let hi = (self.pre.is_some() as u64) * (1 << 33) | ||
+ (self.post.is_some() as u64 * (1 << 32)) | ||
+ self.block_of_change as u64; | ||
|
||
let packed = U128::from_u64s_le(lo, hi); | ||
// Pack all values directly into a single Field: | ||
// [pre_inner: 32 bits | post_inner: 32 bits | block_of_change: 32 bits | post_is_some: 1 bit | pre_is_some: 1 bit] | ||
let packed = U128::from_integer(self.pre.unwrap_unchecked()) | ||
+ (U128::from_integer(self.post.unwrap_unchecked()) << 32) | ||
+ (U128::from_integer(self.block_of_change) << 64) | ||
+ (U128::from_integer(self.post.is_some()) << 96) | ||
+ (U128::from_integer(self.pre.is_some()) << 97); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warnings fix. As discussed in a PR down the stack now I don't work with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we use |
||
|
||
[packed.to_integer()] | ||
} | ||
} | ||
|
||
impl<let INITIAL_DELAY: u32> Deserialize<1> for ScheduledDelayChange<INITIAL_DELAY> { | ||
fn deserialize(input: [Field; 1]) -> Self { | ||
let packed = U128::from_integer(input[0]); | ||
|
||
// We use division and modulo to clear the bits that correspond to other values when unpacking. | ||
let pre_is_some = ((packed.hi as u64) / (1 << 33)) as bool; | ||
let pre_inner = ((packed.lo as u64) / (1 << 32)) as u32; | ||
|
||
let post_is_some = (((packed.hi as u64) / (1 << 32)) % (1 << 1)) as bool; | ||
let post_inner = ((packed.lo as u64) % (1 << 32)) as u32; | ||
|
||
let block_of_change = ((packed.hi as u64) % (1 << 32)) as u32; | ||
let packed = U128::from_field(input[0]); | ||
|
||
// We unpack the values from the Field | ||
let pre_inner = packed.to_integer() as u32; | ||
let post_inner = (packed >> 32).to_integer() as u32; | ||
let block_of_change = (packed >> 64).to_integer() as u32; | ||
let post_is_some = (packed >> 96).to_integer() & 1 == 1; | ||
let pre_is_some = (packed >> 97).to_integer() & 1 == 1; | ||
|
||
Self { | ||
pre: if pre_is_some { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ use dep::aztec::{ | |
}, | ||
}; | ||
|
||
global VALUE_NOTE_LEN: u32 = 3; // 3 plus a header. | ||
pub global VALUE_NOTE_LEN: u32 = 3; // 3 plus a header. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warnings fix --> value was used in a test contract. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which test contract? Accessing this is an antipattern. |
||
|
||
// docs:start:value-note-def | ||
// ValueNote is used as fn parameter in the Claim contract, so it has to implement the Serialize trait. | ||
|
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.
I find
assert_eq
nicer to read thanassert(left == right)
so I sneaked this change in here and in other places.I think we didn't use it before as it was not yet implemented.
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.
This assert is not present in the origianl code though?