-
Notifications
You must be signed in to change notification settings - Fork 598
fix: false decryption fix #7066
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
Changes from all commits
3533ab3
23710b4
a623fe6
842fce8
0adee5c
2a34bd5
faf34ce
b94de06
e89c4a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,4 +16,4 @@ noirc_errors.workspace = true | |
| iter-extended.workspace = true | ||
| convert_case = "0.6.0" | ||
| regex = "1.10" | ||
|
|
||
| tiny-keccak = { version = "2.0.0", features = ["keccak"] } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👀 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,10 @@ use noirc_frontend::{ | |
| Type, | ||
| }; | ||
|
|
||
| use acvm::AcirField; | ||
| use regex::Regex; | ||
| // TODO(#7165): nuke the following dependency from here and Cargo.toml | ||
| use tiny_keccak::{Hasher, Keccak}; | ||
|
|
||
| use crate::{ | ||
| chained_dep, | ||
|
|
@@ -97,7 +100,6 @@ pub fn generate_note_interface_impl(module: &mut SortedModule) -> Result<(), Azt | |
| .collect::<Result<Vec<_>, _>>()?; | ||
| let [note_serialized_len, note_bytes_len]: [_; 2] = | ||
| note_interface_generics.try_into().unwrap(); | ||
| let note_type_id = note_type_id(¬e_type); | ||
|
|
||
| // Automatically inject the header field if it's not present | ||
| let (header_field_name, _) = if let Some(existing_header) = | ||
|
|
@@ -184,8 +186,9 @@ pub fn generate_note_interface_impl(module: &mut SortedModule) -> Result<(), Azt | |
| } | ||
|
|
||
| if !check_trait_method_implemented(trait_impl, "get_note_type_id") { | ||
| let note_type_id = compute_note_type_id(¬e_type); | ||
| let get_note_type_id_fn = | ||
| generate_note_get_type_id(¬e_type_id, note_interface_impl_span)?; | ||
| generate_get_note_type_id(note_type_id, note_interface_impl_span)?; | ||
| trait_impl.items.push(TraitImplItem::Function(get_note_type_id_fn)); | ||
| } | ||
|
|
||
|
|
@@ -324,16 +327,17 @@ fn generate_note_set_header( | |
|
|
||
| // Automatically generate the note type id getter method. The id itself its calculated as the concatenation | ||
| // of the conversion of the characters in the note's struct name to unsigned integers. | ||
| fn generate_note_get_type_id( | ||
| note_type_id: &str, | ||
| fn generate_get_note_type_id( | ||
| note_type_id: u32, | ||
| impl_span: Option<Span>, | ||
| ) -> Result<NoirFunction, AztecMacroError> { | ||
| // TODO(#7165): replace {} with dep::aztec::protocol_types::abis::note_selector::compute_note_selector(\"{}\") in the function source below | ||
| let function_source = format!( | ||
| " | ||
| fn get_note_type_id() -> Field {{ | ||
| {} | ||
| }} | ||
| ", | ||
| fn get_note_type_id() -> Field {{ | ||
| {} | ||
| }} | ||
| ", | ||
| note_type_id | ||
| ) | ||
| .to_string(); | ||
|
|
@@ -387,7 +391,7 @@ fn generate_note_properties_struct( | |
|
|
||
| // Generate the deserialize_content method as | ||
| // | ||
| // fn deserialize_content(serialized_note: [Field; NOTE_SERILIZED_LEN]) -> Self { | ||
| // fn deserialize_content(serialized_note: [Field; NOTE_SERIALIZED_LEN]) -> Self { | ||
| // NoteType { | ||
| // note_field1: serialized_note[0] as Field, | ||
| // note_field2: NoteFieldType2::from_field(serialized_note[1])... | ||
|
|
@@ -525,10 +529,10 @@ fn generate_note_exports_global( | |
| let struct_source = format!( | ||
| " | ||
| #[abi(notes)] | ||
| global {0}_EXPORTS: (Field, str<{1}>) = ({2},\"{0}\"); | ||
| global {0}_EXPORTS: (Field, str<{1}>) = (0x{2},\"{0}\"); | ||
| ", | ||
| note_type, | ||
| note_type_id.len(), | ||
| note_type.len(), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to do this change as note_type_id no longer has the same length as note type. |
||
| note_type_id | ||
| ) | ||
| .to_string(); | ||
|
|
@@ -685,10 +689,18 @@ fn generate_note_deserialize_content_source( | |
| .to_string() | ||
| } | ||
|
|
||
| // TODO(#7165): nuke this function | ||
| // Utility function to generate the note type id as a Field | ||
| fn note_type_id(note_type: &str) -> String { | ||
| fn compute_note_type_id(note_type: &str) -> u32 { | ||
| // TODO(#4519) Improve automatic note id generation and assignment | ||
| note_type.chars().map(|c| (c as u32).to_string()).collect::<Vec<String>>().join("") | ||
| let mut keccak = Keccak::v256(); | ||
| let mut result = [0u8; 32]; | ||
| keccak.update(note_type.as_bytes()); | ||
| keccak.finalize(&mut result); | ||
| // Take the first 4 bytes of the hash and convert them to an integer | ||
| // If you change the following value you have to change NUM_BYTES_PER_NOTE_TYPE_ID in l1_note_payload.ts as well | ||
| let num_bytes_per_note_type_id = 4; | ||
| u32::from_be_bytes(result[0..num_bytes_per_note_type_id].try_into().unwrap()) | ||
| } | ||
|
|
||
| pub fn inject_note_exports( | ||
|
|
@@ -717,47 +729,61 @@ pub fn inject_note_exports( | |
| }, | ||
| file_id, | ||
| ))?; | ||
| let init_function = | ||
| let get_note_type_id_function = | ||
| context.def_interner.function(&func_id).block(&context.def_interner); | ||
| let init_function_statement_id = init_function.statements().first().ok_or(( | ||
| AztecMacroError::CouldNotExportStorageLayout { | ||
| span: None, | ||
| secondary_message: Some(format!( | ||
| "Could not retrieve note id statement from function for note {}", | ||
| note.borrow().name.0.contents | ||
| )), | ||
| }, | ||
| file_id, | ||
| ))?; | ||
| let note_id_statement = context.def_interner.statement(init_function_statement_id); | ||
| let get_note_type_id_statement_id = | ||
| get_note_type_id_function.statements().first().ok_or(( | ||
| AztecMacroError::CouldNotExportStorageLayout { | ||
| span: None, | ||
| secondary_message: Some(format!( | ||
| "Could not retrieve note id statement from function for note {}", | ||
| note.borrow().name.0.contents | ||
| )), | ||
| }, | ||
| file_id, | ||
| ))?; | ||
| let note_type_id_statement = | ||
| context.def_interner.statement(get_note_type_id_statement_id); | ||
|
|
||
| let note_id_value = match note_id_statement { | ||
| let note_type_id = match note_type_id_statement { | ||
| HirStatement::Expression(expression_id) => { | ||
| match context.def_interner.expression(&expression_id) { | ||
| HirExpression::Literal(HirLiteral::Integer(value, _)) => Ok(value), | ||
| HirExpression::Literal(_) => Err(( | ||
| AztecMacroError::CouldNotExportStorageLayout { | ||
| span: None, | ||
| secondary_message: Some( | ||
| "note_type_id statement must be a literal integer expression" | ||
| .to_string(), | ||
| ), | ||
| }, | ||
| file_id, | ||
| )), | ||
| _ => Err(( | ||
| AztecMacroError::CouldNotExportStorageLayout { | ||
| span: None, | ||
| secondary_message: Some( | ||
| "note_id statement must be a literal expression".to_string(), | ||
| "note_type_id statement must be a literal expression" | ||
| .to_string(), | ||
| ), | ||
| }, | ||
| file_id, | ||
| )), | ||
| } | ||
| } | ||
| _ => Err(( | ||
| AztecMacroError::CouldNotAssignStorageSlots { | ||
| AztecMacroError::CouldNotExportStorageLayout { | ||
| span: None, | ||
| secondary_message: Some( | ||
| "note_id statement must be an expression".to_string(), | ||
| "note_type_id statement must be an expression".to_string(), | ||
| ), | ||
| }, | ||
| file_id, | ||
| )), | ||
| }?; | ||
| let global = generate_note_exports_global( | ||
| ¬e.borrow().name.0.contents, | ||
| ¬e_id_value.to_string(), | ||
| ¬e_type_id.to_hex(), | ||
| ) | ||
| .map_err(|err| (err, file_id))?; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| use std::collections::BTreeMap; | ||
|
|
||
| use acvm::acir::circuit::ErrorSelector; | ||
| use acvm::AcirField; | ||
| use iter_extended::vecmap; | ||
| use noirc_abi::{Abi, AbiErrorType, AbiParameter, AbiReturnType, AbiType, AbiValue}; | ||
| use noirc_frontend::ast::Visibility; | ||
|
|
@@ -107,9 +108,7 @@ pub(super) fn value_from_hir_expression(context: &Context, expression: HirExpres | |
| }, | ||
| HirLiteral::Bool(value) => AbiValue::Boolean { value }, | ||
| HirLiteral::Str(value) => AbiValue::String { value }, | ||
| HirLiteral::Integer(field, sign) => { | ||
| AbiValue::Integer { value: field.to_string(), sign } | ||
| } | ||
| HirLiteral::Integer(field, sign) => AbiValue::Integer { value: field.to_hex(), sign }, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix from noir-lang/noir#5270 |
||
| _ => unreachable!("Literal cannot be used in the abi"), | ||
| }, | ||
| _ => unreachable!("Type cannot be used in the abi {:?}", expression), | ||
|
|
||
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.
Unified the message here with
Frfrom foundation package since I am checking the messages intagged_log.ts. Would probably be good to tackle this one