-
Notifications
You must be signed in to change notification settings - Fork 270
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: Unify unencrypted log emission and decoding #7232
Merged
LHerskind
merged 3 commits into
master
from
ek/feat/7162/update-unencrypted-event-emission-api
Jun 28, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 unencrypted_event_emission; |
58 changes: 58 additions & 0 deletions
58
noir-projects/aztec-nr/aztec/src/unencrypted_logs/unencrypted_event_emission.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,58 @@ | ||
use crate::{ | ||
context::{PrivateContext, PublicContext}, event::event_interface::EventInterface, | ||
encrypted_logs::payload::compute_encrypted_event_log, oracle::logs_traits::LensForEncryptedEvent | ||
}; | ||
use dep::protocol_types::{address::AztecAddress, grumpkin_point::GrumpkinPoint, traits::Serialize}; | ||
|
||
fn emit<Event, NB, MB, OB, N, M>( | ||
context: &mut PublicContext, | ||
event: Event | ||
) where Event: EventInterface<NB, MB>, Event: Serialize<N>, [Field; N]: LensForEventSelector<N, M> { | ||
let selector = Event::get_event_type_id(); | ||
|
||
let serialized_event = event.serialize(); | ||
let mut emitted_log = [0; M]; | ||
|
||
// We put the selector in the "last" place, to avoid reading or assigning to an expression in an index | ||
for i in 0..serialized_event.len() { | ||
emitted_log[i] = serialized_event[i]; | ||
} | ||
|
||
emitted_log[serialized_event.len()] = selector.to_field(); | ||
|
||
context.emit_unencrypted_log(emitted_log); | ||
} | ||
|
||
pub fn encode_event<Event, NB, MB, OB, N, M>(context: &mut PublicContext) -> fn[(&mut PublicContext,)](Event) -> () where Event: EventInterface<NB, MB>, Event: Serialize<N>, [Field; N]: LensForEventSelector<N, M> { | ||
| e: Event | { | ||
emit( | ||
context, | ||
e, | ||
); | ||
} | ||
} | ||
|
||
trait LensForEventSelector<N, M> { | ||
// N = event preimage input in fields | ||
// M = event preimage input in fields + event selector as field | ||
fn output(self: [Field; N]) -> [Field; M]; | ||
} | ||
|
||
impl LensForEventSelector<1, 2> for [Field; 1] { | ||
fn output(self) -> [Field; 2] {[self[0] as Field; 2]} | ||
} | ||
impl LensForEventSelector<2, 3> for [Field; 2] { | ||
fn output(self) -> [Field; 3] {[self[0] as Field; 3]} | ||
} | ||
impl LensForEventSelector<3, 4> for [Field; 3] { | ||
fn output(self) -> [Field; 4] {[self[0] as Field; 4]} | ||
} | ||
impl LensForEventSelector<4, 5> for [Field; 4] { | ||
fn output(self) -> [Field; 5] {[self[0] as Field; 5]} | ||
} | ||
impl LensForEventSelector<5, 6> for [Field; 5] { | ||
fn output(self) -> [Field; 6] {[self[0] as Field; 6]} | ||
} | ||
impl LensForEventSelector<6, 7> for [Field; 6] { | ||
fn output(self) -> [Field; 7] {[self[0] as Field; 7]} | ||
} |
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
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 slightly odd to me, would it not be evaluated to constants instead, e.g.,
i + 1
when unrolled so not doing much difference in the end? 🤷 Don't matter to much to me though, still pretty neat.