Skip to content

Commit

Permalink
feat: Sync from aztec-packages (noir-lang#5718)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
AztecBot and vezenovm authored Aug 14, 2024
1 parent 13c1fe6 commit 4ea25db
Show file tree
Hide file tree
Showing 40 changed files with 779 additions and 250 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a26419f00f5f082a9ed856346addf6276fbdb4d7
91042c7bcebfebeb4e629162f44988e2cda1ed41
5 changes: 5 additions & 0 deletions acvm-repo/acir/codegen/acir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,8 @@ namespace Program {
};

struct CallData {
uint32_t value;

friend bool operator==(const CallData&, const CallData&);
std::vector<uint8_t> bincodeSerialize() const;
static CallData bincodeDeserialize(std::vector<uint8_t>);
Expand Down Expand Up @@ -4683,6 +4685,7 @@ Program::BlockType::Memory serde::Deserializable<Program::BlockType::Memory>::de
namespace Program {

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

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

template <>
template <typename Deserializer>
Program::BlockType::CallData serde::Deserializable<Program::BlockType::CallData>::deserialize(Deserializer &deserializer) {
Program::BlockType::CallData obj;
obj.value = serde::Deserializable<decltype(obj.value)>::deserialize(deserializer);
return obj;
}

Expand Down
6 changes: 3 additions & 3 deletions acvm-repo/acir/src/circuit/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ pub use memory_operation::{BlockId, MemOp};
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BlockType {
Memory,
CallData,
CallData(u32),
ReturnData,
}

impl BlockType {
pub fn is_databus(&self) -> bool {
matches!(self, BlockType::CallData | BlockType::ReturnData)
matches!(self, BlockType::CallData(_) | BlockType::ReturnData)
}
}

Expand Down Expand Up @@ -183,7 +183,7 @@ impl<F: AcirField> std::fmt::Display for Opcode<F> {
Opcode::MemoryInit { block_id, init, block_type: databus } => {
match databus {
BlockType::Memory => write!(f, "INIT ")?,
BlockType::CallData => write!(f, "INIT CALLDATA ")?,
BlockType::CallData(id) => write!(f, "INIT CALLDATA {} ", id)?,
BlockType::ReturnData => write!(f, "INIT RETURNDATA ")?,
}
write!(f, "(id: {}, len: {}) ", block_id.0, init.len())
Expand Down
18 changes: 14 additions & 4 deletions acvm-repo/acvm_js/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub async fn execute_circuit_with_return_witness(
console_error_panic_hook::set_once();

let program: Program<FieldElement> = Program::deserialize_program(&program)
.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))?;
.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))?;

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

Ok((solved_witness, return_witness).into())
}
Expand Down Expand Up @@ -106,7 +106,8 @@ async fn execute_program_with_native_type_return(
.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,
None))?;

execute_program_with_native_program_and_return(&program, initial_witness, foreign_call_executor)
.await
Expand Down Expand Up @@ -205,6 +206,14 @@ impl<'a, B: BlackBoxFunctionSolver<FieldElement>> ProgramExecutor<'a, B> {
}
_ => None,
};

let brillig_function_id = match &error {
OpcodeResolutionError::BrilligFunctionFailed {
function_id, ..
} => Some(*function_id),
_ => None,
};

// If the failed opcode has an assertion message, integrate it into the error message for backwards compatibility.
// Otherwise, pass the raw assertion payload as is.
let (message, raw_assertion_payload) = match error {
Expand All @@ -230,6 +239,7 @@ impl<'a, B: BlackBoxFunctionSolver<FieldElement>> ProgramExecutor<'a, B> {
message,
call_stack,
raw_assertion_payload,
brillig_function_id,
)
.into());
}
Expand All @@ -253,7 +263,7 @@ impl<'a, B: BlackBoxFunctionSolver<FieldElement>> ProgramExecutor<'a, B> {
call_resolved_outputs.push(*return_value);
} else {
// TODO: look at changing this call stack from None
return Err(JsExecutionError::new(format!("Failed to read from solved witness of ACIR call at witness {}", return_witness_index), None, None).into());
return Err(JsExecutionError::new(format!("Failed to read from solved witness of ACIR call at witness {}", return_witness_index), None, None, None).into());
}
}
acvm.resolve_pending_acir_call(call_resolved_outputs);
Expand Down
14 changes: 13 additions & 1 deletion acvm-repo/acvm_js/src/js_execution_error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use acvm::{
acir::circuit::{OpcodeLocation, RawAssertionPayload},
acir::circuit::{brillig::BrilligFunctionId, OpcodeLocation, RawAssertionPayload},
FieldElement,
};
use gloo_utils::format::JsValueSerdeExt;
Expand All @@ -12,9 +12,11 @@ export type RawAssertionPayload = {
selector: string;
data: string[];
};
export type ExecutionError = Error & {
callStack?: string[];
rawAssertionPayload?: RawAssertionPayload;
brilligFunctionId?: number;
};
"#;

