Skip to content

Commit

Permalink
feat: Sync from noir (#8333)
Browse files Browse the repository at this point in the history
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
feat: use visibility (noir-lang/noir#5856)
chore: use `new_let` more widely
(noir-lang/noir#5882)
feat: Sync from aztec-packages
(noir-lang/noir#5883)
feat!: return arrays instead of slices from `to_be_radix` functions
(noir-lang/noir#5851)
chore: add a span to track timing of brillig gen
(noir-lang/noir#5835)
feat: add `Expr::as_assert_eq`
(noir-lang/noir#5880)
feat: LSP diagnostics now have "unnecessary" and "deprecated" tags
(noir-lang/noir#5878)
feat: LSP code actions to import or qualify unresolved paths
(noir-lang/noir#5876)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: Tom French <tom@tomfren.ch>
  • Loading branch information
3 people committed Sep 4, 2024
1 parent 4a2adba commit 5299d31
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 44 deletions.
2 changes: 1 addition & 1 deletion authwit/src/entrypoint/app.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion authwit/src/entrypoint/fee.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions authwit/src/entrypoint/function_call.nr
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ impl Serialize<FUNCTION_CALL_SIZE> 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];
}
Expand Down
2 changes: 1 addition & 1 deletion aztec/src/encrypted_logs/header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
16 changes: 8 additions & 8 deletions aztec/src/encrypted_logs/incoming_body.nr
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ 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];
buffer[32 + i] = note_type_id_bytes[i];
}

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];
}
Expand Down Expand Up @@ -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];
Expand All @@ -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];
}
Expand All @@ -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];
Expand All @@ -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];
}
Expand Down
8 changes: 4 additions & 4 deletions aztec/src/encrypted_logs/outgoing_body.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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];
Expand Down
14 changes: 7 additions & 7 deletions aztec/src/hash.nr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn compute_unencrypted_log_hash<T, let N: u32, let M: u32>(
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];
}
Expand All @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion aztec/src/note/note_getter/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn extract_property_value_from_selector<let N: u32>(
// 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;
Expand Down
8 changes: 4 additions & 4 deletions aztec/src/oracle/logs_traits.nr
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ trait ToBytesForUnencryptedLog<let N: u32, let M: u32> {

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]}
}
Expand All @@ -118,7 +118,7 @@ fn arr_to_be_bytes_arr<let N: u32, let L: u32>(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]);
}
Expand All @@ -132,7 +132,7 @@ fn str_to_be_bytes_arr<let N: u32, let L: u32>(string: str<L>) -> [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]);
}
Expand Down
8 changes: 4 additions & 4 deletions aztec/src/test/mocks/mock_note.nr
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ impl NoteInterface<MOCK_NOTE_LENGTH, MOCK_NOTE_BYTES_LENGTH> 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];
buffer[32 + i] = note_type_id_bytes[i];
}

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];
}
Expand All @@ -85,7 +85,7 @@ impl NoteInterface<MOCK_NOTE_LENGTH, MOCK_NOTE_BYTES_LENGTH> for MockNote {

impl Eq for MockNote {
fn eq(self, other: Self) -> bool {
(self.header == other.header) &
(self.header == other.header) &
(self.value == other.value)
}
}
Expand Down
4 changes: 2 additions & 2 deletions aztec/src/utils/point.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -27,7 +27,7 @@ pub fn point_to_bytes(pk: Point) -> [u8; 32] {
result[0] += 128;
}

result.as_array()
result
}

mod test {
Expand Down
4 changes: 2 additions & 2 deletions compressed-string/src/compressed_string.nr
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<let N: u32, let M: u32> CompressedString<N, M> {
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];
Expand All @@ -55,7 +55,7 @@ impl<let N: u32, let M: u32> Eq for CompressedString<N, M> {
impl<let N: u32, let M: u32> Serialize<N> for CompressedString<N, M> {
fn serialize(self) -> [Field; N] {
self.value

}
}

Expand Down
7 changes: 1 addition & 6 deletions compressed-string/src/field_compressed_string.nr
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

0 comments on commit 5299d31

Please sign in to comment.