diff --git a/authwit/src/entrypoint/app.nr b/authwit/src/entrypoint/app.nr index 4c2aaf8f..663ae804 100644 --- a/authwit/src/entrypoint/app.nr +++ b/authwit/src/entrypoint/app.nr @@ -50,7 +50,7 @@ impl AppPayload { for i in 0..ACCOUNT_MAX_CALLS { bytes.extend_from_array(self.function_calls[i].to_be_bytes()); } - bytes.extend_from_slice(self.nonce.to_be_bytes(32)); + bytes.extend_from_array(self.nonce.to_be_bytes::<32>()); bytes.storage } diff --git a/authwit/src/entrypoint/fee.nr b/authwit/src/entrypoint/fee.nr index 0d302d0f..f7d0ea25 100644 --- a/authwit/src/entrypoint/fee.nr +++ b/authwit/src/entrypoint/fee.nr @@ -50,7 +50,7 @@ impl FeePayload { for i in 0..MAX_FEE_FUNCTION_CALLS { bytes.extend_from_array(self.function_calls[i].to_be_bytes()); } - bytes.extend_from_slice(self.nonce.to_be_bytes(32)); + bytes.extend_from_array(self.nonce.to_be_bytes::<32>()); bytes.push(self.is_fee_payer as u8); bytes.storage diff --git a/authwit/src/entrypoint/function_call.nr b/authwit/src/entrypoint/function_call.nr index 10102e9a..18ed6acb 100644 --- a/authwit/src/entrypoint/function_call.nr +++ b/authwit/src/entrypoint/function_call.nr @@ -22,15 +22,15 @@ impl Serialize for FunctionCall { impl FunctionCall { fn to_be_bytes(self) -> [u8; FUNCTION_CALL_SIZE_IN_BYTES] { let mut bytes: [u8; FUNCTION_CALL_SIZE_IN_BYTES] = [0; FUNCTION_CALL_SIZE_IN_BYTES]; - let args_hash_bytes = self.args_hash.to_be_bytes(32); + let args_hash_bytes: [u8; 32] = self.args_hash.to_be_bytes(); for i in 0..32 { bytes[i] = args_hash_bytes[i]; } - let function_selector_bytes = self.function_selector.to_field().to_be_bytes(32); + let function_selector_bytes: [u8; 32] = self.function_selector.to_field().to_be_bytes(); for i in 0..32 { bytes[i + 32] = function_selector_bytes[i]; } - let target_address_bytes = self.target_address.to_field().to_be_bytes(32); + let target_address_bytes: [u8; 32] = self.target_address.to_field().to_be_bytes(); for i in 0..32 { bytes[i + 64] = target_address_bytes[i]; } diff --git a/aztec/src/encrypted_logs/header.nr b/aztec/src/encrypted_logs/header.nr index f43c60b6..c4962380 100644 --- a/aztec/src/encrypted_logs/header.nr +++ b/aztec/src/encrypted_logs/header.nr @@ -23,7 +23,7 @@ impl EncryptedLogHeader { iv[i] = full_key[i + 16]; } - let input: [u8; 32] = self.address.to_field().to_be_bytes(32).as_array(); + let input: [u8; 32] = self.address.to_field().to_be_bytes(); aes128_encrypt(input, iv, sym_key).as_array() } } diff --git a/aztec/src/encrypted_logs/incoming_body.nr b/aztec/src/encrypted_logs/incoming_body.nr index fd2cab44..e3d2ea44 100644 --- a/aztec/src/encrypted_logs/incoming_body.nr +++ b/aztec/src/encrypted_logs/incoming_body.nr @@ -90,8 +90,8 @@ mod test { let mut buffer: [u8; ADDRESS_NOTE_BYTES_LEN] = [0; ADDRESS_NOTE_BYTES_LEN]; - let storage_slot_bytes = storage_slot.to_be_bytes(32); - let note_type_id_bytes = AddressNote::get_note_type_id().to_be_bytes(32); + let storage_slot_bytes: [u8; 32] = storage_slot.to_be_bytes(); + let note_type_id_bytes: [u8; 32] = AddressNote::get_note_type_id().to_be_bytes(); for i in 0..32 { buffer[i] = storage_slot_bytes[i]; @@ -99,7 +99,7 @@ mod test { } for i in 0..serialized_note.len() { - let bytes = serialized_note[i].to_be_bytes(32); + let bytes: [u8; 32] = serialized_note[i].to_be_bytes(); for j in 0..32 { buffer[64 + i * 32 + j] = bytes[j]; } @@ -183,8 +183,8 @@ mod test { fn private_to_be_bytes(self, randomness: Field) -> [u8; TEST_EVENT_BYTES_LEN] { let mut buffer: [u8; TEST_EVENT_BYTES_LEN] = [0; TEST_EVENT_BYTES_LEN]; - let randomness_bytes = randomness.to_be_bytes(32); - let event_type_id_bytes = TestEvent::get_event_type_id().to_field().to_be_bytes(32); + let randomness_bytes: [u8; 32] = randomness.to_be_bytes(); + let event_type_id_bytes: [u8; 32] = TestEvent::get_event_type_id().to_field().to_be_bytes(); for i in 0..32 { buffer[i] = randomness_bytes[i]; @@ -194,7 +194,7 @@ mod test { let serialized_event = self.serialize(); for i in 0..serialized_event.len() { - let bytes = serialized_event[i].to_be_bytes(32); + let bytes: [u8; 32] = serialized_event[i].to_be_bytes(); for j in 0..32 { buffer[64 + i * 32 + j] = bytes[j]; } @@ -206,7 +206,7 @@ mod test { fn to_be_bytes(self) -> [u8; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS] { let mut buffer: [u8; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS] = [0; TEST_EVENT_BYTES_LEN_WITHOUT_RANDOMNESS]; - let event_type_id_bytes = TestEvent::get_event_type_id().to_field().to_be_bytes(32); + let event_type_id_bytes: [u8; 32] = TestEvent::get_event_type_id().to_field().to_be_bytes(); for i in 0..32 { buffer[i] = event_type_id_bytes[i]; @@ -215,7 +215,7 @@ mod test { let serialized_event = self.serialize(); for i in 0..serialized_event.len() { - let bytes = serialized_event[i].to_be_bytes(32); + let bytes: [u8; 32] = serialized_event[i].to_be_bytes(); for j in 0..32 { buffer[32 + i * 32 + j] = bytes[j]; } diff --git a/aztec/src/encrypted_logs/outgoing_body.nr b/aztec/src/encrypted_logs/outgoing_body.nr index 96c35c68..61495849 100644 --- a/aztec/src/encrypted_logs/outgoing_body.nr +++ b/aztec/src/encrypted_logs/outgoing_body.nr @@ -25,10 +25,10 @@ impl EncryptedLogOutgoingBody { let mut buffer = [0 as u8; 128]; - let serialized_eph_sk_high = self.eph_sk.hi.to_be_bytes(32); - let serialized_eph_sk_low = self.eph_sk.lo.to_be_bytes(32); + let serialized_eph_sk_high: [u8; 32] = self.eph_sk.hi.to_be_bytes(); + let serialized_eph_sk_low: [u8; 32] = self.eph_sk.lo.to_be_bytes(); - let address_bytes = self.recipient.to_field().to_be_bytes(32); + let address_bytes: [u8; 32] = self.recipient.to_field().to_be_bytes(); let serialized_recipient_ivpk = point_to_bytes(self.recipient_ivpk.to_point()); for i in 0..32 { @@ -44,7 +44,7 @@ impl EncryptedLogOutgoingBody { let full_key: [u8; 32] = poseidon2_hash_with_separator( [ovsk_app.hi, ovsk_app.lo, eph_pk.x, eph_pk.y], GENERATOR_INDEX__SYMMETRIC_KEY as Field - ).to_be_bytes(32).as_array(); + ).to_be_bytes(); let mut sym_key = [0; 16]; let mut iv = [0; 16]; diff --git a/aztec/src/hash.nr b/aztec/src/hash.nr index 64254a6a..6cca38d1 100644 --- a/aztec/src/hash.nr +++ b/aztec/src/hash.nr @@ -30,7 +30,7 @@ pub fn compute_unencrypted_log_hash( for i in 0..32 { hash_bytes[i] = address_bytes[i]; } - let len_bytes = (n as Field).to_be_bytes(4); + let len_bytes: [u8; 4] = (n as Field).to_be_bytes(); for i in 0..4 { hash_bytes[32 + i] = len_bytes[i]; } @@ -50,12 +50,12 @@ pub fn compute_message_hash( secret_hash: Field ) -> Field { let mut hash_bytes = [0 as u8; 192]; - let sender_bytes = sender.to_field().to_be_bytes(32); - let chain_id_bytes = chain_id.to_be_bytes(32); - let recipient_bytes = recipient.to_field().to_be_bytes(32); - let version_bytes = version.to_be_bytes(32); - let content_bytes = content.to_be_bytes(32); - let secret_hash_bytes = secret_hash.to_be_bytes(32); + let sender_bytes: [u8; 32] = sender.to_field().to_be_bytes(); + let chain_id_bytes: [u8; 32] = chain_id.to_be_bytes(); + let recipient_bytes: [u8; 32] = recipient.to_field().to_be_bytes(); + let version_bytes: [u8; 32] = version.to_be_bytes(); + let content_bytes: [u8; 32] = content.to_be_bytes(); + let secret_hash_bytes: [u8; 32] = secret_hash.to_be_bytes(); for i in 0..32 { hash_bytes[i] = sender_bytes[i]; diff --git a/aztec/src/note/note_getter/mod.nr b/aztec/src/note/note_getter/mod.nr index ab9d0ede..8170ddf8 100644 --- a/aztec/src/note/note_getter/mod.nr +++ b/aztec/src/note/note_getter/mod.nr @@ -17,7 +17,7 @@ fn extract_property_value_from_selector( // Selectors use PropertySelectors in order to locate note properties inside the serialized note. // This allows easier packing and custom (de)serialization schemas. A note property is located // inside the serialized note using the index inside the array, a byte offset and a length. - let value = serialized_note[selector.index].to_be_bytes(32); + let value: [u8; 32] = serialized_note[selector.index].to_be_bytes(); let offset = selector.offset; let length = selector.length; let mut value_field = 0 as Field; diff --git a/aztec/src/oracle/logs_traits.nr b/aztec/src/oracle/logs_traits.nr index cd27ead6..d9112a21 100644 --- a/aztec/src/oracle/logs_traits.nr +++ b/aztec/src/oracle/logs_traits.nr @@ -102,14 +102,14 @@ trait ToBytesForUnencryptedLog { impl ToBytesForUnencryptedLog<32, 68> for Field { fn to_be_bytes_arr(self) -> [u8; 32] { - self.to_be_bytes(32).as_array() + self.to_be_bytes() } fn output_bytes(self) -> [u8; 68] {[self as u8; 68]} } impl ToBytesForUnencryptedLog<32, 68> for AztecAddress { fn to_be_bytes_arr(self) -> [u8; 32] { - self.to_field().to_be_bytes(32).as_array() + self.to_field().to_be_bytes() } fn output_bytes(self) -> [u8; 68] {[self.to_field() as u8; 68]} } @@ -118,7 +118,7 @@ fn arr_to_be_bytes_arr(fields: [Field; L]) -> [u8; N] { let mut bytes: [u8] = &[]; for i in 0..L { // Note that bytes.append() results in bound error - let to_add = fields[i].to_be_bytes(32); + let to_add: [u8; 32] = fields[i].to_be_bytes(); for j in 0..32 { bytes = bytes.push_back(to_add[j]); } @@ -132,7 +132,7 @@ fn str_to_be_bytes_arr(string: str) -> [u8; N] { let chars_bytes = string.as_bytes(); let mut bytes: [u8] = &[]; for i in 0..L { - let to_add = (chars_bytes[i] as Field).to_be_bytes(32); + let to_add: [u8; 32] = (chars_bytes[i] as Field).to_be_bytes(); for j in 0..32 { bytes = bytes.push_back(to_add[j]); } diff --git a/aztec/src/test/mocks/mock_note.nr b/aztec/src/test/mocks/mock_note.nr index c23a3ac8..f40f02b7 100644 --- a/aztec/src/test/mocks/mock_note.nr +++ b/aztec/src/test/mocks/mock_note.nr @@ -65,8 +65,8 @@ impl NoteInterface for MockNote { let mut buffer: [u8; MOCK_NOTE_BYTES_LENGTH] = [0; MOCK_NOTE_BYTES_LENGTH]; - let storage_slot_bytes = storage_slot.to_be_bytes(32); - let note_type_id_bytes = MockNote::get_note_type_id().to_be_bytes(32); + let storage_slot_bytes: [u8; 32] = storage_slot.to_be_bytes(); + let note_type_id_bytes: [u8; 32] = MockNote::get_note_type_id().to_be_bytes(); for i in 0..32 { buffer[i] = storage_slot_bytes[i]; @@ -74,7 +74,7 @@ impl NoteInterface for MockNote { } for i in 0..serialized_note.len() { - let bytes = serialized_note[i].to_be_bytes(32); + let bytes: [u8; 32] = serialized_note[i].to_be_bytes(); for j in 0..32 { buffer[64 + i * 32 + j] = bytes[j]; } @@ -85,7 +85,7 @@ impl NoteInterface for MockNote { impl Eq for MockNote { fn eq(self, other: Self) -> bool { - (self.header == other.header) & + (self.header == other.header) & (self.value == other.value) } } diff --git a/aztec/src/utils/point.nr b/aztec/src/utils/point.nr index 249df9e2..633bd837 100644 --- a/aztec/src/utils/point.nr +++ b/aztec/src/utils/point.nr @@ -13,7 +13,7 @@ pub fn point_to_bytes(pk: Point) -> [u8; 32] { // the "sign") so it's possible to use that last bit as an "is_infinite" flag if desired in the future. assert(!pk.is_infinite, "Cannot serialize point at infinity as bytes."); - let mut result = pk.x.to_be_bytes(32); + let mut result: [u8; 32] = pk.x.to_be_bytes(); // We store only a "sign" of the y coordinate because the rest can be derived from the x coordinate. To get // the sign we check if the y coordinate is less or equal than the curve's order minus 1 divided by 2. @@ -27,7 +27,7 @@ pub fn point_to_bytes(pk: Point) -> [u8; 32] { result[0] += 128; } - result.as_array() + result } mod test { diff --git a/compressed-string/src/compressed_string.nr b/compressed-string/src/compressed_string.nr index d73d024a..134753e1 100644 --- a/compressed-string/src/compressed_string.nr +++ b/compressed-string/src/compressed_string.nr @@ -34,7 +34,7 @@ impl CompressedString { let mut result = [0; M]; let mut w_index = 0 as u32; for i in 0..N { - let bytes = self.value[i].to_be_bytes(31); + let bytes: [u8; 31] = self.value[i].to_be_bytes(); for j in 0..31 { if w_index < M { result[w_index] = bytes[j]; @@ -55,7 +55,7 @@ impl Eq for CompressedString { impl Serialize for CompressedString { fn serialize(self) -> [Field; N] { self.value - + } } diff --git a/compressed-string/src/field_compressed_string.nr b/compressed-string/src/field_compressed_string.nr index cba01277..0207d1c0 100644 --- a/compressed-string/src/field_compressed_string.nr +++ b/compressed-string/src/field_compressed_string.nr @@ -32,11 +32,6 @@ impl FieldCompressedString { } pub fn to_bytes(self) -> [u8; 31] { - let mut result = [0; 31]; - let bytes = self.value.to_be_bytes(31); - for i in 0..31 { - result[i] = bytes[i]; - } - result + self.value.to_be_bytes() } }