Skip to content

Commit

Permalink
chore: remove unnecessary casts (#4906)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Mar 4, 2024
1 parent c98325d commit 7a62c2f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn get_pack_cards(seed: Field, owner: AztecAddress, context: &mut PrivateCon

let mut cards = [Card::from_field(0); PACK_CARDS];
// we generate PACK_CARDS cards
assert((PACK_CARDS as u64) < 8, "Cannot generate more than 8 cards");
assert(PACK_CARDS < 8, "Cannot generate more than 8 cards");
for i in 0..PACK_CARDS {
let strength = (random_bytes[i] as u32) + (random_bytes[i + 1] as u32) * 256;
let points = (random_bytes[i + 2] as u32) + (random_bytes[i + 3] as u32) * 256;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl PrivateKernelTailCircuitPrivateInputs {
// match reads to commitments from the previous call(s)
for rr_idx in 0..MAX_NOTE_HASH_READ_REQUESTS_PER_TX {
let read_request = read_requests.get_unchecked(rr_idx);
let read_commitment_hint = self.read_commitment_hints[rr_idx] as u64;
let read_commitment_hint = self.read_commitment_hints[rr_idx];

if (read_request.value != 0) {
let hash = new_note_hashes.get_unchecked(read_commitment_hint);
Expand Down Expand Up @@ -160,15 +160,15 @@ impl PrivateKernelTailCircuitPrivateInputs {
let nullifier = new_nullifiers[n_idx];
// TODO - should not be able to squash the first nullifier.
let nullified_note_hash = nullifier.note_hash;
let hint_pos = self.nullifier_commitment_hints[n_idx] as u64;
let hint_pos = self.nullifier_commitment_hints[n_idx];

// Nullified_commitment of value `0` implies non-transient (persistable)
// nullifier in which case no attempt will be made to match it to a hash.
// Non-empty nullified_note_hash implies transient nullifier which MUST be matched to a hash below!
// 0-valued nullified_note_hash is empty and will be ignored
if nullified_note_hash != 0 {
assert(
hint_pos < MAX_NEW_NOTE_HASHES_PER_TX as u64, "New nullifier is transient but hint is invalid"
hint_pos < MAX_NEW_NOTE_HASHES_PER_TX, "New nullifier is transient but hint is invalid"
);
let hash = new_note_hashes[hint_pos];
assert_eq(nullified_note_hash, hash.value, "Hinted hash does not match");
Expand All @@ -179,7 +179,7 @@ impl PrivateKernelTailCircuitPrivateInputs {
// squash both the nullifier and the hash
// (set to 0 here and then rearrange array after loop)
new_note_hashes[hint_pos] = SideEffect::empty();
new_nullifiers[n_idx as u64] = SideEffectLinkedToNoteHash::empty();
new_nullifiers[n_idx] = SideEffectLinkedToNoteHash::empty();
}
// non-transient (persistable) nullifiers are just kept in new_nullifiers array and forwarded
// to public inputs (used later by base rollup circuit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ fn validate_public_data_reads(
#[test]
fn consistent_not_hash_subtree_width() {
assert_eq(
MAX_NEW_NOTE_HASHES_PER_TX, 2.pow_32(NOTE_HASH_SUBTREE_HEIGHT as Field) as u64, "note hash subtree width is incorrect"
MAX_NEW_NOTE_HASHES_PER_TX as Field, 2.pow_32(NOTE_HASH_SUBTREE_HEIGHT as Field), "note hash subtree width is incorrect"
);
}

Expand Down Expand Up @@ -644,7 +644,7 @@ mod tests {
);

for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX {
if (i as u64) < MAX_PUBLIC_DATA_WRITES_PER_TEST {
if i < MAX_PUBLIC_DATA_WRITES_PER_TEST {
let (low_leaf_index, leaf): (u64, PublicDataTreeLeaf) = sorted_write_tuples[i].value;

sorted_public_data_writes[i] = leaf;
Expand Down Expand Up @@ -765,7 +765,7 @@ mod tests {
let mut pre_existing_nullifiers = self.pre_existing_nullifiers;

for i in 0..MAX_NEW_NULLIFIERS_PER_TEST {
if (i as u64) < (self.new_nullifiers.len()) {
if i < self.new_nullifiers.len() {
let sorted_tuple = sorted_new_nullifier_tuples[i];
let new_nullifier = sorted_tuple.value;
let original_index = sorted_tuple.original_index;
Expand Down Expand Up @@ -1034,10 +1034,7 @@ mod tests {
assert(outputs.start.note_hash_tree.eq(expected_start_note_hash_tree_snapshot));

for i in 0..new_note_hashes.len() {
expected_commitments_tree.update_leaf(
(i as u64) + (MAX_NEW_NOTE_HASHES_PER_TX as u64),
new_note_hashes[i]
);
expected_commitments_tree.update_leaf(i + MAX_NEW_NOTE_HASHES_PER_TX, new_note_hashes[i]);
}
let expected_end_note_hash_tree_snapshot = AppendOnlyTreeSnapshot {
root: expected_commitments_tree.get_root(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ impl PreviousKernelDataBuilder {
*self
}

pub fn append_public_data_update_requests(&mut self, num_updates: Field) {
pub fn append_public_data_update_requests(&mut self, num_updates: u64) {
let value_offset = self.end.public_data_update_requests.len();
for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX {
if i as u64 < num_updates as u64 {
if i < num_updates {
let update_request = PublicDataUpdateRequest {
// The default leaf index is its index + 23.
leaf_slot: (value_offset + i + 23) as Field,
Expand All @@ -93,10 +93,10 @@ impl PreviousKernelDataBuilder {
}
}

pub fn append_public_data_read_requests(&mut self, num_reads: Field) {
pub fn append_public_data_read_requests(&mut self, num_reads: u64) {
let value_offset = self.end.public_data_reads.len();
for i in 0..MAX_PUBLIC_DATA_READS_PER_TX {
if i as u64 < num_reads as u64 {
if i < num_reads {
let read_request = PublicDataRead {
// The default leaf index is its index + 34.
leaf_slot: (value_offset + i + 34) as Field,
Expand Down Expand Up @@ -145,7 +145,7 @@ impl PreviousKernelDataBuilder {
// so the tx nullifier is in `end`
let index_offset = self.end.new_nullifiers.len();
for i in 0..MAX_NEW_NULLIFIERS_PER_TX {
if i as u64 < num_extra_nullifier as u64 {
if i < num_extra_nullifier {
let mock_value = self.get_mock_nullifier_value(index_offset + i);
self.end.new_nullifiers.push(
SideEffectLinkedToNoteHash {
Expand All @@ -161,7 +161,7 @@ impl PreviousKernelDataBuilder {
pub fn append_new_nullifiers_from_public(&mut self, num_extra_nullifier: u64) {
let index_offset = self.end.new_nullifiers.len();
for i in 1..MAX_NEW_NULLIFIERS_PER_TX {
if i as u64 <= num_extra_nullifier as u64 {
if i <= num_extra_nullifier {
self.end.new_nullifiers.push(
SideEffectLinkedToNoteHash {
value: self.get_mock_nullifier_value(index_offset + i),
Expand All @@ -176,7 +176,7 @@ impl PreviousKernelDataBuilder {
pub fn append_new_nullifiers_non_revertible(&mut self, num_extra_nullifier: u64) {
let index_offset = self.end_non_revertible.new_nullifiers.len();
for i in 1..MAX_NON_REVERTIBLE_NULLIFIERS_PER_TX {
if i as u64 <= num_extra_nullifier as u64 {
if i <= num_extra_nullifier {
self.end_non_revertible.new_nullifiers.push(
SideEffectLinkedToNoteHash {
value: self.get_mock_nullifier_value(index_offset + i),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ impl<SUBTREE_ITEMS, TREE_HEIGHT, SUPERTREE_HEIGHT, SUBTREE_HEIGHT> NonEmptyMerkl

pub fn get_sibling_path(self, leaf_index: u64) -> [Field; TREE_HEIGHT] {
let mut path = [0; TREE_HEIGHT];
let mut current_index = leaf_index as u64;
let mut subtree_width = SUBTREE_ITEMS as u64;
let mut current_index = leaf_index;
let mut subtree_width = SUBTREE_ITEMS;

let mut sibling_index = MerkleTree::sibling_index(current_index);

Expand Down Expand Up @@ -139,7 +139,7 @@ impl<SUBTREE_ITEMS, TREE_HEIGHT, SUPERTREE_HEIGHT, SUBTREE_HEIGHT> NonEmptyMerkl
}

pub fn update_leaf(&mut self, index: u64, value: Field) {
assert(index < SUBTREE_ITEMS as u64, "index must be less than the number of leaves in the subtree");
assert(index < SUBTREE_ITEMS, "index must be less than the number of leaves in the subtree");

self.subtree.update_leaf(index, value, [0; SUBTREE_HEIGHT]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ impl PublicCallDataBuilder {
}
}

pub fn append_public_data_read_requests(&mut self, num_reads: Field) {
pub fn append_public_data_read_requests(&mut self, num_reads: u64) {
let value_offset = self.public_inputs.contract_storage_reads.len();
for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL {
if i as u64 < num_reads as u64 {
if i < num_reads {
let read_request = StorageRead {
// The default storage slot is its index + 1.
storage_slot: (value_offset + i + 1) as Field,
Expand All @@ -126,18 +126,18 @@ impl PublicCallDataBuilder {
}
}

pub fn append_empty_public_data_read_requests(&mut self, num_reads: Field) {
pub fn append_empty_public_data_read_requests(&mut self, num_reads: u64) {
for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL {
if i as u64 < num_reads as u64 {
if i < num_reads {
self.public_inputs.contract_storage_reads.push(StorageRead::empty());
}
}
}

pub fn append_update_requests(&mut self, num_updates: Field) {
pub fn append_update_requests(&mut self, num_updates: u64) {
let value_offset = self.public_inputs.contract_storage_update_requests.len();
for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL {
if i as u64 < num_updates as u64 {
if i < num_updates {
let update_request = StorageUpdateRequest {
// The default storage slot is its index + 1.
storage_slot: (value_offset + i + 1) as Field,
Expand All @@ -149,9 +149,9 @@ impl PublicCallDataBuilder {
}
}

pub fn append_empty_update_requests(&mut self, num_updates: Field) {
pub fn append_empty_update_requests(&mut self, num_updates: u64) {
for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL {
if i as u64 < num_updates as u64 {
if i < num_updates {
self.public_inputs.contract_storage_update_requests.push(StorageUpdateRequest::empty());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn validate_array<T, N>(array: [T; N]) where T: Empty + Eq {
first_zero_pos = i;
}
}
assert((last_non_zero_pos as u64) <= (first_zero_pos as u64), "invalid array");
assert(last_non_zero_pos <= first_zero_pos, "invalid array");
}

// Helper method to determine the number of non-zero/empty elements in a validated array (ie, validate_array(array)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub fn field_from_bytes<N>(bytes: [u8; N], big_endian: bool) -> Field {
assert(bytes.len() as u32 < 32, "field_from_bytes: N must be less than 32");
assert(bytes.len() < 32, "field_from_bytes: N must be less than 32");
let mut as_field = 0;
let mut offset = 1;
for i in 0..N {
Expand Down

0 comments on commit 7a62c2f

Please sign in to comment.