Expand All @@ -38,6 +40,7 @@ impl JsExecutionError {
message: String,
call_stack: Option<Vec<OpcodeLocation>>,
assertion_payload: Option<RawAssertionPayload<FieldElement>>,
brillig_function_id: Option<BrilligFunctionId>,
) -> Self {
let mut error = JsExecutionError::constructor(JsString::from(message));
let js_call_stack = match call_stack {
Expand All @@ -56,8 +59,17 @@ impl JsExecutionError {
None => JsValue::UNDEFINED,
};

let brillig_function_id = match brillig_function_id {
Some(function_id) => {
<wasm_bindgen::JsValue as JsValueSerdeExt>::from_serde(&function_id)
.expect("Cannot serialize Brillig function id")
}
None => JsValue::UNDEFINED,
};

error.set_property("callStack", js_call_stack);
error.set_property("rawAssertionPayload", assertion_payload);
error.set_property("brilligFunctionId", brillig_function_id);

error
}
Expand Down
30 changes: 18 additions & 12 deletions aztec_macros/src/transforms/note_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ pub fn generate_note_interface_impl(
trait_impl.items.push(TraitImplItem::Function(get_note_type_id_fn));
}

if !check_trait_method_implemented(trait_impl, "compute_note_content_hash") {
let compute_note_content_hash_fn = generate_compute_note_content_hash(
if !check_trait_method_implemented(trait_impl, "compute_note_hiding_point") {
let compute_note_hiding_point_fn = generate_compute_note_hiding_point(
&note_type,
note_interface_impl_span,
empty_spans,
)?;
trait_impl.items.push(TraitImplItem::Function(compute_note_content_hash_fn));
trait_impl.items.push(TraitImplItem::Function(compute_note_hiding_point_fn));
}

if !check_trait_method_implemented(trait_impl, "to_be_bytes") {
Expand Down Expand Up @@ -512,29 +512,35 @@ fn generate_note_properties_fn(
Ok(noir_fn)
}

// Automatically generate the method to compute the note's content hash as:
// fn compute_note_content_hash(self: NoteType) -> Field {
// aztec::hash::pedersen_hash(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
// Automatically generate the method to compute the note's hiding point as:
// fn compute_note_hiding_point(self: NoteType) -> Point {
// aztec::hash::pedersen_commitment(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_HIDING_POINT)
// }
//
fn generate_compute_note_content_hash(
fn generate_compute_note_hiding_point(
note_type: &String,
impl_span: Option<Span>,
empty_spans: bool,
) -> Result<NoirFunction, AztecMacroError> {
// TODO(#7771): update this to do only 1 MSM call
let function_source = format!(
"
fn compute_note_content_hash(self: {}) -> Field {{
aztec::hash::pedersen_hash(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_CONTENT_HASH)
r#"
fn compute_note_hiding_point(self: {}) -> aztec::protocol_types::point::Point {{
assert(self.header.storage_slot != 0, "Storage slot must be set before computing note hiding point");
let slot_scalar = dep::std::hash::from_field_unsafe(self.header.storage_slot);
let point_before_slotting = aztec::hash::pedersen_commitment(self.serialize_content(), aztec::protocol_types::constants::GENERATOR_INDEX__NOTE_HIDING_POINT);
let slot_point = dep::std::embedded_curve_ops::multi_scalar_mul([dep::aztec::generators::G_slot], [slot_scalar]);
point_before_slotting + slot_point
}}
",
"#,
note_type
);
let (function_ast, errors) = parse_program(&function_source, empty_spans);
if !errors.is_empty() {
dbg!(errors);
return Err(AztecMacroError::CouldNotImplementNoteInterface {
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()),
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()),
span: impl_span
});
}
Expand Down
Loading

0 comments on commit 4ea25db

Please sign in to comment.