-
Notifications
You must be signed in to change notification settings - Fork 295
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
10 changed files
with
228 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mod unencrypted_event_emission; |
60 changes: 60 additions & 0 deletions
60
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,60 @@ | ||
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_with_keys<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_with_keys( | ||
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