forked from AztecProtocol/aztec-packages
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
FieldNote
(AztecProtocol#3037)
1. Fixes AztecProtocol#2948 2. Removed redundant dependency from `TokenContract`. 3. No camel case in `TestContract`
- Loading branch information
Showing
10 changed files
with
257 additions
and
81 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
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.