Skip to content
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

feat: Sync from noir #8333

Merged
merged 16 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f0c268606a71381ab4504396695a0adb9b3258b6
45344bfe1148a2f592c2e432744d3fb3d46340cc
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/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 noir-projects/aztec-nr/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
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 noir-projects/aztec-nr/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 noir-projects/aztec-nr/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
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 noir-projects/aztec-nr/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 noir-projects/aztec-nr/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 noir-projects/aztec-nr/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 noir-projects/aztec-nr/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 noir-projects/aztec-nr/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
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
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl DAppPayload {
for i in 0..DAPP_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
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ contract AvmTest {
}

/************************************************************************
* Misc
* Misc
************************************************************************/

#[aztec(public)]
Expand All @@ -178,8 +178,7 @@ contract AvmTest {

#[aztec(public)]
fn to_radix_le(input: Field) -> [u8; 10] {
let result: [u8] = input.to_le_radix(/*base=*/ 2, /*limbs=*/ 10);
result.as_array()
input.to_le_radix(/*base=*/ 2)
}

// Helper functions to demonstrate an internal call stack in error messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct Card {

impl FromField for Card {
fn from_field(field: Field) -> Card {
let value_bytes = field.to_le_bytes(32);
let value_bytes: [u8; 32] = field.to_le_bytes();
let strength = (value_bytes[0] as u32) + (value_bytes[1] as u32) * 256;
let points = (value_bytes[2] as u32) + (value_bytes[3] as u32) * 256;
Card { strength, points }
Expand Down Expand Up @@ -157,7 +157,7 @@ pub fn get_pack_cards(
// generate pseudo randomness deterministically from 'seed' and user secret
let secret = context.request_nsk_app(owner_npk_m_hash);
let mix = secret + seed;
let mix_bytes: [u8; 32] = mix.to_le_bytes(32).as_array();
let mix_bytes: [u8; 32] = mix.to_le_bytes();
let random_bytes = std::hash::sha256(mix_bytes);

let mut cards = [Card::from_field(0); PACK_CARDS];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ contract EcdsaKAccount {

// Verify payload signature using Ethereum's signing scheme
// Note that noir expects the hash of the message/challenge as input to the ECDSA verification.
let outer_hash_bytes: [u8; 32] = outer_hash.to_be_bytes(32).as_array();
let outer_hash_bytes: [u8; 32] = outer_hash.to_be_bytes();
let hashed_message: [u8; 32] = std::hash::sha256(outer_hash_bytes);
let verification = std::ecdsa_secp256k1::verify_signature(public_key.x, public_key.y, signature, hashed_message);
assert(verification == true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN, ECDSA_PUBLIC_KEY_NOTE_BYTES_LEN> f

let last_x = self.x[31] as Field;
let last_y = self.y[31] as Field;

[x, last_x, y, last_y, self.npk_m_hash]
}

Expand All @@ -50,17 +50,17 @@ impl NoteInterface<ECDSA_PUBLIC_KEY_NOTE_LEN, ECDSA_PUBLIC_KEY_NOTE_BYTES_LEN> f
let mut x: [u8; 32] = [0; 32];
let mut y: [u8; 32] = [0; 32];

let part_x = serialized_note[0].to_be_bytes(32);
let part_x:[u8; 32] = serialized_note[0].to_be_bytes();
for i in 0..31 {
x[i] = part_x[i + 1];
}
x[31] = serialized_note[1].to_be_bytes(32)[31];
x[31] = serialized_note[1].to_be_bytes::<32>()[31];

let part_y = serialized_note[2].to_be_bytes(32);
let part_y:[u8; 32] = serialized_note[2].to_be_bytes();
for i in 0..31 {
y[i] = part_y[i + 1];
}
y[31] = serialized_note[3].to_be_bytes(32)[31];
y[31] = serialized_note[3].to_be_bytes::<32>()[31];

EcdsaPublicKeyNote { x, y, npk_m_hash: serialized_note[4], header: NoteHeader::empty() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ contract EcdsaRAccount {

// Verify payload signature using Ethereum's signing scheme
// Note that noir expects the hash of the message/challenge as input to the ECDSA verification.
let outer_hash_bytes: [u8; 32] = outer_hash.to_be_bytes(32).as_array();
let outer_hash_bytes: [u8; 32] = outer_hash.to_be_bytes();
let hashed_message: [u8; 32] = std::hash::sha256(outer_hash_bytes);
let verification = std::ecdsa_secp256r1::verify_signature(public_key.x, public_key.y, signature, hashed_message);
assert(verification == true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pub fn calculate_fee<TPublicContext>(context: PublicContext) -> Field {

pub fn get_bridge_gas_msg_hash(owner: AztecAddress, amount: Field) -> Field {
let mut hash_bytes = [0; 68];
let recipient_bytes = owner.to_field().to_be_bytes(32);
let amount_bytes = amount.to_be_bytes(32);
let recipient_bytes: [u8; 32] = owner.to_field().to_be_bytes();
let amount_bytes: [u8; 32] = amount.to_be_bytes();

for i in 0..32 {
hash_bytes[i + 4] = recipient_bytes[i];
Expand Down
Loading
Loading