Skip to content

Commit c74f05c

Browse files
AztecBotvezenovm
andauthored
feat: Sync from aztec-packages (#5718)
Automated pull of Noir development from [aztec-packages](https://github.com/AztecProtocol/aztec-packages). BEGIN_COMMIT_OVERRIDE feat: Sync from noir (AztecProtocol/aztec-packages#7945) feat: Sync from noir (AztecProtocol/aztec-packages#7862) feat: Pass calldata ids to the backend (AztecProtocol/aztec-packages#7875) feat: Hook up secondary calldata column in dsl (AztecProtocol/aztec-packages#7759) feat: make token transfer be recursive (AztecProtocol/aztec-packages#7730) fix: Deflatten databus visibilities (AztecProtocol/aztec-packages#7761) refactor: slot part of note hiding point preimage (AztecProtocol/aztec-packages#7767) feat: Sync from noir (AztecProtocol/aztec-packages#7743) feat: removing superfluous call to MSM (AztecProtocol/aztec-packages#7708) feat(profiler): Add support for brillig functions in opcodes-flamegraph (AztecProtocol/aztec-packages#7698) chore: Improve error reporting in profiler (AztecProtocol/aztec-packages#7712) feat: Report gates and VKs of private protocol circuits with megahonk (AztecProtocol/aztec-packages#7722) feat: note hashes as points (AztecProtocol/aztec-packages#7618) feat: Optimize constant array handling in brillig_gen (AztecProtocol/aztec-packages#7661) feat: add recursive aggregation object to proving/verification keys (AztecProtocol/aztec-packages#6770) feat: adding aggregation to honk and rollup (AztecProtocol/aztec-packages#7466) feat: TXE nr deployments, dependency cleanup for CLI (AztecProtocol/aztec-packages#7548) END_COMMIT_OVERRIDE --------- Co-authored-by: Maxim Vezenov <mvezenov@gmail.com>
1 parent 13c1fe6 commit c74f05c

40 files changed

Lines changed: 779 additions & 250 deletions

File tree

.aztec-sync-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a26419f00f5f082a9ed856346addf6276fbdb4d7
1+
91042c7bcebfebeb4e629162f44988e2cda1ed41

acvm-repo/acir/codegen/acir.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,8 @@ namespace Program {
10421042
};
10431043

10441044
struct CallData {
1045+
uint32_t value;
1046+
10451047
friend bool operator==(const CallData&, const CallData&);
10461048
std::vector<uint8_t> bincodeSerialize() const;
10471049
static CallData bincodeDeserialize(std::vector<uint8_t>);
@@ -4683,6 +4685,7 @@ Program::BlockType::Memory serde::Deserializable<Program::BlockType::Memory>::de
46834685
namespace Program {
46844686

46854687
inline bool operator==(const BlockType::CallData &lhs, const BlockType::CallData &rhs) {
4688+
if (!(lhs.value == rhs.value)) { return false; }
46864689
return true;
46874690
}
46884691

@@ -4706,12 +4709,14 @@ namespace Program {
47064709
template <>
47074710
template <typename Serializer>
47084711
void serde::Serializable<Program::BlockType::CallData>::serialize(const Program::BlockType::CallData &obj, Serializer &serializer) {
4712+
serde::Serializable<decltype(obj.value)>::serialize(obj.value, serializer);
47094713
}
47104714

47114715
template <>
47124716
template <typename Deserializer>
47134717
Program::BlockType::CallData serde::Deserializable<Program::BlockType::CallData>::deserialize(Deserializer &deserializer) {
47144718
Program::BlockType::CallData obj;
4719+
obj.value = serde::Deserializable<decltype(obj.value)>::deserialize(deserializer);
47154720
return obj;
47164721
}
47174722

acvm-repo/acir/src/circuit/opcodes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ pub use memory_operation::{BlockId, MemOp};
1515
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
1616
pub enum BlockType {
1717
Memory,
18-
CallData,
18+
CallData(u32),
1919
ReturnData,
2020
}
2121

2222
impl BlockType {
2323
pub fn is_databus(&self) -> bool {
24-
matches!(self, BlockType::CallData | BlockType::ReturnData)
24+
matches!(self, BlockType::CallData(_) | BlockType::ReturnData)
2525
}
2626
}
2727

@@ -183,7 +183,7 @@ impl<F: AcirField> std::fmt::Display for Opcode<F> {
183183
Opcode::MemoryInit { block_id, init, block_type: databus } => {
184184
match databus {
185185
BlockType::Memory => write!(f, "INIT ")?,
186-
BlockType::CallData => write!(f, "INIT CALLDATA ")?,
186+
BlockType::CallData(id) => write!(f, "INIT CALLDATA {} ", id)?,
187187
BlockType::ReturnData => write!(f, "INIT RETURNDATA ")?,
188188
}
189189
write!(f, "(id: {}, len: {}) ", block_id.0, init.len())

acvm-repo/acvm_js/src/execute.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub async fn execute_circuit_with_return_witness(
5757
console_error_panic_hook::set_once();
5858

5959
let program: Program<FieldElement> = Program::deserialize_program(&program)
60-
.map_err(|_| JsExecutionError::new("Failed to deserialize circuit. This is likely due to differing serialization formats between ACVM_JS and your compiler".to_string(), None, None))?;
60+
.map_err(|_| JsExecutionError::new("Failed to deserialize circuit. This is likely due to differing serialization formats between ACVM_JS and your compiler".to_string(), None, None, None))?;
6161

6262
let mut witness_stack = execute_program_with_native_program_and_return(
6363
&program,
@@ -71,7 +71,7 @@ pub async fn execute_circuit_with_return_witness(
7171
let main_circuit = &program.functions[0];
7272
let return_witness =
7373
extract_indices(&solved_witness, main_circuit.return_values.0.iter().copied().collect())
74-
.map_err(|err| JsExecutionError::new(err, None, None))?;
74+
.map_err(|err| JsExecutionError::new(err, None, None, None))?;
7575

7676
Ok((solved_witness, return_witness).into())
7777
}
@@ -106,7 +106,8 @@ async fn execute_program_with_native_type_return(
106106
.map_err(|_| JsExecutionError::new(
107107
"Failed to deserialize circuit. This is likely due to differing serialization formats between ACVM_JS and your compiler".to_string(),
108108
None,
109-
None))?;
109+
None,
110+
None))?;
110111

111112
execute_program_with_native_program_and_return(&program, initial_witness, foreign_call_executor)
112113
.await
@@ -205,6 +206,14 @@ impl<'a, B: BlackBoxFunctionSolver<FieldElement>> ProgramExecutor<'a, B> {
205206
}
206207
_ => None,
207208
};
209+
210+
let brillig_function_id = match &error {
211+
OpcodeResolutionError::BrilligFunctionFailed {
212+
function_id, ..
213+
} => Some(*function_id),
214+
_ => None,
215+
};
216+
208217
// If the failed opcode has an assertion message, integrate it into the error message for backwards compatibility.
209218
// Otherwise, pass the raw assertion payload as is.
210219
let (message, raw_assertion_payload) = match error {
@@ -230,6 +239,7 @@ impl<'a, B: BlackBoxFunctionSolver<FieldElement>> ProgramExecutor<'a, B> {
230239
message,
231240
call_stack,
232241
raw_assertion_payload,
242+
brillig_function_id,
233243
)
234244
.into());
235245
}
@@ -253,7 +263,7 @@ impl<'a, B: BlackBoxFunctionSolver<FieldElement>> ProgramExecutor<'a, B> {
253263
call_resolved_outputs.push(*return_value);
254264
} else {
255265
// TODO: look at changing this call stack from None
256-
return Err(JsExecutionError::new(format!("Failed to read from solved witness of ACIR call at witness {}", return_witness_index), None, None).into());
266+
return Err(JsExecutionError::new(format!("Failed to read from solved witness of ACIR call at witness {}", return_witness_index), None, None, None).into());
257267
}
258268
}
259269
acvm.resolve_pending_acir_call(call_resolved_outputs);

acvm-repo/acvm_js/src/js_execution_error.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use acvm::{
2-
acir::circuit::{OpcodeLocation, RawAssertionPayload},
2+
acir::circuit::{brillig::BrilligFunctionId, OpcodeLocation, RawAssertionPayload},
33
FieldElement,
44
};
55
use gloo_utils::format::JsValueSerdeExt;
@@ -12,9 +12,11 @@ export type RawAssertionPayload = {
1212
selector: string;
1313
data: string[];
1414
};
15+
1516
export type ExecutionError = Error & {
1617
callStack?: string[];
1718
rawAssertionPayload?: RawAssertionPayload;
19+
brilligFunctionId?: number;
1820
};
1921
"#;
2022

@@ -38,6 +40,7 @@ impl JsExecutionError {
3840
message: String,
3941
call_stack: Option<Vec<OpcodeLocation>>,
4042
assertion_payload: Option<RawAssertionPayload<FieldElement>>,
43+
brillig_function_id: Option<BrilligFunctionId>,
4144
) -> Self {
4245
let mut error = JsExecutionError::constructor(JsString::from(message));
4346
let js_call_stack = match call_stack {
@@ -56,8 +59,17 @@ impl JsExecutionError {
5659
None => JsValue::UNDEFINED,
5760
};
5861

62+
let brillig_function_id = match brillig_function_id {
63+
Some(function_id) => {
64+
<wasm_bindgen::JsValue as JsValueSerdeExt>::from_serde(&function_id)
65+
.expect("Cannot serialize Brillig function id")
66+
}
67+
None => JsValue::UNDEFINED,
68+
};
69+
5970
error.set_property("callStack", js_call_stack);
6071
error.set_property("rawAssertionPayload", assertion_payload);
72+
error.set_property("brilligFunctionId", brillig_function_id);
6173

6274
error
6375
}

aztec_macros/src/transforms/note_interface.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ pub fn generate_note_interface_impl(
202202
trait_impl.items.push(TraitImplItem::Function(get_note_type_id_fn));
203203
}
204204

205-
if !check_trait_method_implemented(trait_impl, "compute_note_content_hash") {
206-
let compute_note_content_hash_fn = generate_compute_note_content_hash(
205+
if !check_trait_method_implemented(trait_impl, "compute_note_hiding_point") {
206+
let compute_note_hiding_point_fn = generate_compute_note_hiding_point(
207207
&note_type,
208208
note_interface_impl_span,
209209
empty_spans,
210210
)?;
211-
trait_impl.items.push(TraitImplItem::Function(compute_note_content_hash_fn));
211+
trait_impl.items.push(TraitImplItem::Function(compute_note_hiding_point_fn));
212212
}
213213

214214
if !check_trait_method_implemented(trait_impl, "to_be_bytes") {
@@ -512,29 +512,35 @@ fn generate_note_properties_fn(
512512
Ok(noir_fn)
513513
}
514514

515-
// Automatically generate the method to compute the note's content hash as:
516-
// fn compute_note_content_hash(self: NoteType) -> Field {
517-
// aztec::hash::pedersen_hash(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
515+
// Automatically generate the method to compute the note's hiding point as:
516+
// fn compute_note_hiding_point(self: NoteType) -> Point {
517+
// aztec::hash::pedersen_commitment(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_HIDING_POINT)
518518
// }
519519
//
520-
fn generate_compute_note_content_hash(
520+
fn generate_compute_note_hiding_point(
521521
note_type: &String,
522522
impl_span: Option<Span>,
523523
empty_spans: bool,
524524
) -> Result<NoirFunction, AztecMacroError> {
525+
// TODO(#7771): update this to do only 1 MSM call
525526
let function_source = format!(
526-
"
527-
fn compute_note_content_hash(self: {}) -> Field {{
528-
aztec::hash::pedersen_hash(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
527+
r#"
528+
fn compute_note_hiding_point(self: {}) -> aztec::protocol_types::point::Point {{
529+
assert(self.header.storage_slot != 0, "Storage slot must be set before computing note hiding point");
530+
let slot_scalar = dep::std::hash::from_field_unsafe(self.header.storage_slot);
531+
532+
let point_before_slotting = aztec::hash::pedersen_commitment(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_HIDING_POINT);
533+
let slot_point = dep::std::embedded_curve_ops::multi_scalar_mul([dep::aztec::generators::G_slot], [slot_scalar]);
534+
point_before_slotting + slot_point
529535
}}
530-
",
536+
"#,
531537
note_type
532538
);
533539
let (function_ast, errors) = parse_program(&function_source, empty_spans);
534540
if !errors.is_empty() {
535541
dbg!(errors);
536542
return Err(AztecMacroError::CouldNotImplementNoteInterface {
537-
secondary_message: Some("Failed to parse Noir macro code (fn compute_note_content_hash). This is either a bug in the compiler or the Noir macro code".to_string()),
543+
secondary_message: Some("Failed to parse Noir macro code (fn compute_note_hiding_point). This is either a bug in the compiler or the Noir macro code".to_string()),
538544
span: impl_span
539545
});
540546
}

0 commit comments

Comments
 (0)