-
Notifications
You must be signed in to change notification settings - Fork 241
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: FieldNote
#3037
Merged
Merged
feat: FieldNote
#3037
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e22a5cb
WIP
benesjan f4d5f10
WIP
benesjan 39c3035
WIP
benesjan 7583564
final touches
benesjan 29eae85
removed unused dependency
benesjan 208bbc3
fixes
benesjan 948310a
no camel case in test contract
benesjan 37eb228
using and testing FieldNote
benesjan 176c2a1
fix
benesjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "field_note" | ||
authors = ["aztec-labs"] | ||
compiler_version = "0.7.1" | ||
type = "lib" | ||
|
||
[dependencies] | ||
aztec = { path = "../aztec" } |
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,90 @@ | ||
use dep::aztec::{ | ||
note::{ | ||
note_header::NoteHeader, | ||
note_interface::NoteInterface, | ||
}, | ||
hash::pedersen_hash, | ||
context::PrivateContext, | ||
}; | ||
|
||
global FIELD_NOTE_LEN: Field = 1; | ||
|
||
// A note which stores a field and is expected to be passed around using the `addNote` function. | ||
// WARNING: This Note is not private as it does not contain randomness and hence it can be easy to perform preimage | ||
// attack on it. | ||
struct FieldNote { | ||
value: Field, | ||
header: NoteHeader, | ||
} | ||
|
||
impl FieldNote { | ||
pub fn new(value: Field) -> Self { | ||
FieldNote { | ||
value, | ||
header: NoteHeader::empty(), | ||
} | ||
} | ||
|
||
pub fn serialize(self) -> [Field; FIELD_NOTE_LEN]{ | ||
[self.value] | ||
} | ||
|
||
pub fn deserialize(preimage: [Field; FIELD_NOTE_LEN]) -> Self { | ||
FieldNote { | ||
value: preimage[0], | ||
header: NoteHeader::empty(), | ||
} | ||
} | ||
|
||
pub fn compute_note_hash(self) -> Field { | ||
// TODO(#1205) Should use a non-zero generator index. | ||
pedersen_hash(self.serialize(), 0) | ||
} | ||
|
||
pub fn compute_nullifier(self) -> Field { | ||
// This note is expected to be shared between users and for this reason can't be nullified using a secret. | ||
0 | ||
} | ||
|
||
pub fn set_header(&mut self, header: NoteHeader) { | ||
self.header = header; | ||
} | ||
} | ||
|
||
fn deserialize(preimage: [Field; FIELD_NOTE_LEN]) -> FieldNote { | ||
FieldNote::deserialize(preimage) | ||
} | ||
|
||
fn serialize(note: FieldNote) -> [Field; FIELD_NOTE_LEN]{ | ||
note.serialize() | ||
} | ||
|
||
fn compute_note_hash(note: FieldNote) -> Field { | ||
note.compute_note_hash() | ||
} | ||
|
||
fn compute_nullifier(note: FieldNote) -> Field { | ||
note.compute_nullifier() | ||
} | ||
|
||
fn get_header(note: FieldNote) -> NoteHeader { | ||
note.header | ||
} | ||
|
||
fn set_header(note: &mut FieldNote, header: NoteHeader) { | ||
note.set_header(header); | ||
} | ||
|
||
fn broadcast(context: &mut PrivateContext, slot: Field, note: FieldNote) { | ||
assert(false, "FieldNote does not support broadcast. Add it to PXE directly using the `.addNote` function."); | ||
} | ||
|
||
global FieldNoteMethods = NoteInterface { | ||
deserialize, | ||
serialize, | ||
compute_note_hash, | ||
compute_nullifier, | ||
get_header, | ||
set_header, | ||
broadcast, | ||
}; |
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 @@ | ||
mod field_note; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we need to way to unit test aztec.nr stuff