-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
376 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
noir-projects/noir-protocol-circuits/crates/types/src/abis/note_selector.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use crate::utils::field::field_from_bytes; | ||
use dep::std::cmp::Eq; | ||
use crate::traits::{Serialize, Deserialize, FromField, ToField, Empty}; | ||
|
||
global SELECTOR_SIZE = 4; | ||
|
||
struct NoteSelector { | ||
// 1st 4-bytes (big-endian leftmost) of abi-encoding of an note. | ||
inner: Field, | ||
} | ||
|
||
impl Eq for NoteSelector { | ||
fn eq(self, other: NoteSelector) -> bool { | ||
other.inner == self.inner | ||
} | ||
} | ||
|
||
impl Serialize<1> for NoteSelector { | ||
fn serialize(self: Self) -> [Field; 1] { | ||
[self.inner] | ||
} | ||
} | ||
|
||
impl Deserialize<1> for NoteSelector { | ||
fn deserialize(fields: [Field; 1]) -> Self { | ||
Self { | ||
inner: fields[0] | ||
} | ||
} | ||
} | ||
|
||
impl FromField for NoteSelector { | ||
fn from_field(field: Field) -> Self { | ||
Self { inner: field } | ||
} | ||
} | ||
|
||
impl ToField for NoteSelector { | ||
fn to_field(self) -> Field { | ||
self.inner | ||
} | ||
} | ||
|
||
impl Empty for NoteSelector { | ||
fn empty() -> Self { | ||
Self { inner: 0 } | ||
} | ||
} | ||
|
||
impl NoteSelector { | ||
pub fn from_signature<N>(signature: str<N>) -> Self { | ||
let bytes = signature.as_bytes(); | ||
let hash = dep::std::hash::keccak256(bytes, bytes.len() as u32); | ||
|
||
let mut selector_be_bytes = [0; SELECTOR_SIZE]; | ||
for i in 0..SELECTOR_SIZE { | ||
selector_be_bytes[i] = hash[i]; | ||
} | ||
|
||
NoteSelector::from_field(field_from_bytes(selector_be_bytes, true)) | ||
} | ||
|
||
pub fn zero() -> Self { | ||
Self { inner: 0 } | ||
} | ||
|
||
fn to_be_bytes(self, byte_size: u32) -> [u8] { | ||
self.inner.to_be_bytes(byte_size) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,3 @@ noirc_errors.workspace = true | |
iter-extended.workspace = true | ||
convert_case = "0.6.0" | ||
regex = "1.10" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.